#include #include using namespace std; //This program demonstrates the basics of structures /* A structure is a compound variable. Itcan be used to group a number of data * elements, possibly of varying types into one unit. * A declaration of a structure serves as a blueprint for the unit and does not * actually declare/ allocate space. *Ideally, structures are declared in global space, in order to facilitate use * throughout the program. * This structure can then be used as a programmer defined data type. * Since no space is allocated while declaring a structure, we cannot give values * to the data on the inside, unless they are consts. */ struct Date //makes a date structure { int day, month, year; //These won't be given values here string dayOfWeek; }d1; //d1 becomes a global varibale of type Date //We can also declare structure variables in another structure declaration struct Person { string name; double height,weight; string eyeColor; Date dateOfBirth; }; //the semicolon is necessary int main() { //In order to allocate space, we need to create variables of the type Date today; Person me; //The . (dot) operator is used to access elements within the structure. today.day=27; today.month=3; today.year=2017; today.dayOfWeek="Monday"; //Input and output work the same way as primitives cout<<"Enter person info: "; cout<<"Name: "; getline(cin,me.name); cout<<"Height and Weight: "; cin>>me.height>>me.weight; cout<<"Eye Color: "; getline(cin,me.eyeColor);// to get rid of newline getline(cin,me.eyeColor); cout<<"Date of birth: "; //In order to use multiple level structures, we can use the dot operator for each level cout<<"Month: "; cin>>me.dateOfBirth.month; cout<<"Day: "; cin>>me.dateOfBirth.day; cout<<"Year: "; cin>>me.dateOfBirth.year; //Output cout<<"Personnel Information:\nName: "<