c+++学生成绩管理系统.docx
《c+++学生成绩管理系统.docx》由会员分享,可在线阅读,更多相关《c+++学生成绩管理系统.docx(15页珍藏版)》请在冰点文库上搜索。
c+++学生成绩管理系统
c++学生成绩管理系统
C++实验报告
一、问题描述:
编写学生成绩管理系统,提供学生资料的输入,学生资料的输出,学生资料的
查询,学生资料删除,以及学生成绩的排序等。
二、系统设计:
整个管理系统的框架是这样的:
先定义一个结构,再定义一个类,其中类中包含输入成员函数,输出成员函数,查找成员函数,排序成员函数,删除成员函数以及检查函数。
主界面在主程序中输出.然后根据使用者输入的需要使用的模块所对应的(1—6)数字,而由主函数调用相对应的函数,完成使用者的需要,并且在主程序的开头还有对当前系统时间和日期的显示.
该程序共由六个模块构成,分别是:
输入模块,输出模块,查找模块,删除模块,排序模块,退出模块。
各模块的功能如下:
输入模块:
该模块用于接收用户输入的学生信息。
输出模块:
该模块用于输出用户输入的学生信息。
查找模块:
按照用户输入的学号进行查找相对应的学生信息,如果找到便显示该生信息;否则,显示未找到。
删除模块:
按照用户输入的学号进行查找相对应的学生信息,如果找到便显示该生信息并询问是否删除该信息,如果选择“是”就彻底删除该生信息;否则显示“未删除”,如果查找不到显示“未找到"。
排序模块:
按照总分进行从大到小的排序并显示排序后的学生信息.
退出模块:
退出该程序.
三、使用说明:
运行该学生成绩管理系统出现:
选1~6选择所要进行的操作即可。
四、源码清单
#includeh〉#includeh>#include〈ctime>#include〈conio。
h〉#include〈iostream〉
structstudent//定义一个学生结构体{
charname[8];
intnum;
charbj[20];
intGS,YY,C,SUM;};
ints=0;
classstudent1//定义一个学生类{
private:
studentstu[40];charname,bj;//姓名班级
intnum;//学号
intGS,YY,C,SUM;//高数,英语,c++,总分排序public:
voidsr(char*,int,char*,int,int,int);//输入模块
voidprint(int);//输出
/*intjc(intxxh){
intm=0;
while(m〈=s+1)if(xxh==stu[m++]。
num)break;
if(m〉s+1)
return0;
else
return1;
}*/
intjc(int);//用来判断学号是否重复/*{
intm;
for(m=0;m<=s+1;)
if(xxh==stu[m++]。
num)
break;
if(m>s+1)
return0;
else
return1;
}*/
/*else
return0;*/
//}
/*intjc(intxxh){
intm;
for(m=0;m〈s+1;m++)if(xxh==stu[m]。
num)break;
if(m>s+1)
return0;
else
return1;
}*/
/*intjc(intxxh){
for(m=0;m〈s+1;m++)
if(xxh=stu[m]。
num)
break;
if(m〉s+1)
return0;
else
return1;
}*/
/*intjc(intxxh){intm;
for(m=0;m〈s+1;m++)
if(xxh==stu[m].num)
{return1;
break;}
else
return0;//notallcontrolpathsreturnavalue
}*/
voidcz(int);//查找
voidsc(int);//删除
voidsum(int);//排序
};
intstudent1:
:
jc(intxxh)//用来判断学号是否重复{
intm;
for(m=0;m<=s+1;)
if(xxh==stu[m++].num)
break;
if(m〉s+1)
return0;
else
return1;
}
voidstudent1:
:
sr(char*xm,intxh,char*bj,intgs,intyy,intc)//输入模块
{
strcpy(stu[s].name,xm);stu[s]。
num=xh;
strcpy(stu[s].bj,bj);stu[s]。
GS=gs;
stu[s]。
YY=yy;
stu[s]。
C=c;
}
voidstudent1:
:
print(ints)//输出模块{
cout<〈s〈〈”\t";
cout〈〈stu[s]。
name〈〈”\t";cout〈bj<<"\t”;cout<〈stu[s].GS〈〈”\t”;cout<}
/*voidstudent1:
:
cz(ints)//查找模块{
intxxh,p;
if(s==0)
{
cout〈〈"没有记录,请先输入记录~”〈else//if(s!
=0)
{cout〈〈”请输入您要查找的学号:
";
cin〉〉xxh;
if(xxh〈100000||xxh〉999999)
{
cout〈<”您输入的学号不正确,请输入一个六位数的学号"〈〈endl;
cin〉〉xxh;
}
else//查找是否有符合条件的记录
{
for(p=0;p<=s;p++)
{if(xxh==stu[p].num)
cout〈〈”姓名\t学号\t班级\t高数\t英语\tC++”〈cout〈〈stu[p]。
name〈〈”\t”;
cout〈〈stu[p].num〈〈”\t";
cout<〈stu[p].bj〈〈"\t”;
cout〈GS<〈”\t”;
cout〈YY〈<”\t”;
cout<〈stu[p]。
C<<"\t”;
//getch();
break;
}
if(p〉s)//else
{
cout〈〈”很抱歉,没有找到您要查找的学号!
"〈〈endl;
//getch();
}
}
}
}*/
//运行结果与预期不同
voidstudent1:
:
cz(ints)//查找模块
{
intxxh,p;
while(s==0)
{
cout〈〈"没有记录,请先输入记录~”<〈endl;break;
}
if(s!
=0)
{cout〈<”请输入您要查找的学号:
";
cin〉>xxh;
while(xxh〈100000||xxh>999999)
//if(xxh〈100000||xxh>999999)//判断输入的学号是否正确{
cout〈〈”您输入的学号不正确,请输入一个六位数的学号”<〈endl;
cin>〉xxh;
}
//if
while(s!
=0)//查找是否有符合条件的记录{
p=1;
if(xxh==stu[s].num){
cout〈<”姓名\t学号\t班级\t高数\t英语\tC++"<cout<〈stu[s]。
name〈〈”\t";cout〈num〈<”\t”;cout〈〈stu[s]。
bj<<"\t";cout〈YY〈〈"\t";cout〈〈stu[s].C<〈endl;getch();
break;
}
else
p=0;
s——;
}
if(p==0)
cout<<”很抱歉,没有找到您要查找的学号!
”<〈endl;}getch();
}
voidstudent1:
:
sc(intn)//删除模块
{
intxxh,p;
charda;
//while
if(s==0)
{
cout〈〈”没有记录,请先输入记录~"<}
if(s!
=0)
{
cout〈<"请输入您要删除的学号:
";
cin〉〉xxh;
//while
if(xxh<100000||xxh>999999){
cout<〈”您输入的学号不正确,请您输入一个六位数的学号”〈cin>〉xxh;
}
for(inti=1;i〈=n;i++){
if(stu[i].num!
=xxh)
p=0;
if(stu[i].num==xxh)
{
cout<〈"姓名\t学号\t班级\t高数\t英语\tC++”〈〈endl;
cout<〈stu[i]。
name〈<”\t";cout<〈stu[i].num<〈”\t”;cout〈〈stu[i]。
bj〈<”\t”;cout〈〈stu[i]。
GS<<”\t”;cout〈YY<〈”\t";cout〈C<c〈〈endl;
cout〈<"您确实要删除该学生的记录吗?
(y/n)”;cin〉〉da;
if(da=='y’||da==’Y')//if(da=='y')
{
for(intj=i;j〈=n—1;j++)//删除记录
{
strcpy(stu[j]。
name,stu[j+1]。
name);
stu[j]。
num=stu[j+1]。
num;strcpy(stu[j]。
bj,stu[j+1]。
bj);stu[j]。
GS=stu[j+1]。
GS;stu[j]。
YY=stu[j+1].YY;stu[j]。
C=stu[j+1]。
C;
}
cout〈〈”该记录已删除!
”〈s=s—1;
p=1;
break;
}
else
{
cout〈〈”该记录未删除!
"〈〈endl;p=1;
}
}
}
if(p==0)
cout〈<”很抱歉,没有找到您要找的学号!
"〈〈endl;
}
getch();
}
voidstudent1:
:
sum(ints)//排序模块{
intchang;
intb[40];
while(s==0)
{
cout〈〈"没有记录,请先输入记录~”〈〈endl;break;
}
if(s!
=0)
{
cout<〈”姓名\t学号\t班级\t英语\t”;cout<〈”高数\tC++\t总分”<〈endl;
for(intk=1;k<=s;k++){
b[k]=stu[k]。
GS+stu[k].YY+stu[k]。
C;
stu[k]。
SUM=stu[k]。
GS+stu[k].YY+stu[k]。
C;
}
for(inti=1;i<=s;i++)//利用冒泡法对B[]进行排序for(intj=1;j<=s—i;j++)if(b[j]
{
chang=b[j];
b[j]=b[j+1];
b[j+1]=chang;
}
for(inth=1;h〈=s;h++)//输出与B[]中相同总分所对应的内容
for(inte=1;e〈=s;e++)if(b[h]==stu[e].SUM){
cout<〈stu[e]。
name<〈”\t”;cout<bj<〈"\t”;cout<〈stu[e]。
YY〈<”\t";cout〈GS〈〈”\t";cout<C〈〈"\t";cout<〈stu[e]。
SUM〈〈endl;}
}
getch();
}
voidmain()
{
student1st;
charda,a;
char*xm,*bj;
intgs,yy,c,xh;
time_tt;
time(&t);
while
(1)
{
system("cls");
cout〈〈”作者:
黄颖芳软件工程+电子商务2班”〈〈endl〈<”学号:
20092110110204”<〈endl;
cout<〈endl;
cout〈〈”学生成绩管理系统"〈〈endl;cout〈<”显示系统时间和日期:
"〈〈ctime(&t)<〈endl;//errorC2146:
syntaxerror:
missing';’beforeidentifier’cout’
cout〈〈”1.输入/添加学生资料”<〈endl;cout<<”2.显示学生资料”〈〈endl;cout<〈”3。
按学号查找”<cout〈〈"4。
删除记录"〈〈endl;
cout〈〈”5。
按总分进行排序”〈〈endl;cout<〈"6。
退出”〈cout<〈"请选择操作(1—6)"〈〈endl;cin〉〉a;
t:
if(a==’6’)break;
switch(a)
{
case'1’:
{
cout〈<"请依次输入学生的姓名,学号,班级,高数,英语,C++:
"〈〈endl;
xm=newchar[];bj=newchar[];cin〉〉xm>>xh>>bj〉〉gs>>yy>〉c;while(st。
jc(xh))//调用JC模块判断学号是否重复{
cout〈〈”学号重复,请重新输入~"<}
s=s+1;
st。
sr(xm,xh,bj,gs,yy,c);cout〈<"是否继续输入?
(y/n)”;
cin〉〉da;
while(da==’y'||da==’Y’)//判断是否要继续输入{
cout〈<”请依次输入学生的姓名,学号,班级,高数,英语,C++:
”〈xm=newchar[];bj=newchar[];cin〉〉xm〉〉xh〉>bj>〉gs>>yy〉>c;while(st。
jc(xh))
{
cout〈〈"学号重复,请重新输入~”〈〈endl;cin〉>xh;
}
s=s+1;
st.sr(xm,xh,bj,gs,yy,c);cout〈<”是否继续输入?
(y/n)”;
cin>〉da;
}
getch();
};break;
case’2’:
{
if(s==0)//判断是否有记录输入
{
cout<〈”没有记录,请先输入记录~”〈〈endl;getch();
break;
}
if(s!
=0)
{
cout〈<"序号”<<"\t”;
cout〈<"姓名"<〈”\t”;
cout〈〈"学号"<〈”\t";
cout〈〈"班级"<〈”\t”;
cout〈〈"高数"〈〈”\t”;
cout〈<”英语”<〈”\t";
cout〈<”C++”〈getch();
}
};break;
case'3’:
st.cz(s);break;case’4’:
st。
sc(s);break;case'5':
st。
sum(s);break;
default:
{
while(a=='0’||a〉'6’)//判断选项是否正确{
cout<<”错误选项,请重新选择~"<〈endl;cin>〉a;
}
gotot;
};break;
}
}
cout〈〈”谢谢您的使用!
”<〈endl;}