-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Saturday 30 May 2015

Concept of structures

Structures


There are many data types in C++.i.e.,int,float,double,long double,bool,etc.

We know that int is used to represent integers and float is used to represent numbers with precision.

But in case of real world objects(such as car,chair,door,etc),these data types are not useful.

So,to remove this difficulty, we use user-defined data types and these data types are known as structures.

Definition:

                                       A structure is a collection of variable types grouped together.You can refer to a structure as a single variable, and to its parts as members of that variable by using the dot (.) operator. 

Remember that the variables in a structure are of different data types.

When dealing with the students in a college, many variables of different types are needed.  It may be necessary to keep track of a name, an address (street, city, state, zip code), an age, an ID number, and a grade point average, for example,below is the general syntax of declaring a structure or user-defined data type in C++.


struct STUDENT_TYPE

{

string name;

string street; 

string city;

string state;

string  zipcode;  

 int age; 

 double IDnum;    

 double grade;

} ;


(reference taken from www.MathBits.com)


No comments:

Post a Comment