有10个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入10个学生的数据,要求打印出3门课都不及格的学生信息。c++
时间: 2023-12-15 08:37:57 浏览: 120
Sure! Here's a C++ program that allows you to input data for 10 students, including their student ID, name, and scores for 3 subjects. It then prints out the information of students who have failed in all three subjects.
```cpp
#include <iostream>
using namespace std;
struct Student {
int studentID;
string name;
int scores[3];
};
int main() {
const int numStudents = 10;
Student students[numStudents];
// Input data for each student
for (int i = 0; i < numStudents; i++) {
cout << "Enter student " << i+1 << " details:" << endl;
cout << "Student ID: ";
cin >> students[i].studentID;
cout << "Name: ";
cin.ignore();
getline(cin, students[i].name);
for (int j = 0; j < 3; j++) {
cout << "Enter score for subject " << j+1 << ": ";
cin >> students[i].scores[j];
}
}
// Print students with all three subjects failed
bool found = false;
cout << "\nStudents who failed in all three subjects:" << endl;
for (int i = 0; i < numStudents; i++) {
bool failed = true;
for (int j = 0; j < 3; j++) {
if (students[i].scores[j] >= 60) {
failed = false;
break;
}
}
if (failed) {
cout << "Student ID: " << students[i].studentID << endl;
cout << "Name: " << students[i].name << endl;
found = true;
}
}
if (!found) {
cout << "No students failed in all three subjects." << endl;
}
return 0;
}
```
You can compile and run this program to input the student data and get the desired output. Let me know if you have any further questions!
阅读全文