跪求一个C语言程序编写的学生信息管理系统,要求能够实现显示、保存功能。 高分悬赏 +1019531467 10

 我来答
风暴头脑
2012-01-05 · TA获得超过267个赞
知道小有建树答主
回答量:273
采纳率:0%
帮助的人:307万
展开全部
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
class student
{
public:
student()
{
strcpy(number,"");
strcpy(name,"");
strcpy(score,"");
}
set(char a[10],char b[20],char c[5])
{
strcpy(number,a);
strcpy(name,b);
strcpy(score,c);
}
output()
{
printf("%-10s%-15s%-5s\n",number,name,score);
}
out()
{
cout<<score<<endl;
}
friend change(student &a,student &b);
friend int i_change(student c);
friend int ii_change(student c);
friend operator >>(ostream &a,student b);
friend int tong(char a[10],student one);
friend float iii_change(student c);
friend int num(student c,int b);
private:
char number[10];
char name[20];
char score[5];
};

int i_change(student c)
{
int b;
if(c.score[0]=='1'&&c.score[1]=='0'&&c.score[2]=='0')
{
b=int(c.score[0])*1000+int(c.score[1])*100+int(c.score[2])*10;
return b;
}
else if(c.score[1]=='.')
{
b=int(c.score[0])*10+int(c.score[2]);
return b;
}
else if(c.score[2]=='.')
{
b=int(c.score[0])*100+int(c.score[1])*10+int(c.score[3]);
return b;
}
else if(c.score[1]=='\0')
{
b=int(c.score[0])*10;
return b;
}
else
{
b=int(c.score[0])*100+int(c.score[1])*10;
return b;
}
}

int ii_change(student c)
{
int b;
b=int(c.number[0])*1e6+int(c.number[1])*1e5+int(c.number[2])*1e4+int(c.number[3])\
*1e3+int(c.number[4])*1e2+int(c.number[5])*10+int(c.number[6]);
return b;
}

float iii_change(student c)
{
float b;
if(c.score[0]=='1'&&c.score[1]=='0'&&c.score[2]=='0')
{
return 100;
}
else if(c.score[1]=='.')
{
b=int(c.score[0])-48+(int(c.score[2])-48)*0.1;
return b;
}
else if(c.score[2]=='.')
{
b=(int(c.score[0])-48)*10+int(c.score[1])-48+(int(c.score[3])-48)*0.1;
return b;
}
else if(c.score[1]=='\0')
{
b=int(c.score[0])-48;
return b;
}
else
{
b=(int(c.score[0])-48)*10+(int(c.score[1])-48);
return b;
}
}

change(student &a,student &b)
{
student c;
strcpy(c.number,a.number);
strcpy(c.name,a.name);
strcpy(c.score,a.score);
strcpy(a.number,b.number);
strcpy(a.name,b.name);
strcpy(a.score,b.score);
strcpy(b.number,c.number);
strcpy(b.name,c.name);
strcpy(b.score,c.score);
}

operator >>(ostream &a,student b)
{
a.write(b.number,strlen(b.number));
a.seekp(10-strlen(b.number),ios::cur);
a.write(b.name,strlen(b.name));
a.seekp(15-strlen(b.name),ios::cur);
a.write(b.score,strlen(b.score));
}

int tong(char a[10],student one)
{
if(a[0]==one.number[0]&&a[1]==one.number[1]\
&&a[2]==one.number[2]&&a[3]==one.number[3]\
&&a[4]==one.number[4]&&a[5]==one.number[5]\
&&a[6]==one.number[6]&&a[7]==one.number[7]\
&&a[8]==one.number[8]&&a[9]==one.number[9])
return 0;
else return 1;
}

int num(student c,int b)
{
if(iii_change©<=b&&iii_change©>b-10) return 1;
else return 0;
}

