Link List

Dear all I am new to Link List please give some idea about below program.

Sample Run:
1- Enter student information
2- Search student by ID
3- Search student by Name
4- Delete student information
5- Print all students
6- Quit
Enter your choice: 1 (Suppose user entered 1)
(Now the details of Student will be entered)
Student ID: bc080400001 (Suppose user entered bc080400001)
Student Name: Ahmad (Suppose user entered Ahmad)
(If user enters an ID that is already in the list, a message should be displayed “Already in the list.”)

(Main menu will be displayed again)
1- Enter student information
2- Search student by ID
3- Search student by Name
4- Delete student information
5- Print all students
6- Quit
Enter your choice: 2 (Suppose user entered 2)
Student ID: bc080400001 (Suppose user entered bc080400001)
(Now the details of Student will be displayed)
Student ID: bc080400001
Student Name: Ahmad
(If user enters an ID that is not in the list, a message should be displayed “Record not found.”)

(Main menu will be displayed again)
1- Enter student information
2- Search student by ID
3- Search student by Name
4- Delete student information
5- Print all students
6- Quit
Enter your choice: 4 (Suppose user entered 4)
(Now it will ask to enter ID to be deleted)
Student ID: bc080400001 (Suppose user entered bc080400001)
(Student record with this ID will be deleted.)

(Main menu will be displayed again)
1- Enter student information
2- Search student by ID
3- Search student by Name
4- Delete student information
5- Print all students
6- Quit
Enter your choice: 5 (Suppose user entered 5)
(Now it will print all students’ information. Suppose there were three students in the list, so it will print: )
Student ID Student Name
------------- ---------------------
bc080400001 Ahmad
bc080200010 Ali
mc070400002 Hassan
closed account (10oTURfi)
It seems you need to create a class for student and create then create a linked list (container) for student objects.

like this:
1
2
3
4
5
6
7
8
class student
{
string name;
int ID;
//...blah blah blah
public:
string getName(return name;)
}


1
2
3
4
5
#include <vector>
//blahblah
vector<student>student_list;
vector<student>::iterator iter;
//.. 


Then to search by name you would want to do something like this:
1
2
3
4
5
6
7
8
9
string blah;
cin >> blah;
for(iter=student_list.begin(); iter!=student_list.end(); iter++)
{
if(iter->getName() == blah)
cout << "Found him!";
else if(iter== --student_list.end())
cout << "cant find him";
}


then to delete student you iterate to the student you want to delete and
iter = student_list.erase(iter);

to print out all you do this:
1
2
3
4
for(iter=student_list.begin(); iter!=student_list.end(); iter++)
{
cout << "Name: " << iter->getName() << "ID: " <</*blah blah*/ endl;
}
Dear Thanks very much for helping me in Link list.
Topic archived. No new replies allowed.