Question

In: Computer Science

**C++ Programming Language** a program that computes the average of a collection of numbers and then...

**C++ Programming Language**

a program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. The objective of this assignment is to select a language that you have never used before and modify the program from the text so that it outputs the number of A's, B's, C's, D's and F's. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade is any score that is not an F, but is at least 10% less than the average. Any scores that are within 10% of the average (either less than or greater than) are C's.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#include<iostream>

#include<cmath>

using namespace std;

//method to calculate the average value of elements in an array

//and return it

double calculateAverage(double numbers[], int count){

                double sum=0;

                //summing values

                for(int i=0;i<count;i++){

                                sum+=numbers[i];

                }

                //finding average

                double avg=(double)sum/count;

                return avg;

}

//method to display the required statistics about numbers in an array/collection

void displayStats(double numbers[], int count){

                //finding average

                double avg=calculateAverage(numbers,count);

                //initializing number of As, Bs...Fs and number of values above

                //average to 0.

                int A=0, B=0, C=0, D=0, F=0, aboveAvg=0;

                //looping through each element in numbers array

                for(int i=0;i<count;i++){

                                //checking if number is above average

                                if(numbers[i]>avg){

                                               aboveAvg++;

                                }

                                //finding the grade

                                if(numbers[i]>=(avg+avg*0.2)){

                                               //value >= 20% greater than the average

                                               A++;

                                }else if(numbers[i]>=(avg+avg*0.1)){

                                               //value >= 10% greater than the average

                                               B++;

                                }else if(numbers[i]<=(avg-avg*0.2)){

                                               //value <= 20% less than the average

                                               F++;

                                }else if(numbers[i]<=(avg-avg*0.1)){

                                               //value <= 10% less than the average

                                               D++;

                                }else{

                                               //value within 10% of average

                                               C++;

                                }

                }

                //displaying stats to the user

                cout<<"Average value: "<<avg<<endl;

                cout<<"Number of values greater than average: "<<aboveAvg<<endl;

                cout<<"Number of As: "<<A<<endl;

                cout<<"Number of Bs: "<<B<<endl;

                cout<<"Number of Cs: "<<C<<endl;

                cout<<"Number of Ds: "<<D<<endl;

                cout<<"Number of Fs: "<<F<<endl;

}

int main(){

                //creating an array containing some numbers

                double collection[]={90,98,70,65,50,75,40,92,87,77};

                //displaying stats

                displayStats(collection, 10);        

                return 0;

}

/*OUTPUT*/

Average value: 74.4

Number of values greater than average: 6

Number of As: 3

Number of Bs: 1

Number of Cs: 3

Number of Ds: 1

Number of Fs: 2


Related Solutions

Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X,...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X, if X is greater than 1 and X is less than 100. Put the inline function in a main program that reads X from the keyboard, calls the function, and then outputs the result. 2. Show an empty statement and detail what it does? 3. A collection of predefined functions is called a Database                    C) Subroutine                       E) None of these Library                       D) Directive 4....
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during their candy bar fundraiser using the following data: 12 bars per case. The candy was sold for $1.00 per bar. Each case cost $8.00. They are required to give the student government association 10% of their earnings. The program should ask the user how many bars were sold. The program should calculate and display the SGA proceed's, the Cheer team's proceeds, and the appropriate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT