?? 學生管理系統(tǒng).cpp
字號:
#include<iostream>
#include<string>
using namespace std;
class stu
{
int num;
char class_o[20];
char name[20];
double elec,c_prog,media,eng,math,sport,polity,average,sum;
public:
stu()
{
}
stu(int m,char cl[20],char n[20],double el,double c_pro,double med,double en,double ma,double sp,double po)
{
num=m;
strcpy(name,n);
strcpy(class_o,cl);
elec=el;
c_prog=c_pro;
media=med;
eng=en;
math=ma;
sport=sp;
polity=po;
}
double getsum()
{
sum=c_prog+media+elec+eng+math+sport+polity;
return sum;
}
double getaver()
{
average=getsum()/7;
return average;
}
friend void main();
};
void main()
{
cout<<" "<<endl;
cout<<" * * * * * * * * * * * * 歡迎來到學籍管理系統(tǒng) * * * * * * * * * * *"<<endl;
cout<<" * ★★★★ 請選擇您要的操作 ★★★★ *"<<endl;
cout<<" * A: 操作: *"<<endl;
cout<<" * (0)數(shù)據(jù)錄入 (1)增加人員 *"<<endl;
cout<<" * (2)刪除人員 (3)修改數(shù)據(jù) *"<<endl;
cout<<" * B: 查詢: *"<<endl;
cout<<" * (4)按總成績查詢 (5)按姓名查詢 *"<<endl;
cout<<" * (6)輸出所有學生的數(shù)據(jù) *"<<endl;
cout<<" * C: 成績: *"<<endl;
cout<<" * (7)按總分查詢排名 (8)按c++程序設計成績查詢排名 *"<<endl;
cout<<" * (9)按電子技術成績查詢排名 (10)按大學外語成績查詢排名 *"<<endl;
cout<<" * (11)按大學體育成績查詢排名 (12)按高等數(shù)學成績查詢排名*"<<endl;
cout<<" * (13)按馬政經成績查詢排名 (y)按多媒體技術成績查詢排名*"<<endl;
cout<<" * *"<<endl;
cout<<" * ★★★★請輸入相應的數(shù)字★★★★ *"<<endl;
cout<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl;
char p;char w;
stu *s[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;
int num;
char class_o[20],name[20];double elec,c_prog,media,eng,math,sport,polity;
do{
cout<<"請輸入班級:";
cin>>class_o;
cout<<"請輸入學號:";
cin>>num;
cout<<"請輸入姓名:";
cin>>name;
cout<<"請輸入電子技術成績:";
cin>>elec;
cout<<"請輸入c++程序設計成績:";
cin>>c_prog;
cout<<"請輸入多媒體技術成績:";
cin>>media;
cout<<"請輸入大學外語成績:";
cin>>eng;
cout<<"請輸入高等數(shù)學成績:";
cin>>math;
cout<<"請輸入大學體育成績:";
cin>>sport;
cout<<"請輸入馬政經成績:";
cin>>polity;
cout<<"班級"<<class_o<<"學號"<<num<<"姓名"<<name<<"電子技術"<<elec<<"c++程序設計"<<c_prog<<"多媒體技術"<<media
<< "大學外語"<<eng<<"高等數(shù)學"<<math<<"大學體育"<<sport<<"馬政經"<<polity<<endl;
j++;
s[i]=new stu(num,class_o,name, elec, c_prog, media,eng,math,sport,polity);
i++;
cout<<"數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎(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 '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<<"您想繼續(xù)查詢嗎?(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<<"您想繼續(xù)查詢嗎?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '1':
{
int num;
char class_o[20],name[20];double elec,c_prog,media,eng,math,sport,polity;
char c;
do
{
cout<<"請輸入您要增加的學生的班級、學號和姓名:"<<endl;
cin>>class_o>>num>>name;
cout<<"請輸入電子技術成績:"<<endl;
cin>>elec;
cout<<"請輸入c++程序設計成績:"<<endl;
cin>>c_prog;
cout<<"請輸入多媒體技術成績:"<<endl;
cin>>media;
cout<<"請輸入大學外語成績:"<<endl;
cin>>eng;
cout<<"請輸入高等數(shù)學成績:"<<endl;
cin>>math;
cout<<"請輸入大學體育成績:"<<endl;
cin>>sport;
cout<<"請輸入馬政經成績:"<<endl;
cin>>polity;
cout<<"班級"<<class_o<<"學號"<<num<<"姓名"<<name<<"電子技術成績"<<elec<<"c++程序設計成績"<<c_prog<<"多媒體技術成績"<<media
<<"大學外語"<<eng<<"高等數(shù)學"<<math<<"大學體育"<<sport<<"馬政經"<<polity<<endl;
j++;
s[i]=new stu(num,class_o,name, elec, c_prog, media,eng,math,sport,polity);
i++;
cout<<"數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎(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<<"要繼續(xù)刪除嗎?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
int num;
char name[20];double ele,c_pro,med,en,ma,sp,po;flag2=0;
char c;
do
{
cout<<"請輸入您要修改的學生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"請輸入新的電子技術成績:"<<endl;
cin>>ele;
cout<<"請輸入新的C++程序設計成績:"<<endl;
cin>>c_pro;
cout<<"請輸入新的多媒體技術成績:"<<endl;
cin>>med;
cout<<"請輸入新的大學外語成績:"<<endl;
cin>>en;
cout<<"請輸入新的高等數(shù)學成績:"<<endl;
cin>>ma;
cout<<"請輸入新的大學體育成績:"<<endl;
cin>>sp;
cout<<"請輸入新的馬政經成績:"<<endl;
cin>>po;
s[h]->c_prog=c_pro;
s[h]->elec=ele;
s[h]->media=med;
s[h]->eng=en;
s[h]->math=ma;
s[h]->sport=sp;
s[h]->polity=po;
cout<<"數(shù)據(jù)修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的學生本來就不存在!請檢查重新輸入!"<<endl;
}
cout<<"想繼續(xù)修改嗎(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '6':
{
cout<<"本系統(tǒng)所有學生數(shù)據(jù)如下:"<<endl;
if(i==0)
cout<<"管理系統(tǒng)中沒有錄入數(shù)據(jù)或者數(shù)據(jù)已經被刪除!"<<endl;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"班級"<<" "<<s[k]->class_o<<"學號"<<" "<<s[k]->num<<"姓名:"<<" "<<s[k]->name<<
"c++程序設計:"<<" "<<s[k]->c_prog<<"電子技術:"<<" "<<s[k]->elec
<<"多媒體技術:"<<" "<<s[k]->media<<"大學外語: "<<" "<<s[k]->eng
<<"高等數(shù)學: "<<" "<<s[k]->math<<"大學體育: "<<" "<<s[k]->sport
<<"馬政經: "<<" "<<s[k]->polity<<"總分:"<<" "<<(*s[k]).getsum()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -