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

Design Constraints 1. Use an integer constant of 100 to specify the number of el

ID: 3641536 • Letter: D

Question

Design Constraints

1. Use an integer constant of 100 to specify the number of elements in the array you will use to collect the grade information.
2. Do not use any global variables in your program.
3. Declare any arrays you need in your main function and pass the arrays as needed into the functions described below.
4. The main function is the only function permitted to do any output to the console!!! Do not do cout operations inside of any other function.
5. Your data collection loop in your main function must allow the user to enter less than 100 grades. It must also make sure that the user does not try to enter more than 100 grades.
6. Each data value entered should be checked to make sure it is between 0 and 100. Any other value entered should be considered invalid and ignored (ie. not counted as a valid input and not stored in an array).
7. Once the data is collected, the array and the number of grades collected must be passed to a function called mean.
8. The mean function must loop through the values in the array, summing them together. The result of the function is the sum divided by the number of grades collected. The result must be returned from the mean function to the main function, where is it output in an appropriate manner (two digits after the decimal point).
9. The main function should then pass the array and the number of grades collected to the median function.
10. The median of a set of numbers is the number in the set where half the numbers are above it and half the numbers are below it. In order to find the median, this function will need to sort the original data.
11. The simplest sorting procedure is called bubble sorting. The following pseudocode describes bubble sorting for X valid array elements.
for outer = 0; outer < X; outer++
for inner = 0; inner < X-1; inner++
if array[inner] > array[inner+1]
swap(array[inner], array[inner+1]);
12. After the data has been sorted, the median value can be found. If the array has an odd number of elements the median is the value of the middle element (Hint: arraySize/2 is the middle element). If the array has an even number of elements then the median is the average of the middle two elements (Hint: arraySize/2 and ( arraySize/2) - 1 are the two middle elements). The median value should be returned by the median function.
13. The main routine should output the median value in an appropriate manner.
14. The main routine should also output the sorted array with 5 grades per line.
15. Carefully develop test cases for your program. Most of your test cases do not need to contain lots of values. Make sure to include incorrect inputs such as negative grade values. Calculate what your mean and median values should be for your test cases. Document your test cases in a Word document.
16. Run your test cases with your program to see if your program generates the expected output. If not, troubleshoot your program and fix the problem. When your program executes a test case correctly, take a screen shot of the program output and paste it into your Word document to prove that your test case executed correctly with your program.
17. Make sure that your code is properly formatted! You also need to make sure you include a comment block for each function which documents the purpose, inputs, and outputs of each function!

Explanation / Answer

#include <iostream>

#include <iomanip>

using namespace std;

float x(int Amount,int list[]) // x= mean, function and equation

{

       int Grade;

       float Sum=0;

       float avg;

       for (Grade=0;Grade<Amount;Grade++)

              Sum+=list[Grade];

       avg= Sum/Amount;

       return avg;

       }

float y(int Amount,int list[]) // y = median, function and swap equation

{

       double avg=0;

for (int outer = 0; outer < Amount; outer++) // sort the array in ascending order

for (int inner = 0; inner < Amount-1; inner++)

if (list[inner] > list[inner+1])

           swap(list[inner], list[inner+1]);

if(Amount%2==0) //if the outcome is an even number

       {

              avg=list [Amount/2]+list[C/2-1]; //

avg=avg/2.0;

}

       else

       avg=list[Amount/2];

        return avg;

}

int main()

{

       int list[100],Amount=0,Sum=0,Grade=0; // Array [0-99] with variables

       int i; // a number to compare to

       float mean;

       float median;

       cout<< "How many students are in the class?";

       cin >> Amount;

   

      

       for(i=0;i<Amount;i++) // loop

       {

       while(list[i]<0 || list[i]>100){ // Loop with parameter within 1-100

       cout<< "Enter grade for student";

       cin >> list[i];

       }

       }

      

       mean=x(Amount,list); //Mean (Variables)

       median=y(Amount,list);

      

       cout << "mean=" << mean << endl;

       cout << "median=" << median<<endl;

       return 0;

}