C语言编程紧急

编写一个简单学生成绩管理系统,并实现如下功能: (1)输入学生的成绩 (2)显示学生的成绩 (3)显示成绩最高分 (4)显示成绩最低分(5)显示平均分

#include<iostream>
using namespace std;
class student
{private:<br> int number;<br> char name[20];<br> char sex;<br> float yingyu;<br> float yuwen;<br> float shuxue;<br> int mingci;<br> public:<br> student(){number=0;strcmp(name," ");sex=' ';yingyu=0;yuwen=0;shuxue=0;mingci=0;}
void chushihua(){number=0;strcmp(name," ");sex=' ';yingyu=0;yuwen=0;shuxue=0;mingci=0;}
void SetNumber(int number_){number=number_;}
void SetName(char name_[]){strcpy(name,name_);}
void SetSex(char sex_){sex=sex_;}
void SetYingyu(float yingyu_){yingyu=yingyu_;}
void SetYuwen(float yuwen_){yuwen=yuwen_;}
void SetShuxue(float shuxue_){shuxue=shuxue_;}
void SetMingci(int mingci_){mingci=mingci_;}
float GetZongchengji(){return yuwen+yuwen+shuxue;}
int GetNumber(){return number;}
float GetYingyu(){return yingyu;}
float GetYuwen(){return yuwen;}
float GetShuxue(){return shuxue;}
char GetSex(){return sex;}
char *GetName(){return name;}
void ShowNumber(){cout<<"编号:"<<number;}
void ShowName(){cout<<" 姓名:"<<name;}
void ShowSex(){cout<<" 性别:"<<sex;}
void ShowYingyu(){cout<<" 英语:"<<yingyu;}
void ShowYuwen(){cout<<" 语文:"<<yuwen;}
void ShowShuxue(){cout<<" 数学:"<<shuxue;}
void ShowMingci(){cout<<" 班级名次:"<<mingci<<endl;}
};
student stu[30];
int jiashuxueshengxinxi()
{int number_;<br> char name_[20];<br> char sex_;<br> int i;<br> float yingyu_;<br> float yuwen_;<br> float shuxue_;<br> for(i=0;i<30;i++)<br> {if(stu[i].GetNumber()==0)<br> {cout<<"请输入学生编号:";<br> cin>>number_;<br> getchar();<br> stu[i].SetNumber(number_);<br> cout<<"请输入学生姓名:";<br> cin>>name_;<br> getchar();<br> stu[i].SetName(name_);<br> loop:<br> cout<<"请输入学生性别(男-M,女-W):";<br> cin>>sex_;<br> getchar();<br> if((sex_=='M')||(sex_=='W')) stu[i].SetSex(sex_);<br> else {goto loop;}
cout<<"请输入学生的英语成绩:";
cin>>yingyu_;
getchar();
stu[i].SetYingyu(yingyu_);
cout<<"请输入学生的语文成绩:";
cin>>yuwen_;
getchar();
stu[i].SetYuwen(yuwen_);
cout<<"请输入学生的数学成绩:";
cin>>shuxue_;
getchar();
stu[i].SetShuxue(shuxue_);
cout<<"该学生信息录入成功!"<<endl;
return 0;
}
}
return 0;
}
int shanchuxueshengxinxi()
{char name_[20];<br> int i;<br> cout<<"请输入要删除的学生姓名:";<br> cin>>name_;<br> for(i=0;i<30;i++)<br> {if(strcmp(stu[i].GetName(),name_)==0) <br> {stu[i].chushihua();<br> cout<<"删除学生信息成功!"<<endl;<br> return 0;<br> }
}
cout<<"对不起,没有此名字的学生!"<<endl;
return 0;
}
int jiansuoxueshengxinxi()
{int number_;<br> char name_[20];<br> char c;<br> int i;<br> cout<<"1.按编号检索;\n"<br> <<"2.按姓名检索.\n"<br> <<"请输入序列号:";<br> cin>>c;<br> getchar();<br> switch(c)<br> {case '1':cout<<"请输入编号";<br> cin>>number_;<br> for(i=0;i<30;i++)<br> if(number_==stu[i].GetNumber()) <br> {stu[i].ShowNumber();<br> stu[i].ShowName();<br> stu[i].ShowSex();<br> stu[i].ShowYingyu();<br> stu[i].ShowYuwen();<br> stu[i].ShowShuxue();<br> cout<<"\n";<br> return 0;<br> }
cout<<"对不起,没有此编号的学生!"<<endl;
break;
case '2':cout<<"请输入姓名";
cin>>name_;
for(i=0;i<30;i++)
if(strcmp(stu[i].GetName(),name_)==0)
{stu[i].ShowNumber();<br> stu[i].ShowName();<br> stu[i].ShowSex();<br> stu[i].ShowYingyu();<br> stu[i].ShowYuwen();<br> stu[i].ShowShuxue();<br> cout<<"\n";<br> return 0;<br> }
cout<<"对不起,没有此姓名的学生!"<<endl;
break;
}
return 0;
}
int xianshiquanbuxueshengdezongchengjihepaiming()
{int i,j;<br> student *p= new student();<br> for(i=0;i<29;i++)<br> for(j=i+1;j<30;j++)<br> {if(stu[i].GetZongchengji()<stu[j].GetZongchengji())<br> {p->SetNumber(stu[j].GetNumber());<br> p->SetName(stu[j].GetName());<br> p->SetSex(stu[j].GetSex());<br> p->SetYingyu(stu[j].GetYingyu());<br> p->SetYuwen(stu[j].GetYuwen());<br> p->SetShuxue(stu[j].GetShuxue());<br> stu[j].SetNumber(stu[i].GetNumber());<br> stu[j].SetName(stu[i].GetName());<br> stu[j].SetSex(stu[i].GetSex());<br> stu[j].SetYingyu(stu[i].GetYingyu());<br> stu[j].SetYuwen(stu[i].GetYuwen());<br> stu[j].SetShuxue(stu[i].GetShuxue()); <br> stu[i].SetNumber(p->GetNumber());<br> stu[i].SetName(p->GetName());<br> stu[i].SetSex(p->GetSex());<br> stu[i].SetYingyu(p->GetYingyu());<br> stu[i].SetYuwen(p->GetYuwen());<br> stu[i].SetShuxue(p->GetShuxue());<br> }
}
delete p;
for(i=0;i<30;i++)
{stu[i].SetMingci(i+1);<br> }
for(i=0;i<30;i++)
if(stu[i].GetNumber()!=0)
{stu[i].ShowNumber();<br> stu[i].ShowName();<br> stu[i].ShowSex();<br> stu[i].ShowYingyu();<br> stu[i].ShowYuwen();<br> stu[i].ShowShuxue();<br> stu[i].ShowMingci();<br> }
delete p;
return 0;
}
int tongjigekepingjunchengjihejigelv()
{float yingyupingjunchengji;<br> float yuwenpingjunchengji;<br> float shuxuepingjunchengji;<br> long yingyusum=0;<br> long yuwensum=0;<br> long shuxuesum=0;<br> int i;<br> int n=0; //统计学籍存在的学生总数<br> for(i=0;i<30;i++)<br> {if(stu[i].GetNumber()!=0)<br> {yingyusum+=stu[i].GetYingyu();<br> yuwensum+=stu[i].GetYuwen();<br> shuxuesum+=stu[i].GetShuxue();<br> n++;<br> }
}
yingyupingjunchengji=yingyusum/n;
yuwenpingjunchengji=yuwensum/n;
shuxuepingjunchengji=shuxuesum/n;
cout<<"科目:英语"<<" 总人数:"<<n<<" 平均成绩:"<<yingyupingjunchengji<<endl;
cout<<"科目:语文"<<" 总人数:"<<n<<" 平均成绩:"<<yuwenpingjunchengji<<endl;
cout<<"科目:数学"<<" 总人数:"<<n<<" 平均成绩:"<<shuxuepingjunchengji<<endl;
return 0;
}
void main()
{int jiashuxueshengxinxi();<br> int shanchuxueshengxinxi();<br> int jiansuoxueshengxinxi();<br> int xianshiquanbuxueshengdezongchengjihepaiming();<br> int tongjigekepingjunchengjihejigelv();<br> FILE *fp;<br> if((fp=fopen("student.txt","rb"))==NULL) <br> {fp=fopen("student.txt","wb+"); //打开文件失败,创建一个新文件<br> }
else {fp=fopen("student.txt","rb"); //打开文件成功,从文件中读取相关数据<br> fread(&stu[0],sizeof(student),30,fp);<br> }
fclose(fp); //关闭文件
char c;
cout<<"欢迎来到高校学籍管理系统\n"
<<"1.加入学生信息;\n"
<<"2.删除学生信息;\n"
<<"3.检索学生信息;\n"
<<"4.显示全部学生的总成绩和排名;\n"
<<"5.统计各科平均成绩和及格率;\n"
<<"6.退出系统."
<<"请输入对应的序列号:";
cin>>c;
switch(c)
{case '1':jiashuxueshengxinxi();main();<br> case '2':shanchuxueshengxinxi();main();<br> case '3':jiansuoxueshengxinxi();main();<br> case '4':xianshiquanbuxueshengdezongchengjihepaiming();main();<br> case '5':tongjigekepingjunchengjihejigelv();main();<br> case '6':fp=fopen("student.txt","wb"); <br> fwrite(&stu[0],sizeof(student),30,fp);<br> fclose(fp); <br> exit(0);<br> }
}
声明一下:按名次查找这个你得自己改 90%以上靠近你的程序了
这是学生学籍管理系统 学号,成绩和名次都有 自己改改
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-19
#include<stdio.h>
#define N 5

main()
{ int a[N]={0},b,i,j,n,k,max,min,s,pin;
for(i=0;i<N;i++) /*输入学生成绩:\n*/
scanf("%d",a[i]);
for(i=1;i<N;i++) /*求最高分*/
{ if(a[k]<a[i]) k=i; }
max=a[k];

for(i=1;i<N;i++)
{ if(a[k]>a[i]) j=i; }/*求最低分*/
min=a[j];
for(i=1;i<N;i++) /*求总分*/
s=s+a[i];
pin=s/N; /*求平均分*/
scanf("%d",&n);
switch(n)
{ case'1' :(这个貌似不用选择吧)
case'2':for(i=0;i<N;i++) /*显示学生成绩:\n*/
printf("%d",a[i]);break;
case'3':printf("%d",max); break;
case'4':printf("%d",min);break;
case'5':printf("%d",pin);break;
case'6':printf("结束!")
}

}
第2个回答  2013-12-19
修改求最小值处应该这样
for(i=1;i<N;i++)
{ if(a[k]>a[i]) k=i; }
min=a[k]; 其他都正确,望采纳