I need help for student information in Linkedlist
I am having a problem that I could not figure it out. Help
1- Enter student information
2 - Quite
Enter your choice: 1 (Suppose user entered 1)
(Now the details of Student will be entered)
Student ID: 1400 (Suppose user entered 1400)
Student Name: Ali (Suppose user entered Ali)
(If user enters an ID that is already in the list, a message should be displayed “Already in the list.”) -> I need this help
Here is my source code:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
class Node
{
public:
int StudentID;
string StudentName;
Node *next;
};
class Linkedlist
{
public:
Node *head;
Linkedlist();
void StudentInformation(int ID, string name);
};
Linkedlist::Linkedlist()
{
head == NULL;
}
void Linkedlist::StudentInformation(int ID, string name)
{
Node *temp = new Node;
temp->StudentID = ID;
temp->StudentName = name;
temp->next = NULL;
head = temp;
}
int main()
{
Linkedlist list;
int choice;
int ID;
string name;
while(1)
{
cout<<"1. Enter student information \n";
cout<<"2. Search student by ID \n";
cout<<"3. Search student by Name \n";
cout<<"4. Delete student information \n";
cout<<"5. Update student information \n";
cout<<"6. Print all students \n";
cout<<"7. Quit \n";
cout<<"Enter yoru choice: ";
cin>>choice;
switch(choice)
{
case 1:
system("CLS");
cout<<"Enter the following student detail: \n";
cout<<"ID: ";
cin>>ID;
cout<<"Name: ";
cin>>name;
list.StudentInformation(ID, name);
system("CLS");
break;
case 7:
exit(1);
default:
cout<<"Error! Invalid Key... \n";
cout<<"Enter any key to get back menu. \n";
getch();
system("CLS");
}
}
}