Tuesday, July 28, 2009

What is code of this data model?

( name [30]; age (int); address; status char[3];)


Address ( housenum; streetname; city_or_provname);


City_or_Provname ( type (this takes on a value of C if city add or P if provincial add); CityName [20]; ProvName [30]);


Outstanding_Student (name [30]; age (int); address; status char[3]);


Failed_Student (name [30]; age (int); address; status char[3]);








typedef struct


{


char name[30];


int age;


char status[3];


}STUDENT;





typedef struct


{


int housenum[30];


char streetname[30];


}ADDRESS;





typedef struct


{


char type[30];


union{


char CName[20];


char PROVINCE[30];


} union


}CITY_or_PROVINCE;





make a program using this data.


asking a user name, sex, address and status


in two given types of students.


and the output is what the user give.

What is code of this data model?
your declaration/definition of the data structures are not correct.





1. a data field of type ADDRESS (you have typedef-er the ADDRESS structure) should be a part of the struct STUDENT.





2. similarly a data field of type CITY_or_PROVINCE should be a part of the struct ADDRESS.





the above two are a requirement stated by your own problem definition.





also I don't see why you need 30 housenums in the ADDRESS struct and 30 type fields for the CITY_or_PROVINCE struct. (for both, 1, i.e. a single variable and not an array, should be enough).





after you have done a typedef of anything you can use it just like a "C" built-in type. so you can declare a student like this





STUDENT outstanding_stud, failed_stud;





use scanf for the user to input the individual fields..





ex.


scanf("%d", %26amp;outstanding_stud.address.housenum);





will result into the control waiting for the user to input an interger for the housenum and will store what the user enters in the housenum field of the address field of the outstanding_stud variable which is a structure of type STUDENT.





for output use printf like this:





printf("House Number: %d\n", outstanding_stud.address.housenum);





which will print:





House Number: 21





if the user has entered 21 for the house number.





you should figure out the rest.





bye!

salary survey

No comments:

Post a Comment