1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
//Create a structure student with faculty number, name, age, avrscores. Create array with 5 students and calculate all avrscores,and //find the student with age<20 and scores<5. #include<iostream> #include<string> using namespace std; struct student { string fnum; string name; int age; double avscores; }; void create_data(student stud[]); double avg(student stud[]); void findstudent(student stud[]); void main() { student stud[5]; create_data(stud); cout << endl << "Total avrscores for 5 students is:" << avg(stud); findstudent(stud); system("pause"); } void create_data(student stud[]) { for (int i = 0; i < 5; i++) { cin.ignore(1000, '\n'); cout << endl << "Please enter faculty number"; getline(cin, stud[i].fnum); cout << endl << "Please enter student name"; getline(cin, stud[i].name); cout << endl << "Please enter student age"; cin >> stud[i].age; cout << endl << "Please enter student scores"; cin >> stud[i].avscores; } } double avg(student stud[]) { double total(0.0); for (int i = 0; i < 5; i++) total = total + stud[i].avscores; return total / 5; } void findstudent(student stud[]) { for (int i = 0; i < 5; i++) if ((stud[i].age <= 20) && (stud[i].avscores < 5)) { cout << endl << stud[i].fnum; cout << endl << stud[i].name; cout << endl << stud[i].age; cout << endl << stud[i].avscores; } } //Homework: Add a new function that find how many students have avscores>5 and calculate their average age