Showing posts with label data types. Show all posts
Showing posts with label data types. Show all posts

C++ Data Types..

     

     Helllooo... Readers.... :) Welcome to inspire++. The blog that gives you sophisticated jokes about programming every week.!! ;)
     Hello people.. Did you guys do the homework I gave you in last post. Here I give you the answers.. Please check
 your answers with mine and try to find anything new to you.. 



     Right!! With the lesson from the last post we realized how to create variables. Today lets talk about types of variables which is more generally data types in c++. 
     Last time we learned how to store integer data in variables . Remember the int keyword.. There we talked about integer variables. There are several more data types in c++.Just  Like integers. 




2. Floating Point.

     So, what if we want to store a decimal number in a variable.. we can't store them in integer variables. So for that we have floating point variables. Floating point variables are used to store decimal point values. How to create them? Easy..!! Just like the way we create integers what we have to do is first, type keyword float, and then leave a space and then type a suitable name for your variable. For example float num1 ; . Don't forget the semicolon..!!!
     Right.. after that you can store any decimal value in it. num1 = 75.8262; . Easy!!  Try it your self.. 

3. Character Variables.
     Ok... after that we can talk about other data types. So.. instead of numbers what if we want to store any character value in a variable. There you have character variable. How to create them. Easy.. char space variable name. Ex:- char Letter;. Now you can store any character like A,B,C ... a,b,c... 1,2,3... But remember when you assign any character to your variable remember to use single quotes '.  Ex:-  Letter='A'; 

4. Boolean Variables.
     This data type might be a little bit confusing to you.. Specially , Why we want such data type. 
     In this Data type we store true and false values. Why we want to store true or false value.? Believe me there are so many times we want to use true or false as output in programming. So how to create this?? Type bool , and then a space and the name you want to give to your variable. now in simple letters you can assign either true OR false to your variable.  

5. Void.
     Void is a data type which is not used to create variables. Really!! Yes.. At this point I have to remind you that Data types are used not only to create variables, but also they are used to create arrays , functions etc. So this data type "void" is use in function defining. 

      So above 5 are known as the primitive data types. You can use them to create certain variables. 
     Now I'm going to tell about another important non primitive data type. string...

6. string
     Imaging you want to store a word , or a sentence as the data. What are the options u have.? you type string And then a space and a name for your string variable, finally semi colon. And you can store data in them by variable name assignment operator and the word or the sentence you want. Remember here when assigning data use double quotation marks " ".




     Ok.. now you know something about variables. Now what I want you to do is to make a program to store several data in suitable types of variables  and print them. This is what you have to do.

     Store these data about a student named  Lio ,who is 20 years old , height about 1.8288 , lives in colombo got Grade A for his Mathematics exam.
     Create suitable variables to store his name , age , city , height in meters city and grade for maths. And get them as the output.

     Do this Exercise and I will give you the answers in my next post. :)
     Bye.. C U Soon.. 
Start from the First post <<<

C++ Variables


     Helloo.. My favorite blog readers.. Welcome to the newest post from ispire++ blog. This post is the next post of our fundamental of programming post series . So don't get confused this with our new post series OOP.
     I gave you some homeworks in my last post. Did you do those. Well if you did here are the answers for them.

Last posts Homework answers ;)









So... last week I promised you to start to talk about c++ variables. Here lets start it. Variables are a kind of structure we use to hold data in a program. 
     We know that when we run a program, it runs on our RAM.(Random Access Memory) . In a program, when we want to store some data(Temporarily, Not on hard disk), We create variables. 
      For example, let say we want to store the age of a person. What we have to do is create a variable to hold that data age of a person. Age is measured by years, so it is we can consider as an integer value. So what exactly we want to do here is, create a variable to hold an integer data. And store our data (age) in it. 
How do we do this.
     We want an integer variable, so we type int first,
     Then we put a space, and then we type a suitable name for the variable, ie:- age.
Ok, and finally as always we type semicolon ; . Right! We now have officially created the first variable we ever created in c++. Weldone guys.. :) 



     
     Ok.. now after we created the variable, lets store something in it. In this example age. Let say the age of the person is 23. So what we do is , in a new line we type the name of our variable, age , and then we type equal sign(in c++ it is known as assignment operator) after that we type the value we want 23 and finally semicolon;. 
     Congratulations you have assigned a value to your variable. Now let's check the variable. In a new line let's start a code to print the value. Type, cout<<age; and build and run your program.




     See the output! It says 23 right!! That's the value we assigned to our variable. See how easy to create variables, assign values to them and use them!! 

     Now I want you to create 5 variables about 5 subjects of a student naming English, Programming, Drawing, Electrical, Fluid. And assign the marks values as follows 80, 83, 75, 80, 60. And then in your program write a code to take them as output. Do this as a homework I'll give you the answers in our next post. 
     Ok.. here I end up this post. Hoping to see you in my next post soon.. Bye..!! :)

Next post>>>

Life of a Systems Engineer

  Hello, my dear readers. ✌😀✋ I'm talking to you after a very long time. And I am thrilled to talk-to and hear-from you after all thi...