#ifndef Score
#define Score
#include<iostream.h>
#include<string.h>
class student//定义class student类
{
friend class list;//声明class list 是class student的友元类
private:
char name[20];
double num;
double grade[4];
public:
student(){next=0;}
void s();
student *next;
char * outname(){return name;};
double outgrade(int i){return grade[i];};
void intgrade();
};
void student::intgrade()//定义intgrade
{ cout<<" 请输入语文成绩\n";
cin>>grade[0];
cout<<"请输入英语成绩\n";
cin>>grade[1];
cout<<"请输入数学成绩\n";
cin>>grade[2];
cout<<"请输入C++成绩\n";
cin>>grade[3];
}
void student::s()
{
cout<<"请输入姓名\n";
cin>>name;
cout<<"请输入学号\n";
cin>>num;
cout<<"请输入语文成绩\n";
cin>>grade[0];
cout<<"请输入英语成绩\n";
cin>>grade[1];
cout<<"请输入数学成绩\n";
cin>>grade[2];
cout<<"请输入C++成绩\n";
cin>>grade[3];
}
class list
{
private:
double high[5],low[5];
double totoal;
student *last,*first;
public:
list(){last=0;first=0;totoal=0;};//定义初始值为0
~list();//声明析构函数
void instu();
void outstu(char *);
int delstu(char *n);
void think();
void search(char s[10]);
double hi(int i);
double lo(int i);
void av(int i);
void ev(int i);
};
list::~list()//定义析构函数
{
if(first!=0)
{
student *p=first,*temp;
while(p!=0)
{
temp=p;
p=p->next;
delete temp;
cout<<"ok\n";
}
}
}
void list::instu()
{ student *p=new student();
p->s();
if(first==0){first=last=p;}else{last->next=p;last=p;}
totoal++;
}
void list::outstu(char *n)
{
student *temp=first;for(;temp!=NULL;temp=temp->next)
if(strcmp(temp->outname(),n)==0)
{ cout<<"姓名 语文 英语 数学 C++ \n ";
cout<<temp->outname()<<" "<<temp->outgrade(0)<<" "<<temp->outgrade(1)<<
" "<<temp->outgrade(2)<<" "<<temp->outgrade(3);}
}
int list::delstu(char *n)
{
student *temp=first,*p;if(strcmp(first->outname(),n)==0)
{ first->next=first;delete temp;}
else if(temp->next!=0)
{if(strcmp(temp->next->outname(),n)==0)
{p=temp->next;temp->next=temp->next->next;delete p;}
else temp=temp->next;}
totoal--;
cout<<"\n删除成功\n";
return 0;
}
void list::think()
{
cout<<"人数"<<totoal<<endl;
cout<<" 语文 、\n";
cout<<"最高分"<<hi(0)<<"最低分"<<lo(0)<<"";
av(0);
ev(0);
cout<<"英语\n";
cout<<"最高分"<<hi(1)<<"最低分"<<lo(1);
av(1);
ev(1);
cout<<"数学、\n";
cout<<"最高分"<<hi(2)<<"最低分"<<lo(2);
av(2);
ev(2);
cout<<"C++";
cout<<"最高分"<<hi(3)<<"最低分"<<lo(3);
av(3);
ev(3);
}
double list::hi(int i)//定义hi(int i)
{
high[i]=0.00;
student *temp=first;
if(temp!=0)
{if(temp->outgrade(i)>high[i])
high[i]=temp->outgrade(i);
temp=temp->next;
}
return high[i];
}
double list::lo(int i)//定义lo(int)
{
low[i]=100;
student *temp=first;if(temp!=0)
{if(temp->outgrade(i)<low[i])
low[i]=temp->outgrade(i);
temp=temp->next;
}
return low[i];
}
void list::av(int i)//定义av(int i )
{ double aver=0;
student *temp=first;if(temp!=0)
{aver+=temp->outgrade(i);
temp=temp->next;
}
cout<<aver/totoal<<endl;
}
void list::ev(int i)//定义ev(int i)
{ int a=0,b=0,c=0,d=0,e=0,f=0;
student *temp=first;if(temp!=0)
{switch((int)temp->outgrade(i)/10)
{
case 10:a++;break;case 9:a++;break;
case 8:b++;break;case 7:c++;break;
case 6:d++;break;case 5:e++;break;
default:f++;
}
temp=temp->next;
}
cout<<"100-90、"<<a<<"89-80、"<<b<<"79-70、"<<c
<<"69-60、"<<e<<"59-50、"<<"50以下"<<f
<<"及格"<<(a+b+c+d)/(a+b+c+d+e+f)*100<<'%'<<endl;
}
void list::search(char s[10])
{
student *temp=first;for(;temp!=NULL;temp=temp->next)
if(strcmp(temp->outname(),s)==0)temp->intgrade();
}
#endif
void main()
{
list will;
int m=0;
do{
cout<<" 学 生 成 绩 管 理 系 统\n";
cout<<" ┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓\n"
<<" ┃录 入 成 绩 ┇ 请 按 1 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃查 询 成 绩 ┇ 请 按 2 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃修 改 成 绩 ┇ 请 按 3 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃删 除 成 绩 ┇ 请 按 4 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃分 析 成 绩 ┇ 请 按 5 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃各分数段人数和及格率 ┇ 请 按 6 并 确 定 ! ┃\n"
<<" ┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┛\n";
cin>>m;
switch(m)
{
case 1:
will.instu();
break;
case 2:
char n[9];
cout<<"请输入姓名\n";
cin>>n;
will.outstu(n);
cout<<"\n";
break;
case 3:
char nb[9];
cout<<"请输入姓名\n";
cin>>nb;
will.outstu(nb);
cout<<"\n";
will.search(nb);
break;
case 4:
char naa[9];
cout<<"请输入姓名\n";
cin>>naa;
will.outstu(naa);
will.delstu(naa);
break;
case 5:
will.think();
break;
}
cout<<"1,继续2,退出\n";
cin>>m;
}
while(m==1);
}