#include "stdafx.h"
#include "iostream.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
const char null='\0';
static char *strsave(char *s) {
char *p;
p=new char[strlen(s)+1];
strcpy(p,s);
return p;
}
class student{ //学生类
public:
char *name;
char *stu_no;
char *sex;
char *banji;
student()
{
name=null;
stu_no=null;
sex=null;
banji=null;
}
student( char *name1,char *stu_no1,char *sex1,char *banji1)
{ name=strsave(name1);
stu_no=strsave(stu_no1);
sex=strsave(sex1);
banji=strsave(banji1);
}
~student()
{ delete []name;
delete []stu_no;
delete []sex;
delete []banji;
}
void print1()
{ cout<<"\n"<<"name:"<<name<<endl;
cout<<"stu_no:"<<stu_no<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"banji:"<<banji<<endl;
}
};
class kc{ //课程类
public:
char *yw_no;
char *yy_no;
char *sx_no;
char *zz_no;
kc(char *yw_no1, char *yy_no1,char *sx_no1,char *zz_no1)
{yw_no=strsave(yw_no1);
yy_no=strsave(yy_no1);
sx_no=strsave(sx_no1);
zz_no=strsave(zz_no1);}
~kc()
{ delete []yw_no;
delete []yy_no;
delete []sx_no;
delete []zz_no;
}
void print2()
{ cout<<"\n"<<"yw_no:"<<yw_no<<endl;
cout<<"yy_no:"<<yy_no<<endl;
cout<<"sx_no:"<<sx_no<<endl;
cout<<"zz_no:"<<sx_no<<endl;}
};
class score: public student, public kc{ // 学生成绩类
public:
int yw_cj;
int yy_cj;
int sx_cj;
int zz_cj;
score( char *name1,char *stu_no1,char *sex1,char *banji1,char*yw_no1,char *yy_no1,char *sx_no1,
char *zz_no1,int yw_cj1,int yy_cj1,int sx_cj1,int zz_cj1):student(name1, stu_no1,sex1,banji1),
kc(yw_no1, yy_no1, sx_no1, zz_no1)
{ yw_cj=yw_cj1;
yy_cj=yy_cj1;
sx_cj=sx_cj1;
zz_cj=zz_cj1;}
void print();
};
void score::print()
{ student::print1();
kc::print2();
cout<<"yw_cj:"<<yw_cj<<endl;
cout<<"yy_cj:"<<yy_cj<<endl;
cout<<"sx_cj:"<<sx_cj<<endl;
cout<<"zz_cj:"<<zz_cj<<endl;
}
int main()
{ char sel;char u[6],p[8];
char uu[6]={"admin"},pp[8]={"123456"};
int n=0;
cout<<"请输入用户名和密码:"<<endl;
cout<<"--------------------"<<endl;
cout<<"user:";
cin>>u;
cout<<"password:";
cin>>p;if(strcmp(uu,u)==0&&strcmp(pp,p)==0)
cout<<"******欢迎进入学生管理系统******"<<endl;
while(strcmp(uu,u)!=0||strcmp(pp,p)!=0)
{
cout<<"输入错误请重新输入"<<endl;
cout<<"请输入用户名和密码:"<<endl;
cout<<"user:";
cin>>u;
cout<<"password:";
cin>>p;
n++;
if(n==2)
{cout<<"对不起您的输入次数已经达到最大!"<<endl;exit(0);}}
cout<<"\n";
score a[10]={score("张三","0321335001","男","信管","001","002","003","004",75,85,65,70),
score("李四","0321335002","男","信管","001","002","003","004",56,85,69,80),
score("李明","0321335003","男","信管","001","002","003","004",68,75,86,83),
score("刘芳","0321335004","女","信管","001","002","003","004",84,65,59,78),
score("王乐","0321335005","女","信管","001","002","003","004",87,65,73,82),
score("高天","0321335010","男","电商","001","002","003","004",54,55,68,53),
score("李山","0321335012","男","电商","001","002","003","004",59,63,85,59),
score("王强","0321335013","男","电商","001","002","003","004",56,55,86,53),
score("刘欣","0321335014","女","电商","001","002","003","004",84,65,59,78),
score("乐乐","0321335015","女","电商","001","002","003","004",87,65,73,82),};
cout<<"*************** 学生管理系统 *************************"<<endl;
cout<<"1: 建立学生成绩表"<<endl;
cout<<"2: 添加一个学生信息"<<endl;
cout<<"3: 删除一个学生信息"<<endl;
cout<<"4: 修改学生信息"<<endl;
cout<<"5: 查找信息"<<endl;
cout<<"6: 信息统计"<<endl;
cout<<"7: 退出系统"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请输入操作:";
cin>>sel;
switch(sel)
{
case '1':{ cout<<"**********学生成绩表记录如下***********"<<endl;
for(int i=0;i<10;i++)
a[i].print();}; break;
case '2':{cout<<"********请输入要添加学生记录*********"<<endl;
cin>>a[10].name; cin>>a[10].stu_no; cin>>a[10].sex; cin>>a[10].banji;
cin>>a[10].yw_no; cin>>a[10].yy_no; cin>>a[10].sx_no; cin>>a[10].zz_no;
cin>>a[10].yw_cj; cin>>a[10].yy_cj; cin>>a[10].sx_cj; cin>>a[10].zz_cj;};break;
case '3':{cout<<"************进行删除操作************"<<endl;
int n=0;char *p1="王强";
for(int c=0;c<10;c++)
if((a[c].sx_cj<60)&&strcmp(a[c].name,p1)==0)
{ n++;}
cout<<"************修改后的数据*************"<<endl;
if(n>=3)
for(int d=0;d<10;d++)
{if(strcmp(a[d].name,p1)>0||strcmp(a[d].name,p1)<0)
{ a[d].print(); cout<<"------------------------"<<endl;}
}}; break;
case '4':{cout<<"************进行修改操作************"<<endl;
char *pp="321335015";
for(int e=0;e<10;e++)
if(strcmp(a[e].stu_no,pp)==0)
{ cout<<"请输入修改后班级:";
cin>>a[e].banji;
a[e].print();
cout<<"-------------------------"<<endl;}}; break;
case '5':{cout<<"************进行查找操作************"<<endl;
student obj("乐乐","0321335015","女","电商");
cout<<"请输入要查找的人的姓名:"<<endl;
for(int g=0;g<10;g++)
if(strcmp(a[g].name,obj.name)==0)
a[g].print();
else
exit(0);
cout<<endl;
cout<<"请输入要查找的班级名:";
cin>>obj.banji;
for(int h=0;h<15;h++)
{if(strcmp(a[h].banji,obj.banji)==0) a[h].print();}};break;
case '6':{ cout<<"******进行统计操作******"<<endl;
char *p2="信管";char *p3="电商";
char *p4="001";char *p5="002";char *p6="003";char *p7="004"; int sum=0;
cout<<"******按班级统计成绩******"<<endl;
for(int i=0;i<10;i++)
if(strcmp(a[i].banji,p2)==0)
{ sum+=a[i].sx_cj;}
cout<<"信管的总成绩为:"<<sum<<endl;
for(int j=0;j<10;j++)
if(strcmp(a[j].banji,p3)==0)
{ sum+=a[j].yw_cj;}
cout<<"电商的总成绩为:"<<sum<<endl;
cout<<"******按课程统计成绩******"<<endl;
for(int i1=0;i1<10;i++)
if(strcmp(a[i1].yw_no,p4)==0)
{ sum+=a[i1].yw_cj;}
cout<<"语文的总成绩为:"<<sum<<endl;
for(int i2=0;i2<10;i++)
if(strcmp(a[i2].yy_no,p5)==0)
{ sum+=a[i2].yy_cj;}
cout<<"英语总成绩为:"<<sum<<endl;
for(int i3=0;i3<10;i++)
if(strcmp(a[i3].sx_no,p4)==0)
{ sum+=a[i3].sx_cj;}
cout<<"数学的总成绩为:"<<sum<<endl;
for(int i4=0;i4<10;i++)
if(strcmp(a[i4].zz_no,p4)==0)
{ sum+=a[i4].zz_cj;}
cout<<"政治的总成绩为:"<<sum<<endl;};break;
case '7':{exit(0);};break;
}
return 0;
}
这是我重新写的,可是有的地方显示不出数据来,请各位告诉我一下为什么?怎么修改?谢谢各位了!
[此贴子已经被作者于2006-1-13 13:21:43编辑过]