#include <iostream> #define N 5 #define COURSES 3 using namespace std; typedef struct x { string fullName; int marks[COURSES]; float average; } Student; string Courses[COURSES] = {"Biology", "Mathematics", "Chemistry"}; Student MyClass[N];
for (i = 0; i < N; i++) { cout << "Student " << i + 1 << endl; cout << "Full name: "; getline(cin, MyClass[i].fullName); //cin >> ; for (j = 0; j < COURSES; j++) { cout << "Mark (" << Courses[j] << "): "; cin >> MyClass[i].marks[j]; MyClass[i].average += MyClass[i].marks[j]; } MyClass[i].average /= (float) COURSES; cin.ignore(100, '\n'); }
for (i = 0; i < COURSES; i++) { cout << Courses[i] << " marks:" << endl; for (j = 0; j < N; j++) { cout << MyClass[j].fullName << " - " << MyClass[j].marks[i] << endl; } }
for (j = 0; j < N; j++) { cout << MyClass[j].fullName << " - " << MyClass[j].average << endl; }
#include <iostream> #define N 5 #define COURSES 3 using namespace std; typedef struct x { string fullName; int marks[COURSES]; float average; } Student; string Courses[COURSES] = {"Biology", "Mathematics", "Chemistry"}; Student MyClass[N]; int main(int argc, char** argv) { int i, j; for (i = 0; i < N; i++) { cout << "Student " << i + 1 << endl; cout << "Full name: "; getline(cin, MyClass[i].fullName); //cin >> ; for (j = 0; j < COURSES; j++) { cout << "Mark (" << Courses[j] << "): "; cin >> MyClass[i].marks[j]; MyClass[i].average += MyClass[i].marks[j]; } MyClass[i].average /= (float) COURSES; cin.ignore(100, '\n'); } cout << endl << endl; for (i = 0; i < COURSES; i++) { cout << Courses[i] << " marks:" << endl; for (j = 0; j < N; j++) { cout << MyClass[j].fullName << " - " << MyClass[j].marks[i] << endl; } } cout << endl << "Student averages:" << endl; for (j = 0; j < N; j++) { cout << MyClass[j].fullName << " - " << MyClass[j].average << endl; } return 0; }
Student 1 Full name: Abraham Cole Mark (Biology): 80 Mark (Mathematics): 74 Mark (Chemistry): 62 Student 2 Full name: Brenda Johnson Mark (Biology): 100 Mark (Mathematics): 80 Mark (Chemistry): 75 Student 3 Full name: Kate Newark Mark (Biology): 60 Mark (Mathematics): 70 Mark (Chemistry): 95 Student 4 Full name: John Lewis Mark (Biology): 50 Mark (Mathematics): 70 Mark (Chemistry): 70 Student 5 Full name: Peter Pan Mark (Biology): 100 Mark (Mathematics): 100 Mark (Chemistry): 100 Biology marks: Abraham Cole - 80 Brenda Johnson - 100 Kate Newark - 60 John Lewis - 50 Peter Pan - 100 Mathematics marks: Abraham Cole - 74 Brenda Johnson - 80 Kate Newark - 70 John Lewis - 70 Peter Pan - 100 Chemistry marks: Abraham Cole - 62 Brenda Johnson - 75 Kate Newark - 95 John Lewis - 70 Peter Pan - 100 Student averages: Abraham Cole - 72 Brenda Johnson - 85 Kate Newark - 75 John Lewis - 63.3333 Peter Pan - 100