help with link list

i need some help to develop a function for a link list you basically have to

1. Add 25 students with (ID ,Name, Department and Grade)
2. Print the name and the score of top three students from each department
3. Print the average of each department (CE, CS, IT)

i couldn't figure out how to develop the print function.

Could you possibly show me your code? It's pretty much impossible for me to help you unless you give me a starting point.
this is my code so far



#include <iostream>
#include <string>
using namespace std;
struct student
{
string name;
int id;
char grade;
student *next;
student *prev;
};
class department
{
private:
student *tail;
student *head;
string name;
int count;
public:
void init();
bool exist(int x);
void addstudent(int y,string z,char g);
void deletestudent(int w);
void printstudent();
int countCourses();


};
void department::init()
{
head = NULL;
tail = NULL;
name="XXX";
count=0;
}
void department::addstudent(int y,string z,char g)
{

{
student* p;
p = new student;
count ++;
p->name = z;
p->id = y;
p->grade=g;
if (tail == NULL)
{
p->next = NULL;
p->prev=NULL;
head = p;
tail = p;
}
else
{
head->prev=p;
p->next = head;
p->prev=NULL;
head = p;
}
}

return;

}
bool department::exist(int x)
{
student* p= head;
while (p!=NULL)
{
if (x==p->id)
{
return true;
break;
}
p= p->next;
}
return false;
}
void department::deletestudent(int w)
{
student* mynode;
mynode = head;

do {
if (w == mynode->id)
{
if (head == mynode)
{
head = mynode->next;
head->prev=NULL;
if (count == 1)
tail =NULL;
}
else if (tail == mynode)
{
tail =mynode->prev;
tail->next = NULL;
}else
{
mynode->next->prev=mynode->prev;
mynode->prev->next=mynode->next;
}

delete mynode;
count --;
break;
}
mynode = mynode->next;
}while (mynode !=NULL);

return;
}
void department::printstudent()
{
student *current;
current = head;
if( head==NULL )
{
cout << "EMPTY"<<endl;
return;
}
while (current != NULL)
{
cout << current-> id <<current->name <<current ->grade <<endl;
current = current->next;
}
return;
}


int main()
{
cout<<"Enter the depertament name"<<endl;
string na;

getline (cin,na);
department S;
S.init();
cout<<"How many students are in "<<na<<endl;
int n;
cin>>n;
int saw; string san;char ga;
for(int i=1;i<=n;i++)
{
cout<<" Enter the student "<<i<<" id"<<endl;
cin>>saw;
cout<<"Enter the "<< i<< " student name"<<endl;
cin>>san;
cout<<"enter the "<<i<<"student grade"<<endl;
cin>>ga;
getline (cin,san);

if(S.exist(saw))
{
cout<<"this course is exist, Enter another id "<<endl; i--;
}
else
{
S.addstudent(saw,san,ga);
}
}

cout<<"Enter a course id to be deleted : ";
int x;
cin>>x;
S.deletestudent(x);



S.printstudent();
return 0;
}
Topic archived. No new replies allowed.