Answer:
Output:
Name: Brainly
ID:0001
Write the 4 tests grades of the student separated by space :10 9 8 10
Brainly
0001
10 9 8 10
Average :9.66667
'1' to continue '0' to exit :
Explanation:
#include<iostream>
#include<string>
using namespace std;
//variables declaration
struct Student {
string id; //string declaration ID
string name; // string declaration name
int grades[4]; //array of 4 because it is 4 grades
};
//definition of the function get information
void inputData(Student &s){
cout << "Name:" ;
getline(cin,s.name);
cout << "ID:";
cin >> s.id;
cout << "Write the 4 tests grades of the student separated by space :";
for (int i = 0; i<4; i++)
cin >> s.grades[i];
}
//definition of the function of average
double inputAvg(Student s){
double summation;
int temporary;
double average;
for (int i = 0; i<4; i++){
for (int j = i; j<4; j++){
if (s.grades[j] > s.grades[i]){
temporary = s.grades[i];
s.grades[i] = s.grades[j];
s.grades[j] = temporary;
}
}
}
summation = 0;
for (int i = 0; i<3; i++){
summation = summation + s.grades[i];
}
average = summation/3;
return average;
}
void disp(Student *s){
cout << s->name << endl;
cout << s->id << endl;
for (int i = 0; i<4; i++)
cout << s->grades[i] << " ";
cout << endl;
cout << "Average :" << inputAvg(*s) << endl;
}
int main(){
Student st;
int ch;
while(true){
inputData(st);
disp(&st);
cout << " '1' to continue '0' to exit :";
cin >> ch;
if (ch == 0)
break;
}
return 0;
}