大神们帮忙改成C程序(学生管理系统)
#include<iostream>#include<cstring>
#include<stdio.h>
#include<fstream> //主要包含文件操作的类和方法
#include<time.h> /*文件里面有对某些时间函数的原型。原型的函数定义放在库文件里*/
using namespace std;
class student
{
private:
char xh[20];
char name[50];
double math;
double history;
double english;
double average;
double sum;
public:
student()
{
}
student(char xh1[20],char name1[50],double ma,double his,double eng)
{
strcpy(name,name1);
strcpy(xh,xh1);
math=ma;
history=his;
english=eng;
}
double getsum()
{
sum=history+english+math;
return sum;
}
double getaver()
{
average=getsum()/3.0;
return average;
}
friend void main();
};
void main()
{ char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
time_t timep;
time(&timep);
struct tm *p;
p=localtime(&timep); /* 获取当前时间*/
{ cout<<" ";
cout<<"**************欢迎进入******************"<<endl;
printf(" 【%d年%02d月%02d日 ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%s %02d:%02d:%02d】\n",week[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);
cout<<" ";
cout<<"************学生管理系统****************"<<endl<<endl;
cout<<" *控制台* "<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" * * * * * * ** 输入你的选择,并按回车结束 * * * * * * * * *"<<endl;
cout<<" * * 请选择你所需要的操作: * *"<<endl;
cout<<" * * (0)信息输入 * (5)按历史排名 * *"<<endl;
cout<<" * * (1)增加人员 * (6)输出所有学生的信息 * *"<<endl;
cout<<" * * (2)删除人员 * (7)按总分查询排名 * *"<<endl;
cout<<" * * (3)修改信息 * (8)退出 * *"<<endl;
cout<<" * * (4)按数学排名 * (9)按英语排名 * *"<<endl;
cout<<" * * 退出按8 * (a)按平均分排名 * *"<<endl;
cout<<" * * *-*-*-*-*-* * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * *"<<endl;
cout<<" * * * * * * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *"<<endl;
cout<<" ***选择相关操作请输入相对的括号里的阿拉伯数字!"<<"***"<<endl;
}
char a;
char b;
student *stu[80];
ofstream *file[80];
int i=0;
int j=0;
bool flag2=0;
do
{ cin>>a;
if((a>='0'&&a<='10'))
flag2=1;
else
cout<<"输入错误!请重新输入:"<<endl;
}
while(flag2==0);
do{
switch(a)
{
case '0':
{
char c;
char xh[20];
char name[50];
double math;
double history;
double english;
do{
cout<<"请输入学号"<<endl;
cin>>xh;
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入历史成绩:"<<endl;
cin>>history;
cout<<"请输入英语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"学号"<<xh<<"姓名"<<name<<"数学成绩"<<math<<"历史成绩"<<history<<"英语成绩"<<english<<endl;
j++;
stu[i]=new student(xh,name, math, history, english);
i++;
cout<<"信息录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"输入错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}
while(flag2==0);
}while(c=='y');
break;
}
case '1':
{ char xh[20];
char name[50];
double math;
double history;
double english;
char c;
do
{
cout<<"请输入您要增加的学生的学号:"<<endl;
cin>>xh;
cout<<"请输入您要增加的学生的姓名:"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入历史成绩:"<<endl;
cin>>history;
cout<<"请输入英语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"学号"<<xh<<"姓名"<<name<<"数学成绩"<<math<<"历史成绩"<<history<<"英语成绩"<<english<<endl;
j++;
stu[i]=new student(xh,name,math,history,english);
i++;
cout<<"信息录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"输入错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '2':
{
char name[50];
bool flag3=0;
char c;
do{
cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,stu[h]->name)==0)
{
flag3=1;
i--;
do{
stu[h]=stu[h+1];
h++;
}
while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的学生本来就不存在!请检查输入的正 确性!";
cout<<"要继续删除吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"输入错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
char name[50];
double mat;
double his;
double eng;
flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,stu[h]->name)==0)
{
flag2=1;
cout<<"请输入新的数学成绩:"<<endl;
cin>>mat;
cout<<"请输入新的历史成绩:"<<endl;
cin>>his;
cout<<"请输入新的英语成绩:"<<endl;
cin>>eng;
stu[h]->history=his;
stu[h]->math=mat;
stu[h]->english=eng;
cout<<"信息修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"输入错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '4':
{
student e;
cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if((stu[x]->math)>(stu[y]->math))
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
case '5':
{
student e;
cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if((stu[x]->history)>(stu[y]->history))
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
case '6':
{
student e;
cout<<"本系统所有学生排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if(strcmp((stu[x]->xh),(stu[y]->xh))<0)
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
if(i==0)
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
case '7':
{
student e;
cout<<"本系统所有学生排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if((stu[x]->getsum())>(stu[y]->getsum()))
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
case '8':
{char ch;
fflush(stdin); /*刷新标准输入缓冲区,把输入缓冲区里的东西丢弃*/
cout<<"是否退出?(y/n)";
cin>>ch;
if(ch=='y')
exit(0);
}/*这个是stdlib的标准库函数,作用是调用操作系统功能结束程序并将参数0作为程序的返回值。
会释放掉程序运行中分配的各种资源,例如会释放掉分配的内存块、安全关闭打开的文件等。
exit(0) 用于程序正常结束*/
break;
case '9':
{
student e;
cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if((stu[x]->english)>(stu[y]->english))
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
case 'a':
{
student e;
cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
for(int x=0;x<i;x++)
{
for(int y=0;y<i;y++)
{
if((stu[x]->getaver())>(stu[y]->getaver()))
{
e=*stu[x];
*stu[x]=*stu[y];
*stu[y]=e;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
cout<<"名次"<<" "<<"学号"<<" "<<"姓名"<<" "<<"历史"<<" "<<"数学"<<" "<<"英语"<<" "<<"总分"<<" "<<"平均分"<<endl;
for(int k=0;k<i;k++)
{
cout<<" "<<k+1<<" "<<stu[k]->xh<<" "<<stu[k]->name<<" "<<stu[k]->history<<" "<<stu[k]->math<<" "<<stu[k]->english<<" "<<stu[k]->getsum()
<<" "<<stu[k]->getaver()<<endl<<endl;
}
break;
}
}
cout<<endl;
cout<<"您想继续进行其他操作(y)"<<endl;
bool flag4=0;
do
{
cin>>b;
if(b!='y'&&b!='n')
cout<<"输入错误!请重新输入!"<<endl;
else
flag4=1;
}
while(flag4==0);
if(b=='y')
cout<<" *控制台* "<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" * * * * * * ** 输入你的选择,并按回车结束 * * * * * * * * *"<<endl;
cout<<" * * 请选择你所需要的操作: * *"<<endl;
cout<<" * * (0)信息输入 * (5)按历史排名 * *"<<endl;
cout<<" * * (1)增加人员 * (6)输出所有学生的信息 * *"<<endl;
cout<<" * * (2)删除人员 * (7)按总分查询排名 * *"<<endl;
cout<<" * * (3)修改信息 * (8)退出 * *"<<endl;
cout<<" * * (4)按数学排名 * (9)按英语排名 * *"<<endl;
cout<<" * * 退出按8 * (a)按平均分排名 * *"<<endl;
cout<<" * * *-*-*-*-*-* * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * *"<<endl;
cout<<" * * * * * * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *"<<endl;
cout<<" ***选择相关操作请输入相对的括号里的阿拉伯数字!"<<"***"<<endl;
cin>>a;
}
while(b=='y');
cout<<"已退出程序"<<endl;
for(int x=0;x<i;x++)
{
delete stu[x];
}
}