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

I need help with the following C Program please Statistics Calculator 1) Use arr

ID: 673423 • Letter: I

Question

I need help with the following C Program please

Statistics Calculator

1) Use arrays

2) Use while and for loops

3) Use if/else statements

In this programming assignment you will write a program that will read a variable number of real numbers. The program will then compute the mean (or average), minimum, and maximum of the numbers entered.

1. The program will ask for the user to enter numbers. Entry of the numbers will end when 20 numbers have been entered, or when the user inputs 'q' (or any other non-numeric character). Any numbers beyond the maximum of 20 will be ignored.

2. The program will then print the (up to 20) numbers that were entered.

3. Finally, the program will compute the average, maximum, and minimum of the numbers entered and print out the resulting statistics. An example session is shown below.

4. If no valid numbers are entered, you should print out an error message to that

Example:

$ ./a.out

Enter real numbers, up to 20, q to quit

10 37 15 21 18 q You entered the following values:

10.0 37.0 15.0 21.0 18.0 The values have mean 20.2, max 37.0, and min 10.0

$ ./a.out

Enter real numbers, up to 20, q to quit

q

No valid numbers entered

$ ./a.out

Enter real numbers, up to 20, q to quit

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 You entered the following values:

1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0

14.0 15.0 16.0 17.0 18.0 19.0 20.0 The values have mean 10.5, max 20.0, and min 1.0

Explanation / Answer

public class StatCalc {
    
        private int count;   // Number of numbers that have been entered.
        private double sum; // The sum of all the items that have been entered.
        private double squareSum; // The sum of the squares of all the items.
        private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
        private double min = Double.POSITIVE_INFINITY; // Smallest item seen.
    
        public void enter(double num) {
              // Add the number to the dataset.
           count++;
           sum += num;
           squareSum += num*num;
           if (num > max)
              max = num;
           if (num < min)
              min = num;
        }
    
        public int getCount() {  
              // Return number of items that have been entered.
           return count;
        }
    
        public double getSum() {
              // Return the sum of all the items that have been entered.
           return sum;
        }
    
        public double getMean() {
              // Return average of all the items that have been entered.
              // Value is Double.NaN if count == 0.
           return sum / count;
        }
    
        public double getStandardDeviation() {
             // Return standard deviation of all the items that have been entered.
             // Value will be Double.NaN if count == 0.
           double mean = getMean();
           return Math.sqrt( squareSum/count - mean*mean );
        }
       
        public double getMin() {
             // Return the smallest item that has been entered.
             // Value will be infinity if no items have been entered.
           return min;
        }
       
        public double getMax() {
             // Return the largest item that has been entered.
             // Value will be -infinity if no items have been entered.
           return max;
        }
    
     } // end class StatCalc



Main Program

     /*
         Computes and display several statistics for a set of non-zero
         numbers entered by the user. (Input ends when user enters 0.)
         This program uses StatCalc.java.0
     */
    
     public class SimpleStats {
    
        public static void main(String[] args) {
          
           StatCalc calc; // Computes stats for numbers entered by user.
           calc = new StatCalc();
          
           double item;    // One number entered by the user.
          
           TextIO.putln("Enter your numbers. Enter 0 to end.");
           TextIO.putln();
          
           do {
              TextIO.put("? ");
              item = TextIO.getlnDouble();
              if (item != 0)
                 calc.enter(item);
           } while ( item != 0 );
          
           TextIO.putln(" Statistics about your calc: ");
           TextIO.putln("   Count:              " + calc.getCount());
           TextIO.putln("   Sum:                " + calc.getSum());
           TextIO.putln("   Minimum:            " + calc.getMin());
           TextIO.putln("   Maximum:            " + calc.getMax());
           TextIO.putln("   Average:            " + calc.getMean());
           TextIO.putln("   Standard Deviation: " + calc.getStandardDeviation());
          
        } // end main()
       
     } // end SimpleStats