Traditional Culture Encyclopedia - Traditional customs - C language experts please come in the next traditional C language program a performance management system
C language experts please come in the next traditional C language program a performance management system
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
#define max 100;
class student
{
public:
student *next;
public:
string name;// name;//student number
long num;//student number
int x,y,z;//math, language, English
int AA;//total score
void play(){cout<<name<< "Student's student number is "<< &num< & lt;",math:"<<<x<<",language:"<<<y<"<",english:"<<<z<<",total score:"<<<AA<<< endl;};
student(string sname, long snum,int sx,int sy,int sz)
{
name=sname;
num=snum;
x=sx;
y=sy;
z=sz;
}
};
class cla
{
public:
cla()//constructor
{
stu=0;
sload();
}
~cla()//destructor
{
student *p;
p=stu;
while(p)
{
p=p->next;
delete stu;
stu=p;
}
stu=0;
}
{ p>void sadd(); //add
void sremove(); //delete
void samend(); //modify
void ssearch(); //query
void staxis(); //sort
void ssave(); //save
void sload(); //read
// Sort Functions
void pxh();
void psx();
void pyw();
void pyy();
void pAA ();
private:
student *stu; //header contact
};
void cla::sadd() //add
{
student *q;
string name1;
long num1;
int x1,y1,z1;
system("cls");
cout<<"\n **Added students** \n"<<endl;
cout<< "Please enter the student's (spaced out with spaces in between )"<<endl;
cout<< "Name School Number Math Score Language Score English Score:"<<endl;
cin>> name1>> num1>> x1>> y1>>. z1;
q=new student(name1,num1,x1,y1,z1);
q->next=0;
q->AA=x1+y1+z1;
if(stu)
{
student *t; p>
t=stu;
if(t->num==num1)
{
cout<< "The student number already exists, please retype"<<endl;
return;
}
while(t-> ;next)
{
if(t->num==num1)
{
cout<< "The student number already exists, please retype"<<endl;
return;
}
t=t->. next;
}
t-> next=q;
}
else
{
stu=q;
}
cout<< "Input complete"<< endl;
}
void cla::remove()//delete
{
system("cls");
int num1;
cout<<"\n** Remove student info **\n";
cout<< "Enter the student number of the student who wants to be removed. Student number of the student you want to delete:";
cin>>num1;
// Find the node to delete
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->. num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
// Delete the node
if(p1!=NULL)//If it finds the node, then delete
{
p1->play();
cout<< "Sure about deletion? [Y/N]"<<endl;
char c;cin>>c;
if(toupper(c)! = 'Y') return;
if(p1==stu) //if the node to be deleted is the first node
{
stu=p1->next;
delete p1;
}
else //if the node to be deleted is a subsequent node
{
stu=p1->next;
delete p1;
} p>{
p2->next=p1->next;
delete p1;
}
cout<< "Find the student with the number "<<num1<<" and delete \n";
}
else // node not found
cout<< "The student you want to delete was not found! \n";
}
void cla::samend()//modify
{
system("cls");
long num1;
cout<<"\n** Modify student information **\n";
cout<< "Enter the student's number to be modified";
cin>>num1;
// Find the node to be modified
student *p1,*p2;
p1=stu;
while(p1)
{
< p>if(p1->num==num1)break;
else
{
p2=p1;
p1=p1->next;
}
}
}
if(p1!=NULL)
{
cout<< "Information about the student whose number is "<<num1<<"<< "Math"<< endl;
cout<< "Name"<<p1->name<< "Math"<<. p1->x<< "Language"<< p1->y<< "English"<<<p1->z<< endl;
cout<< "Please enter the modified information: name Math score Language score English score"<< endl;
cin>>p1->name>>p1->x>>p1->y>>p1->z;
p1->AA=p1->x+p1->y+p1->z;
cout<< "Modification successful"<< endl;
}
else //Contact not found
cout<< "Not found! \n";
}
void cla::ssearch()//query
{
system("cls");
cout<<"\n** Query student information **\n"<< endl;
cout<. << "Please enter the query method:"<<endl;
cout<< "1. Query by student number"<<endl;
cout<< "2. Query by name"<<endl;
cout<< ; "3. return"<<endl;
char c; cin>>c;
switch (c)
{
case '1':
{
long num1;
cout<< "To query student number"<<endl;
cin>>num1;
//Find the node to query
student *p1,*p2;
p1=stu;
while(p1)
{
if( p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
}
if(p1!=NULL)
{
cout<< "Information about the student whose number is "<<num1<<"<<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#" gt;x<<" Language:"<<<p1->y<<" English:"<<<p1->z<<< endl;
cout<< "Query complete..." ;
}
else // contact not found
cout<< "Not found! \n";
break;
}
case '2':
{
string name1;
cout<< "Name of student to look up" << endl;
cin>>. name1;
//find the node to query
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->name==name1)
break;
< p>else{
p2=p1;
p1=p1->next;
}
}
}
if(p1!=NULL)
{
cout<<name1<< "The student's lt;<p1->z<<endl;
cout<< "Query complete..." ;
}
else // contact not found
cout<< "Not found! \n";
break;
}
case '3': return;
}
}
}
void cla::pxh() //sort by student number
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<< "**** has "<<n<< "messages ..." <<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{
p1=stu;
if (p1->num>p1->next->num ) // if the head node is greater than the second one
{
p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; // head node swap
stu=p2;
}
p1=stu;
while(p1->next->next) //intermediate exchange
{
p2=p1;
p1=p1->next;
if(p1->num>p1- >next->num)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //swap
}
}
}
}
p1=stu;
do
{
p1->play();
p1=p1->next;
} while(p1);
}
void cla::psx()//sort by math score
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1 ->next)
{ n++; p1=p1->next; }
cout<< "***There are "<<n<< "messages..." <<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->x>p1->next->x) // if the header node is greater than the the second one
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; // header node swap
stu=p2;
}
p1= stu;
while(p1->next->next) //intermediate exchange
{ p2=p1;
p1=p1->next;
if(p1->x>p1->next->x)
{ < /p>
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //swap
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
}
void cla::. pyw()//sort by language scores
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1-> next)
{ n++; p1=p1->. next; }
cout<< "*** There are "<<n<< "messages..." <<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->y>p1->next->y) // if the header node is greater than the the second one
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; // header node swap
stu=p2;
}
p1= stu;
while(p1->next->next) //intermediate exchange
{ p2=p1;
p1=p1->next;
if(p1->y>p1->next->y)
{ < /p>
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //swap
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
}
void cla::. pyy()//sort by English score
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1-> next)
{ n++; p1=p1->. next; }
cout<< "*** There are "<<n<< "messages..." <<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->z>p1->next->z) // if the header node is greater than the the second one
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; // header node swap
stu=p2;
}
p1= stu;
while(p1->next->next) //intermediate exchange
{ p2=p1;
p1=p1->next;
if(p1->z>p1->next->z)
{ < /p>
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //swap
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
}
void cla::. PAA()//sort by total score
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next ; }
cout<< "*** There are "<<n<< "messages..." <<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->AA>p1->next->AA) // if the head node is greater than the second one
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; // header node swap
stu=p2;
}
p1= stu;
while(p1->next->next) //intermediate exchange
{ p2=p1;
p1=p1->next;
if(p1->AA>p1->next->AA)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; // swap <
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
void cla ::staxis()//sort
{
system("cls");
char c;
cout<< "Please choose which way to sort:"<<endl;
cout<< "1 ...... sorted by student number"<<endl;
cout<< "2 ...... sorted by math grade"<<endl;
cout<< "2 ...... sorted by math grade"<<endl;
cout<< lt; "3...... sorted by language scores"<<endl;
cout<< "4...... sorted by English scores"<<endl;
cout<< "5...... sorted by total score"<<endl;
cout<< "6...... return"<<endl;
cout<< "Please select (1-6)"<< endl;
cin>>c;
switch (c)
{
case '1':pxh(); break;
case '2':pxx(). break;
case '3':pyw(); break;
case '4':pyy(); break;
case '5':pAA(); break;
case '6':return;
}
}
}
< p>void cla::ssave() //save to file{
system("cls");
char c;
cout<<"\n Saving student information (will overwrite the original file), continue or not? [Y/N]:"; cin>>c;
if(toupper(c)! = 'Y') return;
ofstream tfile("date.txt",ios_base::binary);
student *p=stu;
while(p)// Write file
{
tfile<&>. lt;p->name<<"\t"<<p->num<<"\t"<<p->x<<"\t"<<p->y<<"\t"<<p->z;
tfile<<endl;
p=p->next;
}
tfile.close();
cout<< "Saved..." <<endl;
}
void cla::sload() //read
{
student *p;
p=stu;
p=stu;
while(p)
{
stu=p->next ;
delete p;
p=stu;
}
ifstream tfile("date.txt",ios_base::binary);
string name1;
long num1;
int x1,y1,z1;
tfile>>name1>>num1>>x1>>y1>>z1;
while(tfile.good())
{
student *s;
s=stu;
s=new student(name1,num1,x1,y1,z1);
s->next=0;
s->AA=x1+y1+z1;
If(stu) / /If node already exists
{
student *p2;
p2=stu;
while(p2->next) //find tail node
{
p2=p2->next;
}
p2-& gt;next=s; //connect
}
else //if no node exists (table empty)
{
stu=s; //connect
}
tfile>>name1>>num1>>x1>& gt;y1>>z1;
}
tfile.close();
cout<<"\nStudent information has been loaded... \n";
}
void main()
{
char c;
cla a;
do
{
cout<<"\nStudent Results Management System \n";
cout<<"\n";
cout<< lt; "**************************************\n";
cout<<" Author: Software Engineering 06110119: zgjxwl \n";
cout<<" 1 ... ...Add Student \n";
cout<<" 2......Delete Student \n";
cout<<" 3......Modify Student \n" ;
cout<<" 4......Querying Student Information \n";
cout<<" 5......Sorting \n";
cout<< " 6......Save Message \n";
cout<<" 7......Read Message \n";
cout<<" 8... . exit \n";
cout<< "**************************************\n";
cout<< "Please select (1-8):";
cin>>. c;
switch(c)
{
case '1': a.sadd();break;
case '2': a.remove();break;
case '3': a.samend();break;
case '4': a.ssearch();break;
case '5': a.staxis();break;
case '6': a.ssave();break;
case '7': a.sload();break;
} p>
}while(c!='8');
}
- Previous article:How is rock candy made?
- Next article:What are the advantages of cloud computing?
- Related articles
- What are the basic skills of dancing?
- How to practice traditional culture
- What are the folk taboos?
- What are the important festivals in China?
- Improve the long-term management and protection mechanism of human settlements in rural pastoral areas, and use what to reasonably set up people in rural pastoral areas.
- What are the customs of Mid-Autumn Festival?
- Installation method of woodworking wall socket
- Can I buy a demolition and resettlement house?
- Autumn Equinox Customs
- The origin, look and story of She crafts