定义一个vector的学生类,输入若干学生的学号和成绩,并打印出来,询问客户是否继续输入,键入Y则继续输入并打印
时间: 2024-05-07 18:17:32 浏览: 9
您好,这是我制作的ChitGPT,可以与您进行类似对话的交互。
对于您的问题,我可以为您提供以下代码实现。
```c++
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Student {
public:
int id;
double score;
Student() {}
Student(int i, double s) : id(i), score(s) {}
};
int main() {
vector<Student> students;
char option = 'Y';
while (option == 'Y') {
int id;
double score;
cout << "请输入学生的学号和成绩,以空格分隔:";
cin >> id >> score;
students.emplace_back(id, score);
cout << "继续输入?(Y/N)";
cin >> option;
}
cout << "输入的学生信息为:" << endl;
for (auto student : students) {
cout << "学号: " << student.id << " 成绩: " << student.score << endl;
}
return 0;
}
```
请问有什么其他问题我可以帮您解答呢?