Problem in displaying!!!
Feb 19, 2015 at 2:19am UTC
Hello!
I need to know how to display the records when i populate from 1st option and then the 2nd option. I can only display the initial records that i populated in option 1. please help!!!
And I want to know how i can make the 3rd and 4th options work??!!??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#include<iostream>
#include<String>
#include<iomanip>
using namespace std;
const int numofels=1;
struct teletype
{
string name;
string phoneno;
teletype *nextAdd;
};
void populate(teletype *);
void display(teletype *);
void insert(teletype *);
void modify(teletype *);
void remove(teletype *);
int main()
{
int choice;
teletype *list, *current, *newrecpoint;
list = new teletype;
current = list;
while (true )
{
{
cout << "Pick an option from the following menu:" << endl<<endl;
cout << "1. Create an initial list of name and phone numbers" << endl;
cout << "2. Insert a new structure into the linked list" << endl;
cout << "3. Modify an existing structure in the linked list" << endl;
cout << "4. Delete an existing structure from the list" << endl;
cout << "5. Exit from the program" << endl << endl;
cin >> choice;
cin.ignore();
}
if (choice == 1){
for (int i = 0; i < numofels - 1; i++)
{
populate(current);
current->nextAdd = new teletype;
current = current->nextAdd;
}
populate(current);
current->nextAdd = NULL;
cout << "The list is:" << endl;
display(list);
cout << endl;
}
else if (choice == 2){
{
newrecpoint = new teletype;
insert(newrecpoint);
}
current->nextAdd = NULL;
cout << "The list is:" << endl;
display(list); //how to display all
//the records with the new record??
}
else if (choice == 5){
cout << "Good Bye!" ;
exit(0);
}
else
cout << "Enter a number 1-5 " << endl<<endl;
}
system("pause" );
return 0;
}
void populate(teletype *record)
{
cout << "Enter a name: " ;
getline(cin, record->name);
cout << "Enter the phone number: " ;
getline(cin, record->phoneno);
cout << endl;
return ;
}
void display(teletype *contents)
{
while (contents != NULL)
{
cout << endl << setiosflags(ios::left)
<< setw(30) << contents->name
<< setw(20) << contents->phoneno;
contents = contents->nextAdd;
}
cout << endl;
return ;
}
void insert(teletype *newrecord)
{
populate(newrecord);
return ;
}
void modify(teletype *modrecord)
{
populate(modrecord);
return ;
}
Last edited on Feb 19, 2015 at 3:46am UTC
Topic archived. No new replies allowed.