210 likes | 492 Views
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;
E N D
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; 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}*/
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)
Create a struct Appointment • First what is an appointment
Appointment = Date + Time + description What is Date and what is Time
Date = year + month + day Time = hour + minuets + seconds
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
APPOINMENT review = { {2010, 11, 28}, {5 , 30, 0}, “to review programming” }; APPOINMENT review = {2010, 11, 28, 5 , 30, 0,“to review programming”};
Create a struct name it circle which has a point • First what is a circle
Create a struct name it circle which has a point • First what is a circle • Circle = ( center ) point + radius • What is a point
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
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 */
POINT startpoint; POINT startpoint = {10,10}; create a circle its centre is the original point
CIRCLE crl1 = {0,0, 3.5}; Create a circle and then assign its center startpoint and 2.4 to the radius
CIRCLE crl2 ; crl2.c.x = startpoint.x; crl2.c.y= startpoint.y; crl2.rds = 2.4; crl2.c = startpoint; crl2.rds=2.4;
Create a struct name it person where each person has a name, address, and birth day
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;
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
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