1 / 21

Structs within structs

typedef struct{ short int year; unsigned int month; /* 1..12 */ unsigned int day; /* 1..31 */ }DATE; DATE birthday = {1963, 1, 4};. Structs within structs. if( birthday .year < 2000 ){ printf(" Born last century ! n”); }. typedef struct{ short int year;

kaycee
Download Presentation

Structs within structs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. typedef struct{ short int year; unsigned int month; /* 1..12 */ unsigned int day; /* 1..31 */ }DATE; DATE birthday = {1963, 1, 4}; Structs within structs

  2. if( birthday.year < 2000 ){ printf(" Born last century!\n”); }

  3. typedef struct{ short int year; unsigned char month; /* 1..12 */ unsigned char day; /* 1..31 */ }DATE; • typedef struct{ • DATE birthday; • char gnd; • float weight; • }FRIEND; • FRIEND esam; FRIEND zayed ={ {1990,12,31}, ’M’, 61.5} /*FRIEND zayed ={ 1990,12,31, ’M’, 61.5}*/

  4. printf( "Date of birth is %2u/%2u/%4u \n“, zayed.birthday.day, zayed.birthday.month, zayed.birthday.year ); %d  decimal (29, -12) %u  unsigned value (29, 12)

  5. Create a struct Appointment • First what is an appointment

  6. Appointment = Date + Time + description What is Date and what is Time

  7. Date = year + month + day Time = hour + minuets + seconds

  8. typedef struct Date{ int y,m,d; } DATE; typedef struct Time{ int h,m,s; } TIME; typedef struct appointment{ DATE d; TIME t; char description[100]; } APPOINTMENT; create a variable of APPOINTMENT with initial values

  9. APPOINMENT review = { {2010, 11, 28}, {5 , 30, 0}, “to review programming” }; APPOINMENT review = {2010, 11, 28, 5 , 30, 0,“to review programming”};

  10. Create a struct name it circle which has a point

  11. Create a struct name it circle which has a point • First what is a circle

  12. Create a struct name it circle which has a point • First what is a circle • Circle = ( center ) point + radius • What is a point

  13. Create a struct name it circle which has a point • First what is a circle • Circle = point + radius • What is a point • Point = x-axis + y-axis

  14. typedef struct { int, x,y; } POINT; typedef struct{ POINT centre; double rds;} CIRCLE; • Typedef struct{ • int x,y; • }POINT; • Typedef struct{ • POINT centre; • double rds; • }CIRCLE; • /*create a point variable */

  15. POINT startpoint; POINT startpoint = {10,10}; create a circle its centre is the original point

  16. CIRCLE crl1 = {0,0, 3.5}; Create a circle and then assign its center startpoint and 2.4 to the radius

  17. CIRCLE crl2 ; crl2.c.x = startpoint.x; crl2.c.y= startpoint.y; crl2.rds = 2.4; crl2.c = startpoint; crl2.rds=2.4;

  18. Create a struct name it person where each person has a name, address, and birth day

  19. typedef struct { char first[20]; char father[20]; char family[20]; }NAME; typedef struct{ char country[20]; char city[20]; char street[2]; int bulding; int flat; } ADDRESS; typedefstruct{ inty,m,d; }DATE; typedefstruct { NAME pname; ADDRESS padd; DATE pbd; }PERSON;

  20. 1 - Create a variable from each with initial values 2 - Create a variable from PERSON and then show how this variable can be assigned values from the variables created at 1 ASS

  21. Recreate the STUDENT struct with a birth day member and then create two variables one initial values and the second allow the user to input the values ASS

More Related