Hi i'm trying to read out the some code that i search in google. And i try to differentiate the code whether its using what kind of data structure.. Its using binary tree, queue, tree or vector or others?
Code:
#include<iostream.h>
#include<time.h>
#include<math.h>
#include<iomanip>
class studentrecord
{
public:
studentrecord();
char fname[10];
char lname[10];
int ID;
char programme[10];
int year_of_study;
studentrecord *nxt;
void register_student();
void display_all();
void displayStudentInformation();
void Swap();
void SearchStudent();
void DeleteStudent();
void ConditionalDisplay();
};
studentrecord::studentrecord()
{
}
studentrecord *start_ptr=NULL;
int khetho=0;
void studentrecord::register_student()
{
studentrecord *temp,*temp2;
temp=new studentrecord;
cout<<"enter the student fist name:"<<endl;
cin>>temp->fname;
cout<<"enter student last name:"<<endl;
cin>>temp->lname;
cout<<"enter student id:"<<endl;
cin>>temp->ID;
cout<<"Enter the Programme of the student:"<<endl;
cin>>temp->programme;
cout<<"Enter student's year:"<<endl;
cin>>temp->year_of_study;
temp->nxt=NULL;
if(start_ptr==NULL)
{
start_ptr=temp;
}
else
{
temp2=start_ptr;
while(temp2->nxt!=NULL)
{
temp2=temp2->nxt;
}
temp2->nxt=temp;
}
}
void studentrecord::display_all()
{
studentrecord *temp;
temp=start_ptr;
if(start_ptr==NULL)
{
cout<<"the record is empty"<<endl;
}
else
{
while(temp!=NULL)
{
cout<<"last name is:"<<temp->lname<<endl;
cout<<"ID:"<<temp->ID<<endl;
cout<<"first name is:"<<temp->fname<<endl;
cout<<"the programme is:"<<temp->programme<<endl;
cout<<endl;
cout<<endl;
temp=temp->nxt;
}
}
}
void studentrecord::Swap()
{ studentrecord *temp,*temp2,*temp3,*temp4;
temp= start_ptr;
cout<<endl;
int id,id1; //count;
cout<<"enter ID u want to swap "<<endl;
cin>>id;
cout<<"enter 2nd ID u want to swap "<<endl;
cin>>id1;
if (start_ptr == NULL)
{
cout << "The list is empty!" << endl;
}
while(temp!=NULL)
{
if(temp->ID=id1)
{
temp2=temp;
temp=temp->nxt;
}
}
while(temp3!=NULL)
{
if(temp3->ID=id1)
{
temp4=temp3;
temp3=temp3->nxt;
}
}
temp->nxt=temp4;
temp3->nxt=temp2;
temp->nxt=temp3->nxt;
temp3->nxt=temp->nxt;
//temp4->nxt=temp2->nxt;
//temp2->nxt=temp4->nxt;
//temp3->nxt=temp2;
// temp2->nxt=temp->nxt;
// delete temp;
cout<<endl;
// cout<<count;
}
void studentrecord:: SearchStudent()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int id,count=0;
cout<<"enter student ID u want to search for";
cin>>id;
if (start_ptr == NULL)
cout << "The list is empty!" << endl;
else
{
while(temp!=NULL )
{
if(temp->ID==id)
{
cout<<"ID :"<<temp->ID<<endl;
cout<<"First Name: "<<temp->fname<<endl;
cout<<"Last Name: "<<temp->lname<<endl;
cout<<"Programme: "<<temp->programme<<endl;
cout<<"Year of Study: "<<temp->year_of_study<<endl;
count++;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<count;
}
}
void studentrecord:: DeleteStudent()
{ studentrecord *temp,*temp2;
temp= start_ptr;
cout<<endl;
int id, count;
cout<<"enter id u wana delete";
cin>>id;
if (start_ptr == NULL)
{
cout << "The list is empty!" << endl;
}
if(start_ptr->ID = id)
{
temp=start_ptr;
start_ptr=start_ptr->nxt;
delete temp;
}
else
{
while(temp->ID!=id)
{
temp2=temp;
cout<<temp->ID;
count++;
temp = temp->nxt;
}
temp2->nxt=temp->nxt;
delete temp;
cout<<endl;
cout<<count;
}
}
void studentrecord::ConditionalDisplay()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int count=0;
char lastname[20];
cout<<"Enter the Last Name to search: ";
cin>>lastname;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while(temp!=NULL )
{
if(temp->lname==lastname)
{
cout<<endl;
cout<<temp->lname<<endl;
cout<<temp->fname<<endl;
cout<<temp->ID<<endl;
cout<<temp->ID<<endl;
cout<<temp->year_of_study<<endl;
temp=temp->nxt;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<"There are "<<count<<"maches";
}
}
void studentrecord:: displayStudentInformation()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int id,count=0;
cout<<"enter id to get student information";
cin>>id;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while(temp!=NULL )
{
if(temp->ID==id)
{
cout<<temp->fname<<endl;
cout<<temp->lname<<endl;
cout<<temp->ID<<endl;
cout<<temp->year_of_study<<endl;
cout<<endl;
count++;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<count;
}
}
void main()
{
//start_ptr = NULL;
studentrecord l;
do
{
cout << " ______________________________"<<endl;
cout << " Please select a choice : " << endl;
cout << " ______________________________"<<endl;
cout << " 0. Exit the program." << endl;
cout << " 1. register student." << endl;
cout << " 2. search student." << endl;
cout << " 3. Swap student postion." << endl;
cout << " 4. display student information." << endl;
cout << " 5. display all." << endl;
cout << " 6. conditional display."<<endl;
cout << " 7. delete."<<endl;
cout << " _______________________________" <<endl << "";
cin >> khetho;
switch (khetho)
{
case 1 : l.register_student();
cout<<" ";system("pause");
system("cls");
break;
case 2 : l.SearchStudent(); break;
case 3 : l.Swap(); break;
case 4 : l.displayStudentInformation(); break;
case 5 : l.display_all();break;
case 6 : l.ConditionalDisplay();break;
case 7 : l.DeleteStudent();break;
}
}
while (khetho != 0);
}