Create a structure representing a student. The member variables should include student name, student ID, and four test grades for the student (an array of four grades as a member variable). Prompt the user to enter the name, ID, and the four positive test results. Perform error checking for negative values. Store all the data in a structure object. Calculate the average of the three highest grades, dropping the lowest grade. Display the student's name, ID number, four test grades, and the average of the three highest grades. Use a loop to repeat the questions for the next student. You can recycle the same struct object for the next student. Terminate the program when the user decides to stop.

Respuesta :

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;

}