I have an assignment for my comp sci class where i have to make a program using a linked list allowing me to enter a students last name, first name, id, and a test score then have several functions, one printing a roster, one a gradebook, one is a search where the user enter's the student ID number and then displays all the info about that student and then one is adding a student by adding a node to the list and deleting a student. My professor just touched briefly on the linked list and being that im a first time programmer i am having difficulties w/this assignament, if anyone could help me out i'd appreciate it, here's the program i have, but its not even running. so anyhelp i would appreciate! Thanks!!
email: [email protected]
#include <iostream>
using namespace std; //introduces namespace std
struct info
{
char lName[50];
char fName[50];
char iD[20];
int score;
info *next;
};
info* classRoster(info *list,int count)
{
info temp;
info *currentNode=list;
for(int i=0;i<count;i++){
while(currentNode->next!=NULL){
if(strcmp(currentNode->lName,(currentNode->next)->lName)>0){
temp=currentNode->lName;
currentNode->lName=(currentNode->next)->lName;
(currentNode->next)->lName=temp;
}//end if
currentNode=currentNode->next;
}//end while
}//end for
currentNode=list;
cout<<"Class Roster:"<<endl;
cout<<"Name"<<"\t\t\t\t\t"<<"ID#"<<endl;
while(currentNode!=NULL){
cout<<currentNode->lName;
cout<<currentNode->iD;
currentNode=currentNode->next;
}//end while
return list;
}
void gradeBook(info *listhead)
{
info *currentNode=listhead;
cout<<"Grade Book:"<<endl;
cout<<"ID#"<<"\t\t\t"<<"Score"<<endl;
while(currentNode!=NULL){
cout<<currentNode->iD;
cout<<"\t\t\t"<<currentNode->score<<endl;
currentNode=currentNode->next;
}//end while
}
void studentRecord(info *listhead)
{
int iD;
info *currentNode=listhead;
cout<<"Enter the students id:"<<endl;
cin>>iD;
while(currentNode!=NULL){
if(currentNode->iD==iD){
cout<<currentNode->lname;
cout<<currentNode->fname<<endl;
cout<<currentNode->iD<<endl;
cout<<currentNode->score<<endl;
}
currentNode=currentNode->next;
}
}
info* addAStudent(info *listhead)
{
info* newNode;
newNode=new info;
cout<<"Enter the student's last name:";
cin>>newNode->lName,50;
cout<<"Enter the student's first name:";
cin>>newNode->fName,50;
cout<<"Enter the student's id number:";
cin>>newNode->iD;
cout<<"Enter the student's score:";
cin>>newNode->score;
newNode->next=listhead;
listhead=newNode;
cout<<endl;
return listhead;
}
info *deleteNode(node* list,int n)
{
node *ptr,*dptr;
cout<<"Enter the id of the student you want to delete:";
cin>>n;
ptr=list;
if(n==1)
list=list->next;
if(n==2)
list->next=ptr->next;
if(n>2)
for(int i=0;i<n-1;i++)
ptr=ptr->next;
dptr=ptr->next;
ptr->next=dptr->next;
return list;
}
int main()
{
info *head=NULL;
info *newNode;
int numberOfStudents,a;
cout<<"Enter the number of students in the class:"<<endl;
cin>>numberOfStudents;
for(int i=0;i<numberOfStudents;i++){
newNode= new info;
cout<<"Enter the student's last name:";
cin>>newNode->lName,50;
cout<<"Enter the student's first name:";
cin>>newNode->fName,50;
cout<<"Enter the student's id number:";
cin>>newNode->iD;
cout<<"Enter the student's score:";
cin>>newNode->score;
cout<<endl;
}
do{
cout<<"1. Print class roster."<<endl;
cout<<"2. Print grade book."<<endl;
cout<<"3. Print a student record."<<endl;
cout<<"4. Add a student."<<endl;
cout<<"5. Delete a student."<<endl;
cout<<"6. Quit."<<endl;
cin>>a;
if(a==1)
head=classRoster(head,numberOfStudents);
cout<<endl;
if(a==2)
gradeBook(head);
cout<<endl;
if(a==3)
studentRecord(head);
cout<<endl;
if(a==4)
head=addAStudent(head);
if(a==5)
head=deleteAStudent(head);
}while(a!=6);
cout<<"Program Terminated!"<<endl;
return 0;
}