#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 const int MAXRECS = 3; // maximum no. of records struct TeleType { char name[MAXNAME]; char phoneNo[MAXTEL]; TeleType *nextaddr; }; void populate(TeleType *); // function prototype needed by main() void display(TeleType *); // function prototype needed by main() int main() { int i; TeleType *list, *current; // two pointers to structures of type TeleType // get a pointer to the first structure in the list list = new TeleType; current = list; // populate the current structure and create the remaining structures for(i = 0; i < MAXRECS - 1; i++) { populate(current); current->nextaddr = new TeleType; current = current->nextaddr; } populate(current); // populate the last structure current->nextaddr = NULL; // set the last address to a NULL address cout << "\nThe list consists of the following records:\n"; display(list); // display the structures 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; } void display(TeleType *contents) // contents is a pointer to a { // structure of type TeleType while (contents != NULL) // display till end of linked list { cout << endl << settiosflags(ios::left) << setw(30) << contents->name << setw(20) << contents->phoneNo; contents = contents->nextaddr; } cout << endl; return; }