#include"fstream.h"
#include"windows.h"
#include
#include"string.h"
#include"cc.h"
struct stu
{
char name[50];
char gender[70];
int stunum;
double chinese;
double math;
double english;
}stu[100],x,y;
void choose();
void face();
void dayin();
void maxscore();
void scoreface();
void appstudent();
void addstudent();
void revisestudent();
void seekstudent();
void deletestudent();
void overstudent();
void revisestudent();
void addstudent()//******************录入信息
{
int flag;
fstream file;
system("cls");
cout<<" ------------------------------"<
file.open("E:/flag.txt",ios::in|ios::out|ios::binary);
cin>>flag;
file.write((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::out|ios::binary);
for(int i=0;i
cout<<"-----------------------------------"<
cout<<"请输入第"< cin>>x.gender;
cout<<"请输入第"< cin>>x.stunum;
cout<<"请输入第"< cin>>x.chinese;
cout<<"请输入第"< cin>>x.math;
cout<<"请输入第"< cin>>x.english;
cout<<"-----------------------------------"<
}
file.close();
face();
}
void appstudent()//******************添加信息
{
int k,flag;
fstream file;
system("cls");
cout<<"请问你要添加几个人的信息?"<
cin>>k;
file.open("E:/flag.txt",ios::in|ios::out|ios::binary);
file.read((char*)&flag,sizeof(flag));
flag=flag+k;
file.seekg(0,ios::beg);
file.write((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::out|ios::in|ios::binary|ios::app);
for(int i=0;i
cout<<"-----------------------------------"<
cout<<"请输入添加的第"<
cout<<"请输入添加的第"<
cout<<"请输入添加的第"<
cout<<"请输入添加的第"<
cout<<"请输入添加的第"<
file.write((char*)&x,sizeof(x));
}
file.close();
system("cls");
face();
}
void revisestudent()//***************修改信息
{
int n,flag,i,k=0,m;
fstream file;
cout<<" --------------------------------"<
cin>>n;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::out|ios::binary);
for(i=0;i<=flag;i++)
{
file.read((char*)&stu[i],sizeof(stu[i]));
}
file.close();
for(k;k
if(stu[k].stunum==n)
{
cout<<"请重新输入这个学生的姓名:";
cin>>stu[k].name;
cout<<"请重新输入这个学生的性别:";
cin>>stu[k].gender;
cout<<"请重新输入这个学生的学号:";
cin>>stu[k].stunum;
cout<<"请重新输入这个学生的语文成绩:";
cin>>stu[k].chinese;
cout<<"请重新输入这个学生的数学成绩:";
cin>>stu[k].math;
cout<<"请重新输入这个学生的英语成绩:";
cin>>stu[k].english;
cout<<"修改完毕"<
file.open("E:/student.txt",ios::out|ios::binary);
for(m=0;m
file.write((char*)&stu[m],sizeof(stu[m]));
}
file.close();
face();
}
}
if(stu[k].stunum!=n)
{
cout<<"您的输入有误!"<
face();
}
}
void seekstudent()//*****************查找信息
{
fstream file;
int n,flag,i=0,k=0;
system("cls");
cout<<" --------------------------------"<
cin>>n;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::out|ios::binary);
for(i=0;i<=flag;i++)
{
file.read((char*)&stu[i],sizeof(stu[i]));
}
file.close();
for(k;k
if(stu[k].stunum==n)
{
cout<<"这个学生的资料如下:"<
face();
}
}
if(stu[k].stunum!=n)
{
system("cls");
cout<<"查无此人!"<
}
}
void sortstudent()//*****************排序信息
{
int flag;
fstream file;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::binary);
for(int i=0;i<=flag;i++)
{
file.read((char*)&stu[i],sizeof(stu[i]));
}
for(i=0;i
if (stu[i].stunum>stu[j].stunum)
{
y=stu[i];
stu[i]=stu[j];
stu[j]=y;
}
}
file.close();
file.open("E:/student.txt",ios::out|ios::trunc|ios::binary);
for(i=0;i
file.write((char*)&stu[i],sizeof(stu[i]));
}
file.close();
cout<<"排序完毕!"<
face();
}
void deletestudent()//***************删除信息
{
char c;
int flag;
int n;
fstream file;
cout<<"请输入您要删除的学生的学号!"<
cin>>n;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::out|ios::binary);
for(int i=0;i<=flag;i++)
{
file.read((char*)&stu[i],sizeof(stu[i]));
}
for(int k=0;k
if(stu[k].stunum==n)
{
cout<<" -----------------------"<
flag=flag-1;
if (c == 'Y')
{
for(int j=k;j
stu[j]=stu[j+1];
}
}
else
{
face();
}
}
}
file.close();
file.open("E:/flag.txt",ios::in|ios::binary|ios::out);
file.seekg(0,ios::beg);
file.write((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::out|ios::trunc|ios::binary);
for(int m=0;m
file.write((char*)&stu[m],sizeof(stu[m]));
}
file.close();
cout<<"动作完成!"<
face();
}
void overstudent()//*****************浏览信息
{
int flag;
system("cls");
fstream file;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::binary);
for(int i=0;i
file.read((char*)&stu[i],sizeof(stu[i]));
cout<<" -------第"< cout<<" -------------------------"<
file.close();
system("pause");
system("cls");
face();
}
void scoreface()
{
int i;
system("cls");
BLACK_GREEN;cout<<"---------------------------------------------------"<
cin>>i;
switch(i)
{
case 1:
dayin();
break;
case 2:
maxscore();
break;
case 3:
face();
break;
case 0:
exit(0);
break;
default:
cout<<"选择有误!请重新选择!"<
face();
}
}
void dayin()
{
int flag;
system("cls");
fstream file;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::binary);
for(int i=0;i
file.read((char*)&stu[i],sizeof(stu[i]));
cout<<" -------第"< cout<<" -------------------------"<
file.close();
system("pause");
system("cls");
face();
}
void maxscore()
{
int flag;
double maxchinese,maxmath,maxenglish;
double pchinese=0,pmath=0,penglish=0;
system("cls");
fstream file;
file.open("E:/flag.txt",ios::in|ios::out);
file.read((char*)&flag,sizeof(flag));
file.close();
file.open("E:/student.txt",ios::in|ios::binary);
for(int i=0;i
file.read((char*)&stu[i],sizeof(stu[i]));
maxchinese=stu[0].chinese;
maxmath=stu[0].math;
maxenglish=stu[0].english;
if(maxchinese
maxchinese=stu[i].chinese;
}
if(maxmath
maxmath=stu[i].math;
}
if(maxenglish
maxenglish=stu[i].english;
}
pchinese+=stu[i].chinese;
pmath+=stu[i].math;
penglish+=stu[i].english;
}
cout<<" -------------------------"<
system("pause");
system("cls");
face();
}
/*-------------------------主界面*/
void face()
{
int i;
system("cls");
cout<<"Welcome to the student information management system!"<
cin>>i;
switch(i)
{
case 1:
addstudent();
break;
case 2:
appstudent();
break;
case 3:
revisestudent();
break;
case 4:
seekstudent();
break;
case 5:
sortstudent();
break;
case 6:
deletestudent();
break;
case 7:
overstudent();
break;
case 8:
scoreface();
break;
case 0:
exit(0);
break;
default:
cout<<"选择有误!请重新选择!"<
face();
}
}
void choose()
{
char c;
cout<<" -----------------------"<
if(c=='Y'||c=='y')
seekstudent();
else if(c=='N'||c=='n')
face();
else
choose();
}
void main(void)
{
face();
}