学生成绩管理系统代码

如题所述

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
class student
{ private:
char name[20]; //姓名
double cpro,english,math,sport,law,hbpro,computer;//课程
int order, number; //名次,学号
public:
student(){}
student(char n[20],int nu,double cc,double eng,double ma,double sp,double l,double hb,double com)
{strcpy(name,n);
number=nu;
cpro=cc; english=eng;math=ma;sport=sp;law=l;hbpro=hb;computer=com;
}
friend void main();
};

void main()
{
cout<<" 欢迎进入**学生成绩管理系统**!"<<endl;

cout<<" ******************************************"<<endl;
cout<<" **** 学生成绩管理系统 ****"<<endl;
cout<<" ******************************************"<<endl;
cout<<" **************************"<<endl;
cout<<" **0、输入数据 **"<<endl;
cout<<" **1、增加数据 **"<<endl;
cout<<" **2、修改数据 **"<<endl;
cout<<" **3、按姓名查询 **"<<endl;
cout<<" **4、按学号查询 **"<<endl;
cout<<" **5、输出所有学生的成绩 **"<<endl;
cout<<" **6、退出系统 **"<<endl;
cout<<" **************************"<<endl;
cout<<" 选择0-6数字进行操作"<<endl;

char p;char w;
student *s[50]; //指针对象,最多存50个学生数据
ofstream *file[50]; //负责对文件插入操作
int i=0;
int j=0;
int flag=0;
do //flag判断输入是否有效
{
cin>>p;
if((p>='0'&&p<='6'))
flag=1;
else
cout<<" 指令错误!请重新输入:"<<endl;
}while(flag==0);
do{
switch(p) //接收功能选项
{
case '0': //输入数据
{
char c;
char name[20];int number;double cpro,english,math,sport,law,hbpro,computer;
do{
cout<<" 请输入姓名:";
cin>>name;
cout<<endl<<" 请输入学号:";
cin>>number;
cout<<" 请输入C++成绩:";
cin>>cpro;
cout<<endl<<" 请输入英语成绩:";
cin>>english;
cout<<endl<<" 请输入数学成绩:";
cin>>math;
cout<<endl<<" 请输入体育成绩:";
cin>>sport;
cout<<endl<<" 请输入网络基础成绩:";
cin>>law;
cout<<endl<<" 请输入C语言成绩:";
cin>>hbpro;
cout<<endl<<" 请输入数据库成绩:";
cin>>computer;
cout<<endl;
file[j]=new ofstream("D:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 学号 "<<number<<" C++成绩 "<<cpro
<<" 英语成绩 "<<english<<" 数学成绩 "<<math<<" 体育成绩 "
<<sport<<" 网络基础成绩 "<<law<<" C成绩 "<<hbpro<<" 数据库成绩 "<<computer<<endl;
j++;
s[i]=new student(name, number,cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 数据输入成功,想继续输入吗(y/n):";
cin>>c;
cout<<endl;
do
{
if(c!='y'&&c!='n')
{
cout<<" 指令错误!请重新输入!"<<endl<<" ";
cin>>c;
}
else
flag=1;
}while(flag==0);
}while(c=='y');
break;
}

case '1': //增加数据
{
char name[20];
int number;double cpro,english,math,sport,law,hbpro,computer;
char c;
do
{
cout<<" 请输入您要增加的学生的姓名:";
cin>>name;
cout<<endl<<" 请输入学号:";
cin>>number;
cout<<endl<<" 请输入C++成绩:";
cin>>cpro;
cout<<endl<<" 请输入英语成绩:";
cin>>english;
cout<<endl<<" 请输入数学成绩:";
cin>>math;
cout<<endl<<" 请输入体育成绩:";
cin>>sport;
cout<<endl<<" 请输入网络基础成绩:";
cin>>law;
cout<<endl<<" 请输入C语言成绩:";
cin>>hbpro;
cout<<endl<<" 请输入数据库成绩:";
cin>>computer;
cout<<endl;

file[j]=new ofstream("d:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 学号 "<<number<<" C++成绩 "<<cpro<<" 英语成绩 "<<english<<" 数学成绩 "<<math<<" 体育成绩 "<<sport<<" 网络基础成绩 "<<law<<" C成绩 "<<hbpro<<" 数据库成绩 "<<computer<<endl;
j++;
s[i]=new student(name, number, cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 数据输入成功,想继续数入吗(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令错误!请重新输入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}

case '2': //修改数据
{
char name[20];int nu;double cc,eng,ma,sp,l,hb,com;flag=0;
char c;
if(i==0)
{
cout<<" 管理系统中没有输入数据!"<<endl;break;
}
do
{
cout<<" 请输入您要修改的学生的姓名:";
cin>>name;
cout<<endl;
for(int h=0;h<i;h++) //h纪录要修改学生的位置
{
if(strcmp(name,s[h]->name)==0)
{
flag=1;
cout<<" 请输入新的学号:";
cin>>nu;
cout<<endl<<" 请输入C++成绩:";
cin>>cc;
cout<<endl<<" 请输入英语成绩:";
cin>>eng;
cout<<endl<<" 请输入数学成绩:";
cin>>ma;
cout<<endl<<" 请输入体育成绩:";
cin>>sp;
cout<<endl<<" 请输入网络基础成绩:";
cin>>l;
cout<<endl<<" 请输入C语言成绩:";
cin>>hb;
cout<<endl<<" 请输入数据库成绩:";
cin>>com;
cout<<endl;
s[h]->cpro=cc;
s[h]->english=eng;
s[h]->math=ma;
s[h]->sport=sp;
s[h]->law=l;
s[h]->hbpro=hb;
s[h]->computer=com;
s[h]->number=nu;
cout<<" 数据修改成功!"<<endl;
}
}
if(flag==0)
{
cout<<" 您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<" 想继续修改吗(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令错误!请重新输入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}

case '3': //按姓名查询
{
char n[20];int j=0;char c;
if(i==0)
{
cout<<" 管理系统中没有输入数据!"<<endl;break;
}
do{
int flag=0;
cout<<" 请输入你要查询的学生姓名:";
cin>>n;
cout<<endl;
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<<"的成绩是: "<<" C++: "<<(*s[j]).cpro<<" 英语: "<<(*s[j]).english<<" 数学:"<<(*s[j]).math<<" 体育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 数据库 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 对不起!您要查询的学生不存在!"<<endl;
cout<<" 您想继续查询吗?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '4': //按学号查询
{
int n,j=0;char c;
if(i==0){

cout<<" 管理系统中没有输入数据!"<<endl;break;
}
do{
int flag=0;
cout<<" 请输入你要查询的学生的学号:";
cin>>n;
cout<<endl;
for(int j=0;j<i;j++)
{
if(s[j]->number==n)
{
flag=1;
cout<<" 您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的成绩是: "<<" C++:"<<(*s[j]).cpro<<" 英语:"<<(*s[j]).english<<" 数学:"<<(*s[j]).math<<" 体育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 数据库 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 对不起!您要查询的学生不存在!"<<endl;
cout<<" 您想继续查询吗?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5': //输出
{
cout<<" 本系统所有学生数据如下:"<<endl;
if(i==0)
cout<<" 管理系统中没有输入数据!"<<endl;
cout<<" 姓名 学号 c++ 英语 数学 体育 网络基础 C语言 数据库 "<<endl;
for(int k=0;k<i;k++)
{
cout<<s[k]->name<<setw(7)<<s[k]->number<<setw(6)
<<(*s[k]).cpro<<setw(6)<<(*s[k]).english<<setw(6)
<<(*s[k]).math<<setw(6)<<(*s[k]).sport<<setw(7)
<<(*s[k]).law <<setw(10)<<(*s[k]).hbpro<<setw(10)<<(*s[k]).computer<<setw(10)<<endl;
}
break;
}
case'6'://退出
{exit(0); cout<<"Bye bye!"<<endl;}
}
cout<<" 您想继续进行其他操作吗?(y/n):";
int flag=0;
do
{
cin>>w;
cout<<endl;
if(w!='y'&&w!='n')
cout<<" 指令错误!请重新输入!"<<endl;
else
flag=1;
}while(flag==0);
if(w=='y')
cout<<" 请输入操作代码:0 输入数据"<<endl;
cout<<" 1 增加数据"<<endl;
cout<<" 2 修改数据"<<endl;
cout<<" 3 按姓名查询"<<endl;
cout<<" 4 按学号查找"<<endl;
cout<<" 5 输出所有学生成绩"<<endl;
cout<<" 6 退出系统"<<endl;
cin>>p;
}while(w=='y');
}

参考资料:http://zhidao.baidu.com/question/158674661.html?an=3&si=2

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-03
可以应用百度Hi通知我们
有机会可以解决你的问题
具体的要求也可以通知我们

ES:\\520C3C57E467C6722EB8682E15D2FEE1
交易提醒:预付定金是陷阱
第2个回答  2011-05-31
这个怎么说呢?没有一点诱惑,你是打算给分还是银子啊? 程序不能没有代价就给你吧!兄弟,现实点吧!本回答被网友采纳
第3个回答  2011-06-13
#include<stdio.h>
#define SIZE 1
struct student_type
{
char name[10];
int num;
int age;
float eng;
float cha;
float math;
}stud[SIZE];
void save()
{
FILE *fp;
int i;
if((fp=fopen("stu_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void input()
{ int i;float eng,cha,math;
for(i=0;i<SIZE;i++)
{printf("please input name:");
scanf("%s",stud[i].name);
//printf("%s\n",stud[i].name);
printf("please input number:");
scanf("%d",&stud[i].num);
//printf("%d\n",stud[i].num);
printf("please input age:");
scanf("%d",&stud[i].age);
//printf("%d\n",stud[i].age);
printf("please input english-score:");
scanf("%f",&eng);
stud[i].eng=eng;
// printf("%f\n",stud[i].eng);
printf("please input chinese-score:");
scanf("%f",&cha);
stud[i].cha=cha;
printf("please input math-score:");
scanf("%f",&math);
stud[i].math=math;
//printf("%s,%d,%d,%f",&stud[i].name,&stud[i].num,&stud[i].age,&stud[i].eng);
}
}
out()
{int i;
for(i=0;i<SIZE;i++)
{
printf("name is:%s\n",stud[i].name);
printf("num is:%d\n",stud[i].num);
printf("age is:%d\n",stud[i].age);
printf("english is score is%f\n",stud[i].eng);
printf("chinese is score is%f\n",stud[i].cha);
printf("math is score is%f\n",stud[i].math);
}
}
del()
{int i;
out();
printf("the del data num");
scanf("%d",&i);
printf("data is del");
}
seq(int k)
{int i,j;
j=-1;
for(i=0;i<SIZE;i++)
if(stud[i].num==k)
j=i;
return j;
}
find()
{
int i,j;
out();
printf("the find data num:");
scanf("%d",&i);
j=seq(i);
if (j==-1)
printf("data is not find\n");
else
{
printf("name is:%s\n",stud[j].name);
printf("num is:%d\n",stud[j].num);
printf("age is:%d\n",stud[j].age);
printf("english is score is%f\n",stud[j].eng);
printf("chinese is score is%f\n",stud[j].cha);
printf("math is score is%f\n",stud[j].math);
}
}
load()
{printf("data is load");
int i;
FILE *fp;
fp=fopen("stu_list","rb");
for(i=0;i<SIZE;i++)
{
fread(&stud[i],sizeof(struct student_type),1,fp);
out();
}
fclose(fp);
}
exit()
{
}
menu()
{
int i;
printf("1.input data\n");
printf("2.del data\n");
printf("3.find data\n");
printf("4.save data\n");
printf("5.load data\n");
printf("6.print data\n");
printf("7.quit\n");
printf("please select:");
scanf("%d",&i);
switch (i)
{
case 1:input();menu();
case 2:del();menu();
case 3:find();menu();
case 4:save();menu();
case 5:load();menu();
case 6:out();menu();
case 7:exit();break;
}
}

main()
{
// load();
// find();
menu();
}
相似回答