哪位高手帮我看看为什么会出错啊。

book_chinatreeqy 2007-04-12 12:05:06
#include "stdafx.h"
#include "iostream.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#define N 50

class Student{
int number;
char name[20];
float chinese,english,math;
public:
Student(){}
Student(int u,char v[20],float x,float y,float z){ //构造函数
number=u;
strcpy(name,v);
chinese=x;
english=y;
math=z;
}
void output(void)
{
float arg;
arg=(chinese+english+math)/3;
cout<<number<<"\t"<<name<<"\t"<<chinese<<"\t"<<english<<"\t"<<math<<"\t"<<arg<<endl;
}
};




int main(int argc, char* argv[])
{
Student stu[N];
char n; //选择参数
int i=1;int m=1; //控制参数
int a;float c,d,e;char b[20];
cout<<"\t\t\t兰州军区学员曲毅的作业。\n"<<endl;
cout<<"\t\t\t 欢迎使用学生管理程序\n";
do {
cout<<"请选择:"<<endl;
cout<<"1、输入信息"<<endl;
cout<<"2、输出信息"<<endl;
cout<<"0、退出"<<endl<<endl;
cin>>n;
switch(n)
{
case '1':
{
cout<<"请输入学号:";
cin>>a;
cout<<"\n姓名:";
cin>>b;
cout<<"\n语文成绩:";
cin>>c;
cout<<"\n数学成绩:";
cin>>d;
cout<<"\n英语成绩:";
cin>>e;
cout<<endl;
Student stu[i](a,b,c,d,e);
i++;
break;}

case '2':
cout<<endl;
cout<<"学号\t"<<"姓名\t"<<"语文\t"<<"数学\t"<<"英语\t"<<"平均成绩"<<endl;
for (;m<i;m++) stu[m].output();m=1;
cout<<endl;
break;
case '0':exit(0);
default:cout<<"输入错误!"<<endl<<endl;
}
}
while (1);
return 0;
}
...全文
189 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihongxue 2007-04-12
  • 打赏
  • 举报
回复
你在main中定义了两次Student stu[]
应该将第二次的定义去掉,直接用stu[i](a,b,c,d,e)就行。
另外建议不要用do语句,可以考虑用for(;;)代替,表示永远再在for(;;)中用break退出就行了,注意:for(;;)里面有了switch()而switch()里面的break只能用来退出switch()所以在switch外应该再加一次break

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