#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void menu();
class node1
{
friend class U_Record;
char name[51];
char famil[51];
char course[51];
int code;
float score[10];
float ave;
node1 *next1;
};
//*********************************
class node2
{
friend class U_Record;
char lesson[21];
node2 *next2;
};
//**********************************
class U_Record
{
public:
U_Record();
~U_Record();
void add1();
void add2();
void del();
void sortave();
void show();
private:
node1 *first1;
node2 *first2;
};
//************************************
U_Record::U_Record()
{
first1=NULL;
first2=NULL;
}
//**************************************
U_Record::~U_Record()
{
node1 *del1,*temp1;
node2 *del2,*temp2;
del1=first1;
del2=first2;
while(del1)
{
temp1=del1;
del1=del1->next1;
delete temp1;
}
while(del2)
{
temp2=del2;
del2=del2->next2;
delete temp2;
}
}
//****************************************
void U_Record::add1()
{
int i;
bool b;
char y;
U_Record N;
float average,sum=0;
node1 *u1;
node2 *u2;
u1->next1=new node1;
if(!u1)
{
cout<<"Allocation\n";
getch();
exit(4);
}
if(b==true)
{
N.add2();
b=false;
}
do
{
cout<<"Please enter name of new student :\n";
cin>>u1->name;
cout<<"Please enter family of this student ;\n";
cin>>u1->famil;
cout<<"Please enter student's number of this student :\n";
cin>>u1->code;
cout<<"Please enter course of this student :\n";
cin>>u1->course;
u2=first2;
for(i=1;i<=10;i++)
{
cout<<"Please enter score of this student in "<<u2->lesson<<" :\n";
cin>>u1->score
;
sum=sum+(u1->score);
u2=u2->next2;
}
average=(float)sum/10;
u1->ave=average;
cout<<"Do you want to add new student?(Y/N)\n";
cin>>y;
if(y=='Y' || y=='Y')
{
u2=first2;
u1->next1=new node1;
if(!u1)
{
cout<<"Allocation\n";
getch();
exit(4);
}
u1=u1->next1;
}
}while(y=='Y' || y=='y');
menu();
}
//*****************************************
void U_Record::add2()
{
int i;
node2 *u2=new node2;
if(!u2)
{
cout<<"Allocation\n";
getch();
exit(4);
}
first2=u2;
for(i=1;i<=10;i++)
{
cout<<"Please enter name of lesson number "<<i<<" :\n";
cin>>u2->lesson;
u2=u2->next2;
}
}
//*******************************************
void U_Record::del()
{
node1 *u=first1;
node1 *prew;
int n;
char y;
cout<<"Please enter student's number of student that you want delete :\n";
cin>>n;
if(n==first1->code)
{
cout<<"Name\t"<<"Family\t"<<"Student's Number\t"<<"Course\t"<<"Average\n";
cout<<u->name<<"\t"<<u->famil<<"\t"<<u->code<<"\t"<<u->course<<"\t";
cout<<u->ave<<"\n\n";
cout<<"Are you really sure to delete this student from list?(Y/N)\n";
cin>>y;
if(y=='y' || y=='Y')
{
prew=first1->next1;
delete first1;
first1=prew;
}
else
menu();
}
else
{
prew=u;
u=u->next1;
do
{
if(n==u->code)
{
cout<<"Name\t"<<"Family\t"<<"Student's Number\t"<<"Course\t"<<"Average\n";
cout<<u->name<<"\t"<<u->famil<<"\t"<<u->code<<"\t"<<u->course<<"\t";
cout<<u->ave<<"\n\n";
cout<<"Are you really sure to delete this student from list?(Y/N)\n";
cin>>y;
if(y=='y' || y=='Y')
{
prew->next1=u->next1;
delete u;
}
else
void menu2();
}
prew=u;
u=u->next1;
}while(u);
cout<<"There is no student with this student's number\n";
menu();
}
}
//******************************************
void U_Record::sortave()
{
int i,j,sum=0;
float temp;
node1 *u3,*prew1,*temp1;
prew1=first1;
u3=prew1->next1;
do
{
sum=sum+1;
u3=u3->next1;
}while(u3);
u3=prew1->next1;
for(i=sum-1;i>0;i++)
{
for(j=0;j<i;j++)
{
if((prew1->ave)>(u3->ave))
{
temp=prew1->ave;
prew1->ave=u3->ave;
u3->ave=temp;
temp1=u3;
u3=u3->next1;
prew1=u3;
}
}
}
menu();
}
//***************************************************
void U_Record::show()
{
int i,sum=0;
node1 *u4;
node2 *u5;
u4=first1;
u5=first2;
do
{
cout<<"Name\t"<<"Family\t"<<"Student's Number\t"<<"Course\t";
for(i=1;i<=10;i++)
{
cout<<u5->lesson<<"\t";
u5=u5->next2;
}
cout<<"Average\n";
cout<<"_________________________________________________________________";
cout<<"_______________________________________________________________\n";
cout<<u4->name<<"\t"<<u4->famil<<"\t"<<u4->code<<"\t"<<u4->course<<"\t";
for(i=1;i<=10;i++)
{
cout<<u4->score<<"\t";
}
cout<<u4->ave<<"\n\n";
u4=u4->next1;
}while(u4);
menu();
}
//***************************************************
void menu()
{
U_Record M;
int n;
cout<<"Hello,choice a number of this menu to run program,thanks :\n";
cout<<" ******************* \n";
cout<<"For add a student to list click 1\n";
cout<<" ******************* \n";
cout<<"To sotr the list with average of students click 2\n";
cout<<" ******************* \n";
cout<<"To delete a student from the list click 3\n";
cout<<" ******************* \n";
cout<<"To show list click 4\n";
cout<<" ******************* \n";
cout<<"To exit program click 5\n\n";
cout<<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n";
cin>>n;
switch
{
case 1:
M.add1();
break;
case 2:
M.sortave();
break;
case 3:
M.del();
break;
case 4:
M.show();
break;
case 5:
exit(4);
}
}
//********************************************************
main()
{
bool b;
node1 *u1,*first1;
node2 *u2,*first2;
b=true;
u1=new node1;
u2=new node2;
if(!u1)
{
cout<<"Allocation\n";
getch();
exit(4);
}
first1=u1;
if(!u2)
{
cout<<"Allocation\n";
getch();
exit(4);
}
menu();
getch();
}
//********************************************************