已知某班有N名学生,每名学生有学号,姓名和三门课程成绩这些属性,统计有不及格课程学生的人数并输出他们的信息
代码如下,望采纳
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> str; //保存有不及格课程的学生的信息
string name;
int number;
int ach1, ach2, ach3; //三门课程的成绩
while(1) {
cin >> name >> number >> ach1 >> ach2 >> ach3;
if("quit" == name) //输入的一行数据中如果name为quit代表结束输入
break;
if((ach1 < 60) || (ach2 < 60) || (ach3 < 60)) {
string temp = name + " " + to_string(number) + " " + to_string(ach1)
+ " " + to_string(ach2) + " " + to_string(ach3);
str.push_back(temp); //增加一个元素放在容器最后面
}
}
for(auto s : str) //输出容器内所有的元素
cout << s << endl;
return 0;
}