这已经是我第三次写成绩管理系统了,第一次写是大一上期末的大作业
第二次是大一下刚开学 学会链表后写的一份 这次是为了一群小屁孩
这些东西太简单 已经不想在写了。。。.后天上课要是不听话,我就。。
好吧 ,我是一个好老师 不会随便打人的。。。。。。。希望听话呀
温馨提示:要CV的朋友记得在D盘创建一个文件夹 D:\\scores_gover\\scores.txt
#include<iomanip>
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<fstream>
using namespace std;
#define MAX 50 //学生人数最多为50
struct student
{
char name[20];
char number[20];
float chinese;//语文
float math;//数学
float english;//英语
float sum;//总分
};
struct Node
{
student a[MAX];
int length;
};
void logo(); // 登录
void input(); //录入学生的成绩
void search() ; //根据姓名或者学号来查找学生的信息
void reset(); //修改学生的成绩
void add() ; //添加学生的信息
void del() ;//删除学生的信息
void sort() ; //对学生的总分进行排序
void print();//打印所有学生的信息
void exits();//退出系统
void menu();//打印菜单
void danke_sort(); //单科成绩进行排序
void loser(); //单科及格人数
void get_average() ; //计算平均成绩
void average_rank() ;//根据平均成绩排名次
int main()
{
logo();
Node L;
while(1)
{
cout<<"*********"<<endl;
cout<<endl;
cout<<"\t\t\t\t请输入你想要实现的功能"<<endl;
cout<<endl<<endl;;
menu();
int k;
cin>>k;
switch(k)
{
case 1:
input();
break;
case 2:
search();
break;
case 3:
reset();
break;
case 4:
add();
break;
case 5:
del();
break;
case 6:
sort();
break;
case 7:
print();
break;
case 8:
danke_sort();
break;
case 9:
loser();
break;
case 10:
get_average();
break;
case 11:
average_rank();
break;
case 12:
exits();
break;
default:
cout<<"输入错误"<<endl;
}
system("pause");
system("cls");
}
return 0;
}
void logo() //登录功能
{
cout<<"\t\t\t\t欢迎来到成绩管理系统\t\t\t\t"<<endl;
cout<<"\t\t\t\t"<<endl;
cout<<"\t\t\t\t"<<endl;
system("color 04"); // 第一个数字代表背景色,第二个数字代表字体的颜色
char us[]="132728"; //初始化用户名
char pas[]="123456"; // 初始化密码
char user[20]; //设置登录的用户名
char password[20]; //设置登录的密码
char p;
int i,k=3;
cout<<"一共三次登录的机会"<<endl;
while(k>0)
{
i=0;
cout<<"请输入用户名"<<endl;
gets(user);
cout<<"请输入密码"<<endl;
while((p=getch())!='\r')
{
if(p=='\b')
{
cout<<'\b'<<' '<<'\b';
if(i>0);
{
i--;
}
}
else
{
password[i]=p;
cout<<"*";
i++;
}
}
password[i]='\0';
if(strcmp(us,user)==0&&strcmp(pas,password)==0)
{
system("cls");
cout<<endl<<endl;
cout<<"\t\t\t\t\t";
cout<<"登录成功"<<endl;
system("color 4e");
break;
}
else
{
k--;
cout<<"您还有"<<k<<"次登录的机会"<<endl;
system("pause");
system("cls");
}
}
if(k==0)
{
cout<<"三次都输出错误"<<endl;
system("pause");
exit(0);
}
}
void input() //录入学生的成绩
{
ofstream file; //输出到文件上
Node L;
L.length=0;
cout<<"是否清空所有学生后全部重新输入Y/N?"<<endl;
char key;
do
{
cin>>key;
}while(key!='y'&&key!='Y'&&key!='N'&&key!='n');
if(key=='y'||key=='Y')
{
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
}
else
{
return ;
}
int i=0;
cout<<"你想录入几个学生的成绩"<<endl;
int n;
cin>>n;
while(i<n)
{
cout<<"请输入第"<<i+1<<"个学生的姓名"<<endl;
setbuf(stdin,NULL); //清空缓冲区
gets(L.a[i].name);
file<<L.a[i].name<<" ";
cout<<"请输入第"<<i+1<<"个学生的学号"<<endl;
gets(L.a[i].number);
file<<L.a[i].number<<" ";
cout<<"请输入第"<<i+1<<"个学生的语文成绩"<<endl;
cin>>L.a[i].chinese;
file<<L.a[i].chinese<<" ";
cout<<"请输入第"<<i+1<<"个学生的数学成绩"<<endl;
cin>>L.a[i].math;
file<<L.a[i].math<<" ";
cout<<"请输入第"<<i+1<<"个学生的英语成绩"<<endl;
cin>>L.a[i].english;
file<<L.a[i].english<<" ";
L.a[i].sum=L.a[i].chinese+L.a[i].math+L.a[i].english;
file<<L.a[i].sum<<" "<<endl;
i++;
system("cls"); //清屏
}
}
void search() //根据姓名或者学号来查找学生的信息
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause"); //屏幕上会显示按任意键继续
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有录入学生成绩"<<endl;
system("pause");
return ;
}
else
{
int key;
cout<<"你想根据姓名查找还是根据学号来查找 ,姓名1:学号2"<<endl;
do
{
cin>>key;
}
while(key!=1&&key!=2); //只能输入1 或者 2
if(key==1)
{
char name[20];
cout<<"请输入你要查找的名字"<<endl;
setbuf(stdin,NULL);
gets(name);
int i=0;
while(i<L.length)
{
if(strcmp(name,L.a[i].name)==0)
{
cout<<"这个学生的信息是"<<endl;
cout<<"姓名:"<<L.a[i].name<<"\t学号:"<<L.a[i].number;
cout<<"\t语文:"<<L.a[i].chinese<<"\t数学:"<<L.a[i].math;
cout<<"\t英语:"<<L.a[i].english<<endl;
return ;
}
i++;
}
cout<<"没有找到这个学生的信息傲"<<endl;
system("pause");
return ;
}
else if(key==2)
{
char number[20];
cout<<"请输入你要查找的学号"<<endl;
setbuf(stdin,NULL);
gets(number);
int i=0;
while(i<L.length)
{
if(strcmp(number,L.a[i].number)==0)
{
cout<<"这个学生的信息是"<<endl;
cout<<"姓名:"<<L.a[i].name<<"\t学号:"<<L.a[i].number;
cout<<"\t语文:"<<L.a[i].chinese<<"\t数学:"<<L.a[i].math;
cout<<"\t英语:"<<L.a[i].english<<"\t总分:"<<L.a[i].sum<<endl;
return ;
}
i++;
}
}
cout<<"没有找到这个学生的信息傲"<<endl;
system("pause"); //
return ;
}
}
void reset() //修改学生的成绩
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有录入学生成绩"<<endl;
system("pause");
return ;
}
else
{
int key;
cout<<"你想根据姓名查找还是根据学号来查找 ,姓名1:学号2"<<endl;
setbuf(stdin,NULL);
do
{
cin>>key;
}
while(key!=1&&key!=2); //只能输入1 或者 2
if(key==1)
{
char name[20];
cout<<"请输入你要查找的名字"<<endl;
setbuf(stdin,NULL);
gets(name);
i=0;
while(i<L.length)
{
if(strcmp(name,L.a[i].name)==0)
{
cout<<"这个学生的信息是"<<endl;
cout<<"姓名:"<<L.a[i].name<<"\t学号:"<<L.a[i].number;
cout<<"\t语文:"<<L.a[i].chinese<<"\t数学:"<<L.a[i].math;
cout<<"\t英语:"<<L.a[i].english<<"\t总分: "<<L.a[i].sum<<endl;
cout<<"请输入修改的姓名"<<endl;
setbuf(stdin,NULL);
cin>>L.a[i].name;
cout<<"请输入修改的学号"<<endl;
setbuf(stdin,NULL);
cin>>L.a[i].number;
cout<<"请输入要修改的语文成绩"<<endl;
cin>>L.a[i].chinese;
cout<<"请输入要修改的数学成绩"<<endl;
cin>>L.a[i].math;
cout<<"请输入要修改的英语成绩"<<endl;
cin>>L.a[i].english;
L.a[i].sum=L.a[i].chinese+L.a[i].math+L.a[i].english;
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
for(i=0; i<=L.length-1; i++)
{
file<<L.a[i].name<<" "<<L.a[i].number<<" "<<L.a[i].chinese<<" "<<L.a[i].math<<" "<<L.a[i].english<<" "<<L.a[i].sum<<" "<<endl;
}
file.close();
cout<<"修改完毕"<<endl;
system("pause");
return ;
}
i++;
}
if(i==L.length)
{
cout<<"没有找到这个学生的信息傲"<<endl;
system("pause");
return ;
}
}
else if(key==2)
{
char number[20];
cout<<"请输入你要查找的学号"<<endl;
setbuf(stdin,NULL);
gets(number);
i=0;
while(i<L.length)
{
if(strcmp(number,L.a[i].number)==0)
{
cout<<"这个学生的信息是"<<endl;
cout<<"姓名:"<<L.a[i].name<<"\t学号:"<<L.a[i].number;
cout<<"\t语文:"<<L.a[i].chinese<<"\t数学:"<<L.a[i].math;
cout<<"\t英语:"<<L.a[i].english<<"\t总分: "<<L.a[i].sum<<endl;
cout<<"请输入修改的姓名"<<endl;
setbuf(stdin,NULL);
cin>>L.a[i].name;
cout<<"请输入修改的学号"<<endl;
setbuf(stdin,NULL);
cin>>L.a[i].number;
cout<<"请输入要修改的语文成绩"<<endl;
cin>>L.a[i].chinese;
cout<<"请输入要修改的数学成绩"<<endl;
cin>>L.a[i].math;
cout<<"请输入要修改的英语成绩"<<endl;
cin>>L.a[i].english;
L.a[i].sum=L.a[i].chinese+L.a[i].math+L.a[i].english;
cout<<"修改完毕"<<endl;
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
for(i=0; i<=L.length-1; i++)
{
file<<L.a[i].name<<" "<<L.a[i].number<<" "<<L.a[i].chinese<<" "<<L.a[i].math<<" "<<L.a[i].english<<" "<<L.a[i].sum<<" "<<endl;
}
system("pause");
return ;
}
i++;
}
if(i==L.length)
{
cout<<"没有找到这个学生的信息傲"<<endl;
system("pause");
return ;
}
}
}
}
void add() //添加学生的信息
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生的成绩被录入傲"<<endl;
system("pause");
return ;
}
else
{
cout<<"你想插入在哪个位置"<<endl;
cout<<1<<"---"<<L.length+1<<endl;
cout<<"只能是其中一个"<<endl;
int key;
setbuf(stdin,NULL);
do
{
cin>>key;
}
while(key<1||key>L.length+1); //如果超出了范围就让他重新输入
for(i=L.length; i>=key; i--)
{
L.a[i]=L.a[i-1];
}
cout<<"请输入你要插入学生的姓名"<<endl;
setbuf(stdin,NULL);
gets(L.a[i].name);
cout<<"请输入你要插入学生的学号"<<endl;
setbuf(stdin,NULL);
gets(L.a[i].number);
cout<<"请输入你要插入学生的语文"<<endl;
cin>>L.a[i].chinese;
cout<<"请输入你要插入学生的数学"<<endl;
cin>>L.a[i].math;
cout<<"请输入你要插入学生的英语"<<endl;
cin>>L.a[i].english;
L.a[i].sum=L.a[i].chinese+L.a[i].math+L.a[i].english;
L.length=L.length+1;
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
for(i=0; i<=L.length-1; i++)
{
file<<L.a[i].name<<" "<<L.a[i].number<<" "<<L.a[i].chinese<<" "<<L.a[i].math<<" "<<L.a[i].english<<" "<<L.a[i].sum<<" "<<endl;
}
cout<<"插入成功"<<endl;
system("pause");
return ;
}
}
void del() //删除学生的信息
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生的信息"<<endl;
system("pause");
return ;
}
else
{
int key;
cout<<"你想删除第几个节点"<<endl;
cout<<"仅限于"<<1<<"---"<<L.length<<"个"<<endl;
setbuf(stdin,NULL);
do
{
cin>>key;
}
while(key<1||key>L.length);
for(i=key; i<=L.length-1; i++)
{
L.a[i-1]=L.a[i];
}
L.length--;
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
i=0;
for(i=0; i<=L.length-1; i++)
{
file<<L.a[i].name<<" "<<L.a[i].number<<" "<<L.a[i].chinese<<" "<<L.a[i].math<<" "<<L.a[i].english<<" "<<L.a[i].sum<<" "<<endl;
}
cout<<"删除成功"<<endl;
system("pause");
return ;
}
}
void sort() //对学生的总分进行排序
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生的信息"<<endl;
system("pause");
return ;
}
else
{
int j;
for(i=0; i<=L.length-2; i++)
{
for(j=0; j<=L.length-2-i; j++)
{
if(L.a[j].sum<L.a[j+1].sum)
{
student temp;
temp=L.a[j];
L.a[j]=L.a[j+1];
L.a[j+1]=temp;
}
}
}
}
file.open("D:\\scores_gover\\scores.txt",ios::out|ios::trunc);
if(file.is_open())
{
cout<<"打开文件成功"<<endl;
}
else
{
cout<<"打开失败"<<endl;
return ;
}
for(i=0; i<=L.length-1; i++)
{
file<<L.a[i].name<<" "<<L.a[i].number<<" "<<L.a[i].chinese<<" "<<L.a[i].math<<" "<<L.a[i].english<<" "<<L.a[i].sum<<" "<<endl;
}
cout<<"排序成功"<<endl;
system("pause");
}
void print()
{
int i=0;
Node L;
L.length=0;
ifstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--; //实际比理论多一个 所以减少一个
i=0;
while(i<=L.length-1)
{
cout<<"姓名:"<<std::left<<setw(16)<<L.a[i].name<<"学号:"<<std::left<<setw(16)<<L.a[i].number<<"语文:"<<std::left<<setw(16)<<L.a[i].chinese;
cout<<"数学:"<<std::left<<setw(16)<<L.a[i].math<<"英语:"<<std::left<<setw(16)<<L.a[i].english<<"总分:"<<std::left<<setw(16)<<L.a[i].sum<<endl;
i++;
}
}
void exits()
{
cout<<"退出程序"<<endl;
system("pause");
exit(0);
}
void menu()
{
cout<<"\t\t\t************************************"<<endl;
cout<<"\t\t\t*\t *"<<endl;
cout<<"\t\t\t*\t1.录入学生的信息 *"<<endl;
cout<<"\t\t\t*\t2.查找学生的信息 *"<<endl;
cout<<"\t\t\t*\t3.修改学生的信息 *"<<endl;
cout<<"\t\t\t*\t4.添加学生的信息 *"<<endl;
cout<<"\t\t\t*\t5.删除学生的信息 *"<<endl;
cout<<"\t\t\t*\t6.根据学生成绩的总分排名 *"<<endl;
cout<<"\t\t\t*\t7.输出所有学生的信息 *"<<endl;
cout<<"\t\t\t*\t8.按照单科成绩进行排序 *"<<endl;
cout<<"\t\t\t*\t9.单科不及格 *"<<endl;
cout<<"\t\t\t*\t10.计算机平均成绩 *"<<endl;
cout<<"\t\t\t*\t11.根据平均成绩排名 *"<<endl;
cout<<"\t\t\t*\t12.退出 *"<<endl;
cout<<"\t\t\t*\t *"<<endl;
cout<<"\t\t\t************************************"<<endl;
}
void danke_sort()
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生信息哟"<<endl;
return ;
}
cout<<"你想按照哪门功课排序1.语文 2. 数学 3.英语"<<endl;
int j;
int n;
cin>>n;
switch(n)
{
case 1:
for(i=0; i<=L.length-2; i++)
{
for(j=0; j<=L.length-i-2; j++)
{
if(L.a[j].chinese<L.a[j+1].chinese)
{
student temp;
temp=L.a[j];
L.a[j]=L.a[j+1];
L.a[j+1]=temp;
}
}
}
break;
case 2:
for(i=0; i<=L.length-2; i++)
{
for(j=0; j<=L.length-i-2; j++)
{
if(L.a[j].math<L.a[j+1].math)
{
student temp;
temp=L.a[j];
L.a[j]=L.a[j+1];
L.a[j+1]=temp;
}
}
}
break;
case 3:
for(i=0; i<=L.length-2; i++)
{
for(j=0; j<=L.length-i-2; j++)
{
if(L.a[j].english<L.a[j+1].english)
{
student temp;
temp=L.a[j];
L.a[j]=L.a[j+1];
L.a[j+1]=temp;
}
}
}
break;
}
cout<<endl;
i=0;
while(i<=L.length-1)
{
cout<<"姓名"<<L.a[i].name<<"\t学号:"<<L.a[i].number<<"\t语文"<<L.a[i].chinese;
cout<<"\t数学"<<L.a[i].math<<"\t英语"<<L.a[i].english<<"\t总分"<<L.a[i].sum<<endl;
i++;
}
}
void loser()
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生信息哟"<<endl;
return ;
}
cout<<"您想统计哪课不及格人数 1.语文 2.数学 3.英语"<<endl;
int n,num=0;
do
{
cin>>n;
}
while(n!=1&&n!=2&&n!=3);
Node temp;
temp.length=0;
switch(n)
{
case 1:
for(i=0; i<=L.length-1; i++)
{
if(L.a[i].chinese<90)
{
strcpy(temp.a[num].name,L.a[i].name);
strcpy(temp.a[num].number,L.a[i].number);
temp.a[num].chinese=L.a[i].chinese;
temp.a[num].math=L.a[i].math;
temp.a[num].english=L.a[i].english;
temp.a[num].sum=L.a[i].sum;
num++;
}
}
break;
case 2:
for(i=0; i<=L.length-1; i++)
{
if(L.a[i].math<90)
{
strcpy(temp.a[num].name,L.a[i].name);
strcpy(temp.a[num].number,L.a[i].number);
temp.a[num].chinese=L.a[i].chinese;
temp.a[num].math=L.a[i].math;
temp.a[num].english=L.a[i].english;
temp.a[num].sum=L.a[i].sum;
num++;
}
}
break;
case 3:
for(i=0; i<=L.length-1; i++)
{
if(L.a[i].english<90)
{
strcpy(temp.a[num].name,L.a[i].name);
strcpy(temp.a[num].number,L.a[i].number);
temp.a[num].chinese=L.a[i].chinese;
temp.a[num].math=L.a[i].math;
temp.a[num].english=L.a[i].english;
temp.a[num].sum=L.a[i].sum;
num++;
}
}
break;
}
switch(n)
{
case 1:
cout<<"语文";
break;
case 2:
cout<<"数学";
break;
case 3:
cout<<"英语";
break;
}
temp.length=num;
cout<<"不及格人数为"<<num<<"个"<<endl;
if(num!=0)
{
cout<<"这些学生的信息别分是"<<endl;
for(i=0; i<=temp.length-1; i++)
{
cout<<"姓名"<<temp.a[i].name<<"\t学号:"<<temp.a[i].number<<"\t语文"<<temp.a[i].chinese;
cout<<"\t数学"<<temp.a[i].math<<"\t英语"<<temp.a[i].english<<"\t总分"<<temp.a[i].sum<<endl;
}
}
}
void get_average() //计算平均成绩
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生信息哟"<<endl;
return ;
}
for(i=0; i<=L.length-1; i++)
{
float average=(L.a[i].chinese+L.a[i].math+L.a[i].english)/3;
cout<<"姓名"<<L.a[i].name<<"\t学号:"<<L.a[i].number<<"\t语文"<<L.a[i].chinese;
cout<<"\t数学"<<L.a[i].math<<"\t英语"<<L.a[i].english<<"\t总分"<<L.a[i].sum;
cout<<"\t平均成绩"<<average<<endl;
}
}
void average_rank() //根据平均成绩排名次
{
int i=0;
Node L;
L.length=0;
fstream file;
file.open("D:\\scores_gover\\scores.txt",ios::in);
if(!file.is_open())
{
cout<<"打开文件失败"<<endl;
system("pause");
return ;
}
else
{
while(!file.eof())
{
file>>L.a[i].name>>L.a[i].number>>L.a[i].chinese>>L.a[i].math>>L.a[i].english>>L.a[i].sum;
L.length++;
i++;
}
file.close();
}
L.length--;
if(L.length==0)
{
cout<<"还没有学生的信息"<<endl;
system("pause");
return ;
}
else
{
int j;
for(i=0; i<=L.length-2; i++)
{
for(j=0; j<=L.length-2-i; j++)
{
if(L.a[j].sum<L.a[j+1].sum)
{
student temp;
temp=L.a[j];
L.a[j]=L.a[j+1];
L.a[j+1]=temp;
}
}
}
}
int rank=1;
cout.setf(std::ios::left);
for(i=0; i<=L.length-1; i++)
{
float average=(L.a[i].chinese+L.a[i].math+L.a[i].english)/3;
cout<<"rank:"<<setw(10)<<rank<<"姓名:"<<setw(10)<<L.a[i].name<<"学号:"<<setw(10)<<L.a[i].number<<"语文:"<<setw(10)<<L.a[i].chinese;
cout<<"数学:"<<setw(10)<<L.a[i].math<<"英语:"<<setw(10)<<L.a[i].english<<"总分"<<setw(10)<<L.a[i].sum;
cout<<"平均成绩:"<<average<<endl;
if(i!=L.length-1&&L.a[i+1].sum!=L.a[i].sum)
{
rank++;
}
}
}