📄 student.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////
// 成绩管理系统 1.0版 //
// //
// 2005年1月5日 //
// //
// 阿牙 //
/////////////////////////////////////////////////////////////////////////////////
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip.h>
#include<conio.h>
class stu
{
char name[20];
double math,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],double ma,double chin,double eng)
{
strcpy(name,n);
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};
/*******************************主程序***********************************/
void main()
{
/*****************************遮掩密码********************************/
char lin(char aa[]);//lin函数声明
static char a[6]="admin";
static char b[6]="12345";
int q;
char QUIT;
static char r[6];
for (q=0;q<3;q++)
{
cout<<"请输入您的用户名: "<<" ";
cin>>r;
cout<<endl;
cout<<"请输入您的五位密码: "<<" ";
// cin>>aa;
cout<<endl;
static char aa[5];
lin(aa);//调用lin函数
if (strcmp(a,r)||strcmp(b,aa))
{
cout<<"错误!请重新输入. "<<endl;
}
else
{
cout<<endl;
getchar( );
cout<<"正确!欢迎进入学生管理系统. "<<endl;
getchar( );
q=3;
////////////////////////////////////////////////////////////////////////////////
/**********************************界面**************************************/
{
cout<<" ///////////////////////////////////////"<<endl;
cout<<" // 成绩管理系统 1.0版 //"<<endl;
cout<<" // //"<<endl;
cout<<" // 2005年1月7日 //"<<endl;
cout<<" ///////////////////////////////////////"<<endl;
cout<<" 请选择您需要的操作!"<<endl;
cout<<" ★编辑◎菜单★"<<endl;
cout<<" ※***********************************※"<<endl;
cout<<" @@(0)数据录入 @@"<<endl;
cout<<" @@(1)增加人员 @@"<<endl;
cout<<" @@(2)删除人员 @@"<<endl;
cout<<" @@(3)修改数据 @@"<<endl;
cout<<" ※***********************************※"<<endl;
cout<<" ★查询◎菜单★"<<endl;
cout<<" §***********************************§"<<endl;
cout<<" @@(4)按总成绩查询 @@"<<endl;
cout<<" @@(5)按姓名查询 @@"<<endl;
cout<<" @@(6)输出所有学生的数据 @@"<<endl;
cout<<" §***********************************§"<<endl;
cout<<" ★排名◎菜单★"<<endl;
cout<<" ◇***********************************◇"<<endl;
cout<<" @@(7)按总分查询排名 @@"<<endl;
cout<<" @@(8)按语文查询排名 @@"<<endl;
cout<<" @@(9)按数学查询排名 @@"<<endl;
cout<<" @@(y)按英语查询排名 @@"<<endl;
cout<<" ◇***********************************◇"<<endl;
cout<<" ★其它◎操作★"<<endl;
cout<<" △***********************************△"<<endl;
cout<<" @@(l)读取记录 @@"<<endl;
cout<<" @@(s)保存记录 @@"<<endl;
cout<<" @@(z)退出程序! @@"<<endl;
cout<<" △***********************************△"<<endl;
cout<<"选择相关操作请输入相对的括号里的指令!"<<endl;
cout<<"你的选择是:";
/********************************功能选择***********************************/
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='10'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do {
switch(p)
{
case '0':
{
char c;
char name[20];double math,chinese,english;
do {
cout<<"请输入姓名:";
cin>>name;
cout<<endl<<"请输入数学成绩:";
cin>>math;
cout<<endl<<"请输入语文成绩:";
cin>>chinese;
cout<<endl<<"请输入外语成绩:";
cin>>english;
file[j]=new ofstream("d: document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)";
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 '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');
break;
}
case '5':
{
char n[20];int j=0;char c;
do {
int flag=0;
cout<<"请输入你要查询的学生姓名"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的总成绩成绩是"<<(*s[j]).getsum()<<endl<<"平均成绩是:"<<(*s[j]).getaver()<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '1':
{
char name[20];double math,chinese,english;
char c;
do {
cout<<"请输入姓名:";
cin>>name;
cout<<endl<<"请输入数学成绩:";
cin>>math;
cout<<endl<<"请输入语文成绩:";
cin>>chinese;
cout<<endl<<"请输入外语成绩:";
cin>>english;
file[j]=new ofstream("d: document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, 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[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');
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -