📄 c++课设.cpp
字号:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class stu//////类的定义
{
public:
stu()
{ strcpy(name,"");strcpy(number,"");
math=chinese=english=average=sum=0;
}
stu(char n[200],char num[200],double ma,double chin,double eng)
{
strcpy(name,n);
for(int i=0;i<200;++i)
number[i]=num[i];
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
private:
char name[200],number[200];
double math,chinese,english,average,sum;
};
void main()
{
cout<<" "<<endl;
cout<<" ㊣━━^-^o中華人民共和國o^-^━━㊣ "<<endl;
cout<<" ┃ 华东交通大学 ┃ "<<endl;
cout<<" ┃ 软件学院软件工程八班 ┃ "<<endl;
cout<<" ㊣━━^-^学生成绩查询系统^-^━━㊣ "<<endl;
cout<<" ★★★★ ★★★★ "<<endl;
cout<<" (0)数据录入 (1)文件读取 "<<endl;
cout<<" (2)删除人员 (3)修改数据 "<<endl;
cout<<" (4)总成绩查询 (5)姓名查询 "<<endl;
cout<<" (6)输出学生数据 (7)总分排名 "<<endl;
cout<<" (8)语文排名 (9)数学排名 "<<endl;
cout<<" (10)英语排名 (11)如有删除请保存 "<<endl;
cout<<" "<<endl;
cout<<" ★★★★请输入相应的代码★★★★ "<<endl;
cout<<" * * * * * * * * * * * * * * * * * * * * * * * * * * "<<endl;
int p;char w;
stu *s[200]={0};
int i=0,j=0;bool flag2=0; char c='y',nam[200],num[200];double mat,chin,eng;
cout<<" ▉▉▉▉▉▉▉▉▉▉▉▉▉ 99% ............."<<endl;
cout<<" "<<endl;
cout<<" LOADING SYSTEM:.................. "<<endl;
cout<<" "<<endl;
cout<<" 欢迎你使用本学生成绩查询系统:"<<endl;
cout<<" ^-^ 请选择相应操作代码^-^: ";
do///////////////起始指令判断
{
cin>>p;
if((p>=0&&p<=11))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
/////////////开辟存储空间
char *infilename="测试数据.dat";
ifstream infile(infilename,ios::in);
if(!infile)
cout<<" 指定文件名<"<<infilename<<">不存在,请仔细核对,系统将自动退出操作!"<<endl;
else
while(infile&&i<200)
{infile>>nam>>num>>mat>>chin>>eng;
s[i]=new stu(nam,num,mat,chin,eng);
++i;
}
i=i-1;
infile.close();
ofstream outfile("测试数据.dat",ios::app);
do{
switch(p)
{
case 0:///数据录入
{
do{ cout<<"请输入姓名:"<<endl;cin>>nam;
cout<<"请输入学号:"<<endl;cin>>num;
cout<<"请输入数学成绩:"<<endl;cin>>mat;
cout<<"请输入语文成绩:"<<endl;cin>>chin;
cout<<"请输入外语成绩:"<<endl;cin>>eng;
outfile<<nam<<" "<<num<<" "<<mat<<" "<<chin<<" "<<eng<<" "<<endl;
s[i]=new stu(nam,num,mat, chin, eng);
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');
outfile.close();system("cls");
break;
}
case 1:///文件读取
{ string infilena; cout<<" 请输入指定输入文件名:";cin>>infilena;
ifstream infile(infilena.c_str(),ios::in);cout<<endl;
if(!infile)
cout<<" 指定文件名<"<<infilename<<">不存在,请仔细核对,系统将自动退出操作!"<<endl;
else
while(infile&&i<200)
{ infile>>nam>>num>>mat>>chin>>eng;
s[i]=new stu(nam,num,mat,chin,eng);
++i;
}
infile.close();
break;
}
case 2:////删除人员
{char name[20];bool flag3=0;char c;
do
{cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
if(strcmp(name,s[h]->name)==0)
{ flag3=1;
i--;
do
{s[h]=s[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');system("cls");
break;
}
case 3://///修改数据 /
{bool found=false;
do
{cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>nam;
for(int h=0;h<i&&!found;++h)
{if(strcmp(nam,s[h]->name)==0)
{cout<<"请输入新的学号:"<<endl;
cin>>num;
cout<<"请输入新的数学成绩:"<<endl;
cin>>mat;
cout<<"请输入新的语文成绩:"<<endl;
cin>>chin;
cout<<"请输入新的外语成绩:"<<endl;
cin>>eng;
strcpy(s[h]->number,num);
s[h]->chinese=chin;
s[h]->math=mat;
s[h]->english=eng;
cout<<"数据修改成功!";found=true;
}
}
if(!found)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
system("cls");
break;
}
case 4:////总成绩查询
{double t;char c;
do
{int flag1=0;
cout<<"请输入你要查询学生的总成绩"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{if(s[q]->getsum()==t)
{flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
system("cls");
break;
}
case 5:////////姓名查询
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -