#include <iostream>
#include <windows.h>
#include <bits/stdc++.h>
using namespace std;
typedef struct student
{
long int num;//学号
char name[20];//姓名
int foxscore;//fox成绩
int cscore;//C语言
int englishscore;//英语成绩
int allscore;//总成绩
struct student *next;
}stu,*st;
void goxy(int x,int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos = {
0 };
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void setcolor(unsigned short ForeColor,unsigned short BackGroundColor)
{
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,ForeColor+BackGroundColor*0x10);
}
void caidan()
{
goxy(30,10);
printf("************************************");
goxy(30,12);
printf("欢迎进入学生成绩小程序");
goxy(30,14);
printf("************************************");
goxy(30,16);
printf("请选择");
goxy(30,18);
printf("1.输入4个学生的信息 2.3门课程总分 3.总分降序显示出来 4.根据学号显示出该学生的信息");
goxy(30,20);
printf("5.退出");
goxy(30,22);
}
void getinformation(st &head){
st qhead;
qhead=head;
for(int i=1;i<5;i++){
st p=new stu;
p->next=NULL;
cin>>p->num>>p->name>>p->foxscore>>p->cscore>>p->englishscore;
p->allscore=p->cscore+p->foxscore+p->englishscore;
qhead->next=p;
qhead=p;
}
}
void printfallscore(st head){
st p=head->next;
cout<<"4名同学的总成绩如下"<<endl;
while(p){
cout<<p->name<<" "<<p->allscore<<endl;
p=p->next;
}
}
st charu(st head,st &q){
st p1,p2;
p1=head;
p2=head->next;
while(p2!=NULL){
if(q->allscore<p2->allscore){
p1=p1->next;
p2=p2->next;
}else break;
}
p1->next=q;
q->next=p2;
return head;
}
st mysort(st head){
st p1,q,t;
p1=head;
q=head->next->next;
p1->next->next=NULL;
t=q->next;
while(q!=NULL){
p1=charu(p1,q);
q=t;
if(t!=NULL)
t=q->next;
}
return p1;
}
void searchnum(st head){
cout<<"请输入要查找的学号"<<endl;
int x,y=0;
cin>>x;
st p;
p=head->next;
while(p){
if(p->num==x){
cout<<p->num<<" "<<p->name<<" "<<p->foxscore<<" "<<p->cscore<<" "<<p->englishscore;
y=1;
break;
}
p=p->next;
}
if(y==0) cout<<"没有要找的学号"<<endl;
}
int main()
{
st head=new stu;
head->next=NULL;
//cout << "对4个学生的信息进行输入;" << endl;
//getinformation(head);//1 a 10 20 30 2 b 20 30 40 3 c 45 50 60 4 d 70 80 90
setcolor(7,2);
system("cls");
int i,flag=0;
t:caidan();
scanf("%d",&i);
switch (i){
case 1:system("cls");
cout<<"对4个学生的信息进行输入;例如 1 a 10 20 30 2 b 20 30 40 3 c 45 50 60 4 d 70 80 90"<<endl;
getinformation(head);//1 a 10 20 30 2 b 20 30 40 3 c 45 50 60 4 d 70 80 90//10 fu 99 100 100 15 zhao 80 70 60 20 qian 15 25 35 30 wang 55 56 57
flag=1;
system("pause");system("cls");goto t; break;
case 2:
if(flag==0){
cout<<"请先选择1,建立学生信息后再操作"<<endl;
system("pause");
system("cls");
goto t;
}
system("cls");
cout<<"显示学生3门课程总分"<<endl;
printfallscore(head);
system("pause");system("cls");goto t;break;
case 3:
if(flag==0){
cout<<"请先选择1,建立学生信息后再操作"<<endl;
system("pause");
system("cls");
goto t;
}
system("cls");
cout<<"对4个学生的总分按降序排序并显示出来"<<endl;
head=mysort(head);
printfallscore(head);
system("pause");system("cls");goto t;break;
case 4:
if(flag==0){
cout<<"请先选择1,建立学生信息后再操作"<<endl;
system("pause");
system("cls");
goto t;
}
cout<<"输入一个学号,显示出该学生的有关信息"<<endl;
searchnum(head);
system("pause");system("cls");goto t;break;
case 5:exit(1);break;
default:system("cls");goto t;
}
return 0;
}