Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Challenge: Lowest Score Drop at the end of the Chapter. You must

ID: 3850097 • Letter: C

Question

C++ Programming Challenge: Lowest Score Drop at the end of the Chapter.

You must use the stated functions and complete the Input Validation.

Do NOT use global variables or arrays

-- Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:

1) void getScore() should ask the user for a test score, score it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.

2) void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.

3) int findLowest () should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determine which of the five scores to drop.

Input Validation: Do not accept test scores lower than 0 or higher than 100.

Explanation / Answer

The answer is as follows:

#include<iostream.h>

void getScore(int &a)
{
   
    do {
       cout << "Enter Score:";
       cin >> a;
       if ( a < 0 && a > 100)
          cout << "Invalid score";
    } while ( a < 0 && a > 100)
}

int findLowest(int m[5])
{
   int temp;
   for (int i = 0; i < 4; i++)
   {
       if (m[i] < m[i+1]) //swap if m[i] < m[i+1]
       {
          temp = m[i];
          m[i] = m[i+1];
          m[i+1] = temp;
       }
   }
   return m[4];
}
void calcAverage(int m[5])
{
     int b;
     int sum;
     b= findLowest(m);
     for (int i =0; i<5; i++)
     {
         if (m[i] != b)
            sum = sum + m[i];
     }
     cout << sum/4;
}

void main()
{
   int scores[5];
   int b;
  
   for (int i = 0; i<5; i++)
   {
       getscore(b);
       scores[i] = b;
   }
   calcAverage(scores)
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote