// a program illustrating dynamic structure allocation #include #include const int MAXNAME = 30; // maximum no. of characters in a name const int MAXTEL = 16; // maximum no. of characters in a telephone number struct TeleType { char name[MAXNAME]; char phoneNo[MAXTEL]; }; void populate(TeleType *); // function prototype needed by main() void dispOne(TeleType *); // function prototype needed by main() int main() { char key; TeleType *recPoint; // recPoint is a pointer to a // structure of type TeleType cout << "Do you wish to create a new record (respond with y or n): "; key = cin.get(); if (key == 'y') { key = cin.get(); // get the Enter key in buffered input recPoint = new TeleType; populate(recPoint); dispOne(recPoint); } else cout << "\nNo record has been created."; return 0; } // input a name and phone number void populate(TeleType *record) // record is a pointer to a { // structure of type TeleType cout << "Enter a name: "; cin.getline(record->name,MAXNAME); cout << "Enter the phone number: "; cin.getline(record->phoneNo,MAXTEL); return; } // display the contents of one record void dispOne(TeleType *contents) // contents is a pointer to a { // structure of type TeleType cout << "\nThe contents of the record just created is:" << "\nName: " << contents->name << "\nPhone Number: " << contents->phoneNo << endl; return; }