main()
{
char a[10],b[20],c[5],d,h4,a1[9],a2[10],t[9],d1,t1[9],t2[9],t3[10];
student stu[10];
int h1,h2,h3=0,h5,h6=0,h7,h8,h9,h10,h11,h12,h13,h14=100,h15,h16;

float w=0;
fstream one("key.txt",ios::in),two,three;
one.read(a1,8);
one.close();
while(1)
{
cout<<"请输入8位登录密码:"<<endl;
cin>>t;
if(t[0]==a1[0]&&t[1]==a1[1]&&t[2]==a1[2]&&t[3]==a1[3]\
&&t[4]==a1[4]&&t[5]==a1[5]&&t[6]==a1[6]&&t[7]==a1[7]&&t[8]=='\0')
{
while(1)
{
cout<<endl;
cout<<"登录成功!欢迎光临学生成绩录入系统!"<<endl;
cout<<"请选择您需要的操作:"<<endl;
cout<<"1 录入学生成绩"<<endl;
cout<<"2 查看成绩列表"<<endl;
cout<<"3 打印成绩列表"<<endl;
cout<<"4 查询学生成绩"<<endl;
cout<<"5 统计学生成绩"<<endl;
cout<<"6 修改学生数据"<<endl;
cout<<"7 删除学生数据"<<endl;
cout<<"8 修改登录密码"<<endl;
cout<<"9 退出本系统"<<endl;
cin>>h2;
switch(h2)
{
case 1:
for(;h3<10;h3++)
{
cout<<endl;
cout<<"请输入学生学号:"<<endl;
cin>>a;
cout<<"请输入学生姓名:"<<endl;
cin>>b;
cout<<"请输入学生成绩(0-100):"<<endl;
cin>>c;
stu[h3].set(a,b,c);
h6++;
cout<<"需要继续输入吗(y/n)?"<<endl;
cin>>d;
if(d=='n')
{
cout<<"是否确定以上的输入(y/n)?"<<endl;
cin>>h4;
if(h4=='y')
{
h3++;
h6=0;
cout<<"输入成功!"<<endl;
break;
}
else
{
for(h5=h3-h6+1;h5<(h3+1);h5++)
{
stu[h5].set("","","0");
}
h3=h3-h6+1;
h6=0;
break;
}
}
}break;
case 2:
cout<<"请选择查看方式:"<<endl;
cout<<"1 按成绩查看"<<endl;
cout<<"2 按学号查看"<<endl;
cin>>h8;
if(h8==1)
{
for(h9=0;h9<h3-1;h9++)
{
for(h10=h9+1;h10<h3;h10++)
{
if(i_change(stu[h9])<i_change(stu[h10]))
{
change(stu[h9],stu[h10]);
}
}
}
}
if(h8==2)
{
for(h9=0;h9<h3-1;h9++)
{
for(h10=h9+1;h10<h3;h10++)
{
if(ii_change(stu[h9])>ii_change(stu[h10]))
{
change(stu[h9],stu[h10]);
}
}
}
}
cout<<"学号 姓名 成绩"<<endl;
for(h7=0;h7<h3;h7++)
{
stu[h7].output();
}break;
case 3:
cout<<endl;
cout<<"请选择打印方式:"<<endl;
cout<<"1 按成绩打印"<<endl;
cout<<"2 按学号打印"<<endl;
cin>>h1;
if(h1==1)
{
for(h9=0;h9<h3-1;h9++)
{
for(h10=h9+1;h10<h3;h10++)
{
if(i_change(stu[h9])<i_change(stu[h10]))
{
change(stu[h9],stu[h10]);
}
}
}
}
if(h1==2)
{
for(h9=0;h9<h3-1;h9++)
{
for(h10=h9+1;h10<h3;h10++)
{
if(ii_change(stu[h9])>ii_change(stu[h10]))
{
change(stu[h9],stu[h10]);
}
}
}
}
two.open("学生成绩.txt",ios::in|ios::out|ios::trunc);
two.write("学号 姓名 成绩",30);
h12=71;
for(h11=0;h11<h3;h11++)
{
two.seekp(h12,ios::beg);
two>>stu[h11];
h12+=71;
}
two.close();

cout<<"打印成功!"<<endl;break;
case 4:
cout<<endl;
cout<<"请输入需要查询的学生的学号:"<<endl;
cin>>a2;
for(h13=0;h13<h3;h13++)
{
h14=100;
if(tong(a2,stu[h13])==0)
{
h14=h13;
break;
}
}
if(h14==100) cout<<"查无此人!"<<endl;
else
{
cout<<"该学生的信息为:"<<endl;
stu[h14].output();
}break;
case 5:
for(h9=0;h9<h3-1;h9++)
{
for(h10=h9+1;h10<h3;h10++)
{
if(i_change(stu[h9])<i_change(stu[h10]))
{
change(stu[h9],stu[h10]);
}
}
}
cout<<"最高分是:"<<endl;
stu[0].out();
cout<<"最低分是:"<<endl;
stu[h3-1].out();
cout<<"平均分是:"<<endl;
w=0;
for(h9=0;h9<h3;h9++)
{
w+=iii_change(stu[h9]);
}
cout<<w/h3<<endl;
for(h15=10;h15<101;h15+=10)
{
int h16=0;
for(h9=0;h9<h3;h9++)
{
h16+=num(stu[h9],h15);
}
cout<<h15-10<<"-"<<h15<<"区间共有:"<<h16<<"人"<<endl;
}
break;
case 6:
cout<<endl;
cout<<"请输入需要修改的学生的学号:"<<endl;
cin>>a2;
for(h13=0;h13<h3;h13++)
{
h14=100;
if(tong(a2,stu[h13])==0)
{
h14=h13;
break;
}
}
if(h14==100) cout<<"查无此人!"<<endl;
else
{
cout<<endl;
cout<<"请重新输入该学生学号:"<<endl;
cin>>a;
cout<<"请重新输入该学生姓名:"<<endl;
cin>>b;
cout<<"请重新输入该学生成绩(0-100):"<<endl;
cin>>c;
stu[h14].set(a,b,c);
cout<<"数据修改成功!"<<endl;
}break;
case 7:
cout<<endl;
cout<<"请输入需要删除的学生的学号:"<<endl;
cin>>a2;
for(h13=0;h13<h3;h13++)
{
h14=100;
if(tong(a2,stu[h13])==0)
{
h14=h13;
break;
}
}
if(h14==100) cout<<"查无此人!"<<endl;
else
{
cout<<"真的要删除此学生的数据吗(y/n)?"<<endl;
cin>>d1;
if(d1=='y')
{
change(stu[h14],stu[h3-1]);
stu[h3-1].set("","","");
h3--;
cout<<"数据删除成功!"<<endl;
}
}break;
case 8:
cout<<endl;
cout<<"请输入您的新密码:"<<endl;
cin>>t1;
cout<<"请再输入一次新密码:"<<endl;
cin>>t2;
if(t1[0]==t2[0]&&t1[1]==t2[1]&&t1[2]==t2[2]&&
t1[3]==t2[3]&&t1[4]==t2[4]&&t1[5]==t2[5]&&
t1[6]==t2[6]&&t1[7]==t2[7]&&t1[8]==t2[8])
{
cout<<"密码已经确认!"<<endl;
three.open("key.txt",ios::out);
three.write(t1,strlen(t1));
three.close();break;
}
else
{
cout<<"两次输入的密码不一致!"<<endl;
break;
}
case 9:
goto loop;break;
default:break;
}
}
}
}
loop:;
}
更多追问追答
追问
程序简单点的最好有 释义。谢谢 不用密码什么的 能够实现显示、保存功能
追答
这是我以前做的一个课程设计,所以很快就把代码贴上了.....如果要改...我都忘得差不多了
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式