Saved Bookmarks
| 1. |
Considering the following specifications:Structure nameDataTypeSizeNamefirstarray of characters60midarray of characters40lastarray of characters60phoneareaarray of characters4excharray of characters4numbarray of characters6class nameDateTypep-recnameNamephonePhonewith member functions constructors and display_rec.(i) Declare structures in C++ for Name and Phone.(ii) Declare a class for P_rec.(iii) Define the constructor (outside the class P_rec) that gathers information from the user for the above two structures Name and Phone.(iv) Define the display_rec (outside the class P_rec) that shows the current values. |
|
Answer» #include #include #include struct Name { char first[40]; char mid[40]; char last[60]; }; struct Phone { char area[4]; char exch[4]; char numb[6]; }; class P_rec { Name name; Phone phone; p_rec(); void display_rec(); }; P_rec() { first="abc"; mid="aaa"; last="jjj"; area=1234; exch=7546; numb=789456; } void display_rec() { cout<<first<<mid<<last<<area<<exch<<numb; } void main() { clrscr(); P_rec p; p.display_rec(); getch(); } |
|