Current location - Education and Training Encyclopedia - University rankings - College c language test for help! ~
College c language test for help! ~
Give a student the management of grades, run on VC, don't know TC. Try it yourself, there may be many problems. This is the C++ version, and you have to change it to the C version, and it may not be feasible after the change, mainly because TC does not support the standard well, which is not conducive to debugging ... or don't use TC.

# include & ltiostream & gt

# include & ltiomanip & gt

# include & ltfstream & gt

# include & lt string & gt

Use namespace std

# define max100;

Class students

{

Public:

Student * Next;

Public:

String name; //Name

Long num// student number

int x,y,z; //Mathematics, Chinese and English

Int AA// total score

void play(){ cout & lt; & lt Name & lt& lt "Student ID Yes"

student(string sname,long snum,int sx,int sy,int sz)

{

name = sname

num = snum

x = sx

y = sy

z = sz

}

};

Category cla

{

Public:

Cla()// constructor

{

stu = 0;

sload();

}

~cla()// destructor

{

Student * p;;

p = stu

while(p)

{

p = p-& gt; Next;

Delete stu

stu = p;

}

stu = 0;

}

void sadd(); //Add

void s remove(); //Delete

void samend(); //modify

void s search(); //query

void stat xis(); //sort

void ssave(); //Save

void sload(); //read

//Sorting function

void pxh();

void psx();

void pyw();

void pyy();

void pAA();

Private:

Student * stu// Head contact

};

Voidcla:: sad ()//Add

{

Student * q;;

String name1;

long num 1;

int x 1,y 1,z 1;

System ("CLS");

Cout & lt& lt" \n ** Additional students * * \ n "<& ltendl

Cout & lt& lt "Please enter students (separated by spaces)" < & ltendl

Cout & lt& lt's name, student number, math score, Chinese score and English score: "< & ltendl"

CIN & gt; & gtname 1 & gt; & gtnum 1 & gt; & gtx 1 & gt; & gty 1 & gt; & gtz 1;

Q = freshman (name 1, num 1, x 1, y 1, z1);

q->; next = 0;

q->; AA = x 1+y 1+z 1;

If (Stu)

{

Student * t;;

t = stu

if(t->; num==num 1)

{

Cout & lt& lt student id already exists, please re-enter.

Return;

}

while(t->; Next)

{

if(t->; num==num 1)

{

Cout & lt& lt student id already exists, please re-enter.

Return;

}

t = t-& gt; Next;

}

t->; next = q;

}

other

{

stu = q;

}

Cout & lt& lt "Input complete"

}

Void cla::sremove()// delete

{

System ("CLS");

int num 1;

Cout & lt< "\ n * * Delete student information * * \ n";

Cout & lt& lt "Please enter the student ID of the student you want to delete:";

CIN & gt; & gtnum 1;

//Find the node to delete.

Student *p 1, * p2

p 1 = stu;

while(p 1)

{

if(p 1->; num==num 1)

Break;

other

{

p2 = p 1;

p 1 = p 1->; Next;

}

}

//Delete node

if(p 1! =NULL)// If a node is found, delete it.

{

p 1->; play();

Cout & lt& lt "Are you sure you want to delete it? [Yes/No] "< & ltendl

char c; CIN & gt; & gtc;

if(toupper(c)! ='Y') returns;

If(p 1==stu) // The node to be deleted is the first node.

{

stu = p 1->; Next;

Delete p1;

}

Else // The node to be deleted is a subsequent node.

{

p2->; next = p 1->; Next;

Delete p1;

}

Cout & lt& lt "Found student number as"

}

Else // Node not found.

Cout & lt& lt "The student you want to delete was not found! \ n ";

}

Void cla::samend()// Modify

{

System ("CLS");

long num 1;

Cout & lt< "\ n * * Modify student information * * \ n";

Cout & lt& lt "Enter the student number to be modified";

CIN & gt; & gtnum 1;

//Find the node to modify.

Student *p 1, * p2

p 1 = stu;

while(p 1)

{

if(p 1->; num==num 1)

Break;

other

{

p2 = p 1;

p 1 = p 1->; Next;

}

}

if(p 1! = empty)

{

Cout & lt& lt "student number is"

Cout & lt& lt "name"

Cout & lt& lt "Please enter the revised information: name, math score, Chinese score and English score" < & ltendl.

CIN & gt; & gtp 1->; Name & gt>P1->; x & gt& gtp 1->; y & gt& gtp 1->; z;

p 1->; AA = p 1->; x+p 1->; y+p 1->; z;

Cout & lt& lt "Modified successfully"

}

Else // No contact found.

Cout & lt& lt "not found! \ n ";

}

Void cla::ssearch()// query

{

System ("CLS");

Cout & lt& lt" \n** Inquiring about student information * * \ n "<& ltendl

Cout & lt& lt "Please enter a query method:"

Cout & lt& lt" 1. Query by student number "

Cout & lt& lt"2. Query by name "

Cout & lt& lt"3. Return "

char c; CIN & gt; & gtc;

Switch (c)

{

Case "1":

{

long num 1;

Cout & lt& lt "Student ID card to query"

CIN & gt; & gtnum 1;

//Find the node to query.

Student *p 1, * p2

p 1 = stu;

while(p 1)

{

if(p 1->; num==num 1)

Break;

other

{

p2 = p 1;

p 1 = p 1->; Next;

}

}

if(p 1! = empty)

{

Cout & lt& lt "student number is"

Cout & lt& lt "Name:"

Cout & lt& lt "Query complete ...";

}

Else // No contact found.

Cout & lt& lt "not found! \ n ";

Break;

}

Case "2":

{

String name1;

Cout & lt& lt "Name of student to query"

CIN & gt; & gtname 1;

//Find the node to query.

Student *p 1, * p2

p 1 = stu;

while(p 1)

{

if(p 1->; name==name 1)

Break;

other

{

p2 = p 1;

p 1 = p 1->; Next;

}

}

if(p 1! = empty)

{

cout & lt& ltname 1 & lt; & lt "student information" < & ltendl

Cout & lt& lt "Student ID:"

Cout & lt& lt "Query complete ...";

}

Else // No contact found.

Cout & lt& lt "not found! \ n ";

Break;

}

Case "3": Return;

}

}

Void cla::pxh() // Sort by student number.

{

Student *p 1, * p2

int n;

p 1 = stu;

n = 1;

while(p 1->; Next)

{ n++; p 1 = p 1->; Next; }

Cout & lt& lt“* * * * Yes "

int I;

p 1 = stu;

for(I = 1; I & ltn;; i++)

{

p 1 = stu;

if(p 1->; num & gtp 1->; Next-> Num) // If the head node is greater than the second one.

{

p2 = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; next = p 1; //Head node switching

stu = p2

}

p 1 = stu;

while(p 1->; Next-> Next)//Intermediate exchange

{

p2 = p 1;

p 1 = p 1->; Next;

if(p 1->; num & gtp 1->; Next-> Numbers)

{

p2->; next = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; Next-> next = p 1;

P 1=p2- > Next; //exchange

}

}

}

p 1 = stu;

do

{

p 1->; play();

p 1 = p 1->; Next;

} while(p 1);

}

Void cla::psx()// Sort by math scores.

{

Student *p 1, * p2

int n;

p 1 = stu;

n = 1;

while(p 1->; Next)

{ n++; p 1 = p 1->; Next; }

Cout & lt& lt“* * * * Yes "

int I;

p 1 = stu;

for(I = 1; I & ltn;; i++)

{ p 1 = stu;

if(p 1->; x & gtp 1->; Next-> X) // If the head node is greater than the second one.

{ p2 = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; next = p 1; //Head node switching

stu = p2

}

p 1 = stu;

while(p 1->; Next-> Next)//Intermediate exchange

{ p2 = p 1;

p 1 = p 1->; Next;

if(p 1->; x & gtp 1->; Next-> x)

{

p2->; next = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; Next-> next = p 1;

P 1=p2- > Next; //exchange

}

}

}

p 1 = stu;

do

{ p 1->; play();

p 1 = p 1->; Next;

} while(p 1);

}

Void cla::pyw()// Sort by Chinese score.

{

Student *p 1, * p2

int n;

p 1 = stu;

n = 1;

while(p 1->; Next)

{ n++; p 1 = p 1->; Next; }

Cout & lt& lt“* * * * Yes "

int I;

p 1 = stu;

for(I = 1; I & ltn;; i++)

{ p 1 = stu;

if(p 1->; y & gtp 1->; Next-> Y) // If the first node is larger than the second node's

{ p2 = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; next = p 1; //Head node switching

stu = p2

}

p 1 = stu;

while(p 1->; Next-> Next)//Intermediate exchange

{ p2 = p 1;

p 1 = p 1->; Next;

if(p 1->; y & gtp 1->; Next-> y)

{

p2->; next = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; Next-> next = p 1;

P 1=p2- > Next; //exchange

}

}

}

p 1 = stu;

do

{ p 1->; play();

p 1 = p 1->; Next;

} while(p 1);

}

Void cla::pyy()// Sort by English scores.

{

Student *p 1, * p2

int n;

p 1 = stu;

n = 1;

while(p 1->; Next)

{ n++; p 1 = p 1->; Next; }

Cout & lt& lt“* * * * Yes "

int I;

p 1 = stu;

for(I = 1; I & ltn;; i++)

{ p 1 = stu;

if(p 1->; z & gtp 1->; Next-> Z) // If the head node is greater than the second one.

{ p2 = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; next = p 1; //Head node switching

stu = p2

}

p 1 = stu;

while(p 1->; Next-> Next)//Intermediate exchange

{ p2 = p 1;

p 1 = p 1->; Next;

if(p 1->; z & gtp 1->; Next-> z)

{

p2->; next = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; Next-> next = p 1;

P 1=p2- > Next; //exchange

}

}

}

p 1 = stu;

do

{ p 1->; play();

p 1 = p 1->; Next;

} while(p 1);

}

Void cla::pAA()// Sort by total score.

{

Student *p 1, * p2

int n;

p 1 = stu;

n = 1;

while(p 1->; Next)

{ n++; p 1 = p 1->; Next; }

Cout & lt& lt“* * * * Yes "

int I;

p 1 = stu;

for(I = 1; I & ltn;; i++)

{ p 1 = stu;

if(p 1->; AA & gtp 1->; Next-> AA) // If the first node is larger than the second node's

{ p2 = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; next = p 1; //Head node switching

stu = p2

}

p 1 = stu;

while(p 1->; Next-> Next)//Intermediate exchange

{ p2 = p 1;

p 1 = p 1->; Next;

if(p 1->; AA & gtp 1->; Next-> AA)

{

p2->; next = p 1->; Next;

p 1->; next = p 1->; Next-> Next;

p2->; Next-> next = p 1;

P 1=p2- > Next; //exchange

}

}

}

p 1 = stu;

do

{ p 1->; play();

p 1 = p 1->; Next;

} while(p 1);

}

Void cla::s taxi()// sort

{

System ("CLS");

char c;

Cout & lt& lt "Please select a sorting method:"

Cout & lt& lt" 1 ... sorted by student number "

Cout & lt& lt"2 ... Sort by math scores "

Cout & lt& lt"3 ... Ranked by Chinese scores "< & ltendl

Cout & lt& lt"4 ... ranked by English scores "< & ltendl

Cout & lt& lt"5 ... Sort by total score "

Cout & lt& lt"6 ... Return "

Cout & lt& lt "Please select (1-6)"

CIN & gt; & gtc;

Switch (c)

{

case ' 1 ':pxh(); Break;

Case "2": PSX (); Break;

Case "3": pyw (); Break;

Case "4": pyy (); Break;

Case "5": PAA (); Break;

Situation "6": Return;

}

}

Void cla::ssave() // Save to a file.

{

System ("CLS");

char c;

Cout & lt< "\ nSave the student information (this will overwrite the original file). Do you want to continue? [Yes/No]: "; CIN & gt; & gtc;

if(toupper(c)! ='Y') returns;

ofstream tfile("date.txt ",IOs _ base::binary);

Student * p = stu

While(p)// write file

{

tfile & lt& ltp->; Name & lt< "\ t"<<P->; num & lt& lt" \ t " & lt& ltp->; x & lt& lt" \ t " & lt& ltp->; y & lt& lt" \ t " & lt& ltp->; z;

tfile & lt& ltendl

p = p-& gt; Next;

}

tfile . close();

Cout & lt& lt "saved ..."

}

Void cla::sload() // read

{

Student * p;;

p = stu

while(p)

{

stu = p-& gt; Next;

Delete p;

p = stu

}

ifstream tfile("date.txt ",IOs _ base::binary);

String name1;

long num 1;

int x 1,y 1,z 1;

tfile & gt& gtname 1 & gt; & gtnum 1 & gt; & gtx 1 & gt; & gty 1 & gt; & gtz 1;

while(tfile.good())

{

//Create a student contact

Students';

s = stu

S = freshman (name 1, num 1, x 1, y 1, z1);

s-& gt; next = 0;

s-& gt; AA = x 1+y 1+z 1;

If(stu) // If a node already exists

{

Student * p2

p2 = stu

And (p2- > Next)//Find the tail node.

{

p2 = p2-& gt; Next;

}

p2->; next = s; //connection

}

Otherwise//If there is no node (empty table)

{

stu = s; //connection

}

tfile & gt& gtname 1 & gt; & gtnum 1 & gt; & gtx 1 & gt; & gty 1 & gt; & gtz 1;

}

tfile . close();

Cout & lt< "\ nStudent information has been loaded ... \ n ";;

}

void main()

{

char c;

cla a;

do

{

Cout & lt< "\ nStudent achievement management system \ n";

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n”;

Cout & lt& lt "Author: Software Engineering 0611019: zgjxwl \ n";

Cout & lt& lt" 1 ... Increase students \ n ";;

Cout & lt& lt"2 ... Delete students \ n ";;

Cout & lt& lt"3 ... Modify students \ n ";;

Cout & lt& lt"4 ... Inquiring about student information \ n ";;

Cout & lt& lt"5 ... sort \ n ";;

Cout & lt& lt"6 ... Save information \ n ";;

Cout & lt& lt"7 ... reading information \ n ";;

Cout & lt& lt"8 ... Exit \ n ";;

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n”;

Cout & lt& lt Please select (1-8):;

CIN & gt; & gtc;

Switch (c)

{

case ' 1 ':a . sadd(); Break;

Case "2": a.sremove (); Break;

Case "3": a.samend (); Break;

Case "4": a.s search (); Break;

Case "5": a. statxis (); Break;

Case "6": a.s save (); Break;

Case "7": a.sload (); Break;

}

}while(c! ='8');

}