求帮忙改正解决方法
求帮忙改正
求帮忙改正 就是输入5位学生的姓名,学号,成绩 然后再输出 问题是只输出了最后面那位学生的信息
#include <iostream>
using namespace std;
class Info{
int id;
char name[20];
int QTscore;//Info student[COUNT];
public:
void set_info(int id1,char *name1,int QTscore1){
id=id1;
strcpy(name,name1);
QTscore=QTscore1;
}
int get_info(){
return QTscore;
}
void show(){
cout<<id<<"\t";
cout<<name<<"\t";
cout<<QTscore<<"\t"<<endl;
}
};
int main() {
int i=0;
const int COUNT=5;
int id;
char name[20];
int QTscore;
/*switch(i){
case 0:
cout<<"第一位学生信息"<<endl;
case 1:
cout<<"第二位学生信息"<<endl;
}*/
Info student[COUNT];
cout<<"请输入学生信息(学号,姓名,成绩)"<<endl; //输入信息
for(i=0;i<COUNT;i++){
cin>>id>>name>>QTscore;
student[i].set_info(id,name,QTscore);
}
cout<<"学号 姓名 QTscore 平均分"<<endl;
for(i=0;i<COUNT;i++) //输出信息
student[i].set_info(id,name,QTscore);
for(i=0;i<COUNT;i++)
student[i].show();
//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
------解决方案--------------------
求帮忙改正 就是输入5位学生的姓名,学号,成绩 然后再输出 问题是只输出了最后面那位学生的信息
#include <iostream>
using namespace std;
class Info{
int id;
char name[20];
int QTscore;//Info student[COUNT];
public:
void set_info(int id1,char *name1,int QTscore1){
id=id1;
strcpy(name,name1);
QTscore=QTscore1;
}
int get_info(){
return QTscore;
}
void show(){
cout<<id<<"\t";
cout<<name<<"\t";
cout<<QTscore<<"\t"<<endl;
}
};
int main() {
int i=0;
const int COUNT=5;
int id;
char name[20];
int QTscore;
/*switch(i){
case 0:
cout<<"第一位学生信息"<<endl;
case 1:
cout<<"第二位学生信息"<<endl;
}*/
Info student[COUNT];
cout<<"请输入学生信息(学号,姓名,成绩)"<<endl; //输入信息
for(i=0;i<COUNT;i++){
cin>>id>>name>>QTscore;
student[i].set_info(id,name,QTscore);
}
cout<<"学号 姓名 QTscore 平均分"<<endl;
for(i=0;i<COUNT;i++) //输出信息
student[i].set_info(id,name,QTscore);
for(i=0;i<COUNT;i++)
student[i].show();
//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
------解决方案--------------------