Hi everybody. I am a C++ user who is new to link-listed. Now I am having a problem with one of my program. The program is about design a student recording system. The problem that I am facing is on the int main part. I am not sure how to link those void print or void delete to the main function, which means I don't know how to do the delete student part and the print part. So I hope someone can help me on this. Below is the code that I did by far.
#include<iostream> #include<string> using namespace std; class studentDet { private: struct node { string name; double cgpa; int id; string prog; int progcode; node *link; studentDet* next; }*head; public: studentDet(); void InsNew(string name, int id, string prog, int progcode,double cgpa); void UpdateS(string name, int id, string prog, int progcode,double cgpa); void PrintList(); bool SearchId(int id); void DeleteNode(); ~studentDet(); }; /////////////////////////////////////////////////////// studentDet::studentDet() { head=NULL; } studentDet::~studentDet() { node *q; if( head == NULL ) return; while( head != NULL ) { q = head->link; delete head; head = q; } } ////////////////////////////////////////////////////// /* Inserting a New Student Node (always last) */ void studentDet::InsNew(string name, int id, string prog, int progcode,double cgpa) { node *newNode, *prev; newNode = new node; newNode->name = name; newNode->id = id; newNode->prog = prog; newNode->progcode = progcode; newNode->cgpa; newNode->link = NULL; if (head == NULL) head = newNode; else { prev = head; while ((prev->link) != NULL) prev = prev->link; prev->link = newNode; } } /////////////////////////////////////////////// /*Update anywhere Reinsert void studentDet::UpdateS(string name, int id, double cgpa, char prog, int progcode); { node *newNode, *prev; newNode = new node; newNode->name = name; newNode->id = id; newNode->prog = prog; newNode->progcode = progcode; newNode->cgpa; newNode->link = NULL; /////////////////////////////////////////// */ void studentDet::PrintList() { node *current; current = head; while (current != NULL) { cout<<"\n\n------------Student Info------------"<<endl; cout<<"Name: \tID: \tProgramme: \tProgramme Code: \tCGPA: "<<endl; cout<<current->name; cout<<"\t"<<current->id; cout<<"\t\t"<<current->prog; cout<<"\t"<<current->progcode; cout<<"\t"<<current->cgpa; current=current->link; } } ///////////////////////////////////////// bool studentDet::SearchId(int id) { node *current; current = head; bool found; found = false; while ((current != NULL) && (!found)) { if (current->id == id) found = true; else current = current->link; } return found; } ///////////////////////////////////////////////// /* Deleting the Last Node */ void studentDet::DeleteNode() { node *PreviousNode, *CurrentNode; if (head != NULL) { if (head->link == NULL) { delete head; head = NULL; } else { PreviousNode = head; CurrentNode = head->link; while ((CurrentNode->link) != NULL) { PreviousNode = CurrentNode; CurrentNode = CurrentNode->link; } PreviousNode->link = NULL; delete CurrentNode; } } } /////////////////////////////////////////////// int main() { studentDet list; string name; int id; char prog[20]; int progcode; double cgpa; char selected; int cont; do { cout<<"A. Add a student information."<<endl; cout<<"B. Update a student information."<<endl; cout<<"C. Delete a student information."<<endl; cout<<"D. Print."<<endl; cout<<"E. Search."<<endl; cin>>selected; switch (selected) { case 'a': case 'A': cout<<"Please Fill In The Following Blanks"<<endl; cout<<"Enter Name: "; cin>>name; cout<<"\nEnter ID: "; cin>>id; cout<<"\nEnter Programme: "; cin>>prog; cout<<"\nEnter Programme Code: "; cin>>progcode; cout<<"\nEnter CGPA: "; cin>>cgpa; list.InsNew(name, id, prog, progcode, cgpa); break; case 'b': case 'B': break; case 'c': case 'C': break; case 'd': case 'D': void PrintList(); break; case 'e': case 'f': break;} } while ( cont=1); system("pause"); getchar(); getchar(); return 0; }