Please help C The program is an interactive program that rea

Please help. C++

The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For each input, the program will give a short response printed to cout. Each response to cout is followed by a single endl.
Important: The program must not try to store all the numbers in a single big array. In fact, it is outlawed by the CSI police that you have any array that is larger than 100 elements. Instead, you should create a frequency array which has indexes from [0] to [99]. A location, such as frequency[i], tells you how many times the number i has occurred in the input. This frequency array should be initialized to all zeros, and each time a number is read, the program will add one to the corresponding array location. For example, frequency[42] begins at zero. When one 42 is read, frequency[42] is increased to one. If another 42 is read, frequency[42] is increased to two, and so on. All of the statistics that you need to calculate can be computed based on the frequency array (so that you don\'t need to store all those numbers separately).
• Input: The letter N followed by an integer in the range 0 to 99. The biggest possible input number is 99. The specification does not care what the program does for numbers that are outside of the legal range.
Output: The word \"OK\".
• Input: The letter S.
Output: The output is the SUM of all the input numbers read so far. This output is 0 if there has not yet been any numbers read by the program.
• Input: The letter A.
Output: The output is the AVERAGE of all the input numbers read so far, calculated as a double number. For example, if there have been four input numbers 2, 2, 6 and 5, then the average is 3.75. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of an average.
• Input: The letter B.
Output: The output is the BIGGEST of all the input numbers read so far, For example, if there have been four input numbers 2, 2, 6 and 5, then the biggest is 6. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of a number.
• Input: The letter F.
Output: The output is the most FREQUENT of all the input numbers read so far--in other words, the number that has been read most often (also called the \"mode\"). If there are several numbers that are equally often, then the smallest number is printed. For example, if there have been four input numbers 2, 2, 6 and 5, then the most frequent is 2. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead.
• Input: The letter H.
Output: The output is a count of HOW MANY numbers have been input so far. This could be as small as zero.
• Input: The letter M.
Output: The output is the MEDIAN of all the input numbers read so far. The median is a number that has no more than half of the input numbers below it and no more than half the input numbers above it. For example, if there have been five input numbers 2, 2, 3, 6 and 5, then the median is 3 since two of the five numbers are below 3 and two of the five numbers are above 3. Notice that if there has been an even number of inputs (such as 2, 3, 6, 5) then there may be several choices for the median (in this example, the median could be either 3 or 5). In this case, it does not matter whether the output is the 3 or the 5. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of the median.
• Input: The letter Q.
Output: The program outputs the word \"END\" and then stops.
SAMPLE SESSION WITH THE PROGRAM: User input in the session is written in italic. Program output is written in bold:
Welcome to Stats Array!
These are your choices:
N- Numbers
S- Sum of all
A- Average of all
B- Biggest of all
F- Most Frequent of all
H- How many numbers
M- Median of all
Q- Quit
N 2
OK
N 2
OK
N 6
OK
N 5
OK
H
4
S
15
A
3.75
F
2
N 3
OK
M
3
Q
END
HINTS:
Read the command characters with an input statement like this (where command is a char variable):
cin >> command;
Use a switch statement to control the action of the program based on the command character that has been read. If the command character was an N, then read the number with an input statement like this (where number is an integer variable):
cin >> number;
Don\'t forget the break statement at the end of each case.
Please help. C++

The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For each input, the program will give a short response printed to cout. Each response to cout is followed by a single endl.
Important: The program must not try to store all the numbers in a single big array. In fact, it is outlawed by the CSI police that you have any array that is larger than 100 elements. Instead, you should create a frequency array which has indexes from [0] to [99]. A location, such as frequency[i], tells you how many times the number i has occurred in the input. This frequency array should be initialized to all zeros, and each time a number is read, the program will add one to the corresponding array location. For example, frequency[42] begins at zero. When one 42 is read, frequency[42] is increased to one. If another 42 is read, frequency[42] is increased to two, and so on. All of the statistics that you need to calculate can be computed based on the frequency array (so that you don\'t need to store all those numbers separately).
• Input: The letter N followed by an integer in the range 0 to 99. The biggest possible input number is 99. The specification does not care what the program does for numbers that are outside of the legal range.
Output: The word \"OK\".
• Input: The letter S.
Output: The output is the SUM of all the input numbers read so far. This output is 0 if there has not yet been any numbers read by the program.
• Input: The letter A.
Output: The output is the AVERAGE of all the input numbers read so far, calculated as a double number. For example, if there have been four input numbers 2, 2, 6 and 5, then the average is 3.75. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of an average.
• Input: The letter B.
Output: The output is the BIGGEST of all the input numbers read so far, For example, if there have been four input numbers 2, 2, 6 and 5, then the biggest is 6. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of a number.
• Input: The letter F.
Output: The output is the most FREQUENT of all the input numbers read so far--in other words, the number that has been read most often (also called the \"mode\"). If there are several numbers that are equally often, then the smallest number is printed. For example, if there have been four input numbers 2, 2, 6 and 5, then the most frequent is 2. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead.
• Input: The letter H.
Output: The output is a count of HOW MANY numbers have been input so far. This could be as small as zero.
• Input: The letter M.
Output: The output is the MEDIAN of all the input numbers read so far. The median is a number that has no more than half of the input numbers below it and no more than half the input numbers above it. For example, if there have been five input numbers 2, 2, 3, 6 and 5, then the median is 3 since two of the five numbers are below 3 and two of the five numbers are above 3. Notice that if there has been an even number of inputs (such as 2, 3, 6, 5) then there may be several choices for the median (in this example, the median could be either 3 or 5). In this case, it does not matter whether the output is the 3 or the 5. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of the median.
• Input: The letter Q.
Output: The program outputs the word \"END\" and then stops.
SAMPLE SESSION WITH THE PROGRAM: User input in the session is written in italic. Program output is written in bold:
Welcome to Stats Array!
These are your choices:
N- Numbers
S- Sum of all
A- Average of all
B- Biggest of all
F- Most Frequent of all
H- How many numbers
M- Median of all
Q- Quit
N 2
OK
N 2
OK
N 6
OK
N 5
OK
H
4
S
15
A
3.75
F
2
N 3
OK
M
3
Q
END
HINTS:
Read the command characters with an input statement like this (where command is a char variable):
cin >> command;
Use a switch statement to control the action of the program based on the command character that has been read. If the command character was an N, then read the number with an input statement like this (where number is an integer variable):
cin >> number;
Don\'t forget the break statement at the end of each case.

The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For each input, the program will give a short response printed to cout. Each response to cout is followed by a single endl.
Important: The program must not try to store all the numbers in a single big array. In fact, it is outlawed by the CSI police that you have any array that is larger than 100 elements. Instead, you should create a frequency array which has indexes from [0] to [99]. A location, such as frequency[i], tells you how many times the number i has occurred in the input. This frequency array should be initialized to all zeros, and each time a number is read, the program will add one to the corresponding array location. For example, frequency[42] begins at zero. When one 42 is read, frequency[42] is increased to one. If another 42 is read, frequency[42] is increased to two, and so on. All of the statistics that you need to calculate can be computed based on the frequency array (so that you don\'t need to store all those numbers separately).
• Input: The letter N followed by an integer in the range 0 to 99. The biggest possible input number is 99. The specification does not care what the program does for numbers that are outside of the legal range.
Output: The word \"OK\".
• Input: The letter S.
Output: The output is the SUM of all the input numbers read so far. This output is 0 if there has not yet been any numbers read by the program.
• Input: The letter A.
Output: The output is the AVERAGE of all the input numbers read so far, calculated as a double number. For example, if there have been four input numbers 2, 2, 6 and 5, then the average is 3.75. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of an average.
• Input: The letter B.
Output: The output is the BIGGEST of all the input numbers read so far, For example, if there have been four input numbers 2, 2, 6 and 5, then the biggest is 6. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of a number.
• Input: The letter F.
Output: The output is the most FREQUENT of all the input numbers read so far--in other words, the number that has been read most often (also called the \"mode\"). If there are several numbers that are equally often, then the smallest number is printed. For example, if there have been four input numbers 2, 2, 6 and 5, then the most frequent is 2. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead.
• Input: The letter H.
Output: The output is a count of HOW MANY numbers have been input so far. This could be as small as zero.
• Input: The letter M.
Output: The output is the MEDIAN of all the input numbers read so far. The median is a number that has no more than half of the input numbers below it and no more than half the input numbers above it. For example, if there have been five input numbers 2, 2, 3, 6 and 5, then the median is 3 since two of the five numbers are below 3 and two of the five numbers are above 3. Notice that if there has been an even number of inputs (such as 2, 3, 6, 5) then there may be several choices for the median (in this example, the median could be either 3 or 5). In this case, it does not matter whether the output is the 3 or the 5. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of the median.
• Input: The letter Q.
Output: The program outputs the word \"END\" and then stops.
SAMPLE SESSION WITH THE PROGRAM: User input in the session is written in italic. Program output is written in bold:
Welcome to Stats Array!
These are your choices:
N- Numbers
S- Sum of all
A- Average of all
B- Biggest of all
F- Most Frequent of all
H- How many numbers
M- Median of all
Q- Quit
N 2
OK
N 2
OK
N 6
OK
N 5
OK
H
4
S
15
A
3.75
F
2
N 3
OK
M
3
Q
END
HINTS:
Read the command characters with an input statement like this (where command is a char variable):
cin >> command;
Use a switch statement to control the action of the program based on the command character that has been read. If the command character was an N, then read the number with an input statement like this (where number is an integer variable):
cin >> number;
Don\'t forget the break statement at the end of each case.
The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For each input, the program will give a short response printed to cout. Each response to cout is followed by a single endl.
Important: The program must not try to store all the numbers in a single big array. In fact, it is outlawed by the CSI police that you have any array that is larger than 100 elements. Instead, you should create a frequency array which has indexes from [0] to [99]. A location, such as frequency[i], tells you how many times the number i has occurred in the input. This frequency array should be initialized to all zeros, and each time a number is read, the program will add one to the corresponding array location. For example, frequency[42] begins at zero. When one 42 is read, frequency[42] is increased to one. If another 42 is read, frequency[42] is increased to two, and so on. All of the statistics that you need to calculate can be computed based on the frequency array (so that you don\'t need to store all those numbers separately).
• Input: The letter N followed by an integer in the range 0 to 99. The biggest possible input number is 99. The specification does not care what the program does for numbers that are outside of the legal range.
Output: The word \"OK\".
• Input: The letter S.
Output: The output is the SUM of all the input numbers read so far. This output is 0 if there has not yet been any numbers read by the program.
• Input: The letter A.
Output: The output is the AVERAGE of all the input numbers read so far, calculated as a double number. For example, if there have been four input numbers 2, 2, 6 and 5, then the average is 3.75. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of an average.
• Input: The letter B.
Output: The output is the BIGGEST of all the input numbers read so far, For example, if there have been four input numbers 2, 2, 6 and 5, then the biggest is 6. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of a number.
• Input: The letter F.
Output: The output is the most FREQUENT of all the input numbers read so far--in other words, the number that has been read most often (also called the \"mode\"). If there are several numbers that are equally often, then the smallest number is printed. For example, if there have been four input numbers 2, 2, 6 and 5, then the most frequent is 2. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead.
• Input: The letter H.
Output: The output is a count of HOW MANY numbers have been input so far. This could be as small as zero.
• Input: The letter M.
Output: The output is the MEDIAN of all the input numbers read so far. The median is a number that has no more than half of the input numbers below it and no more than half the input numbers above it. For example, if there have been five input numbers 2, 2, 3, 6 and 5, then the median is 3 since two of the five numbers are below 3 and two of the five numbers are above 3. Notice that if there has been an even number of inputs (such as 2, 3, 6, 5) then there may be several choices for the median (in this example, the median could be either 3 or 5). In this case, it does not matter whether the output is the 3 or the 5. If there has not yet been any input numbers, then the program should print the word \"ERROR\" instead of the median.
• Input: The letter Q.
Output: The program outputs the word \"END\" and then stops.
SAMPLE SESSION WITH THE PROGRAM: User input in the session is written in italic. Program output is written in bold:
Welcome to Stats Array!
These are your choices:
N- Numbers
S- Sum of all
A- Average of all
B- Biggest of all
F- Most Frequent of all
H- How many numbers
M- Median of all
Q- Quit
N 2
OK
N 2
OK
N 6
OK
N 5
OK
H
4
S
15
A
3.75
F
2
N 3
OK
M
3
Q
END
HINTS:
Read the command characters with an input statement like this (where command is a char variable):
cin >> command;
Use a switch statement to control the action of the program based on the command character that has been read. If the command character was an N, then read the number with an input statement like this (where number is an integer variable):
cin >> number;
Don\'t forget the break statement at the end of each case.

Solution

Your program is as below :

#include <iostream.h>
using namespace std;
int frequency[100] = {0}; //frequency array
/*Declaration of functions */
void addNumber(void);
void sum(void);
void average(void);
void big(void);
void frequent(void);
void howMany(void);
void median(void);

int main() {
    char command;
   /*Menu printing*/
   cout <<\"Welcome to Stats Array!\"<< endl;
   cout <<\"These are your choices : \" << endl;
   cout <<\"N-Numbers\"<<endl;
   cout <<\"S-Sum of all\"<<endl;
   cout <<\"A-Average of all\"<<endl;
   cout <<\"B-Biggest of all\"<<endl;
   cout <<\"F-Most Frequent of all\"<<endl;
   cout <<\"H-How many numbers\"<<endl;
   cout <<\"M-Median of all\"<<endl;
   cout <<\"Q-Quit\"<<endl;
   do{
   cin >> command;
   switch(command){
           case \'N\' :
            addNumber();
            break;
           case \'S\' :
            sum();
            break;
           case \'A\':
            average();
           break ;
           case \'B\' :
            big();
               break;
           case \'F\' :
            frequent();
           break;
           case \'H\':
            howMany();
           break;
           case \'M\' :
            median();
               break;
           case \'Q\' :
            cout << \"END\";
            break;

   }
   }while(command!=\'Q\');

   getch();
   return 0;
}

void addNumber(void){    //addNumer() add the number to frequency array.
    int number;
    cin >> number;
    cout << \"OK\"<<endl;
    frequency[number]++;
}

void sum(void){        //Gives sum of all numbers that are entered.
   int tsum = 0;
   for (int i=0; i<99 ;i++){
       if(frequency[i]>0){
               tsum= tsum +(i*frequency[i]);
       }
   }
   cout << \"Sum is : \" << tsum << endl;
}

void average(void){        //Gives average of all the numbers entered.
   double count=0.0,tsum = 0.0;
   double avg;
   for (int i=0; i<99 ;i++){
       if(frequency[i]>0){
               tsum = tsum +(i*frequency[i]);
       }
   }
   for(i=0;i<99;i++){
       if(frequency[i]>0){
           if(frequency[i]==1){
               count++;
           }
           else if(frequency[i]>1){
               count+=frequency[i];
           }
       }
   }
   avg = tsum / count;
   if(avg!=0){
   cout << \"Average is : \"<< avg<<endl;
   }
   else{
       cout << \"ERROR\"<<endl ;
   }
}

void big(void){              //Gives Biggest number entered.
   int b = 0;
   for(int i=0; i<99; i++){
       if(frequency[i]>0){
           if(i>b){
                  b = i;
           }
       }
   }
   if(b!=0){
       cout << \"Biggest number is :\" <<b<<endl;
   }
   else{
       cout << \"ERROR\";
   }
}

void frequent(void){          //Gives most frequent number.
       int max=0;
       for (int i=0; i<=99; i++){
       if(frequency[i]!=frequency[max]){
           if(frequency[i]>frequency[max]){
                   max = i;
           }
       }else{
           if(i<max)
               max=i;
           }
       }

       if(max!=0){
       cout << \"Most frequent number is \" << max<< endl;
       }
       else{
       cout << \"ERROR\";
       }

}

void howMany(){            //Gives how many numbers are entered.
   int count = 0;

   for(int i=0;i<=99;i++){
       if(frequency[i]>0){
           if(frequency[i]==1){
               count++;
           }
           else{
               count+=frequency[i];
           }
       }
   }
   if(count!=0){
       cout << \"Total Number entered are : \"<<count<<endl;
   }
   else{
       cout << \"ERROR\";
   }
}

void median(void){           //Gives median of entered number.
   int count=0,no=0;
   int middle,k,j;
   double mdn;

   for(int i=0;i<=99;i++){
       if(frequency[i]>0){
           if(frequency[i]==1){
               no++;
           }
           else{
               no+=frequency[i];
           }
       }
   }
   middle = no/2;
/*Formula for median
   if entered numbers are even than median = {(middle)+(middle+1)}/2
   if entered numbers are odd than median = middle+1 */
   if(no%2==0){
   i=0;
           do{

               if(frequency[i]!=0){
                   if(frequency[i]>1){
                       count += frequency[i];
                           j=i;
                      }
                   else{
                       count++;
                       j = i;
                   }
               }

               i++;
           }while(count!=middle);
           count = 0;
           i=0,k=0;
           do{

               if(frequency[i]!=0){
                   if(frequency[i]>1){
               count += frequency[i];
                       k=i;
                  }
                   else{
                   count++;
                   k = i;
                   }
               }

               i++;
           }while(count!=middle+1);
               mdn = (k + j)/2;
               cout <<\"The median is : \"<<mdn << endl;
       }
   else{
       count=0;
       i=0,k=0;
           do{

               if(frequency[i]!=0){
                   if(frequency[i]>1){
               count += frequency[i];
                       k=i;
                  }
                   else{
                   count++;
                   k = i;
                   }
               }

               i++;
           }while(count!=middle+1);

       mdn = k;
       cout << \" The median is :\"<<mdn << endl;
   }

}

Output :

Welcome to Stats Array!

These are your choices:

N- Numbers

S- Sum of all

A- Average of all

B- Biggest of all

F- Most Frequent of all

H- How many numbers

M- Median of all

Q- Quit

N 2

OK

N 2

OK

N 6

OK

N 5

OK

H

4

S

15

A

3.75

F

2

N 3

OK

M

3

Q

END

 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For
 Please help. C++ The program is an interactive program that reads input from the keyboard. Several instructions (listed below) may be entered by the user. For

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site