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.
Mattingly "AI & Prompt Design: Named Entity Recognition"
Please help. C++ The program is an interactive program th.pdf
1. 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,
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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
8. 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
9. 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.
10. 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
11. 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
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;
12. cout <<"These are your choices : " << endl;
cout <<"N-Numbers"<> 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"<0){
13. 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<0){
if(i>b){
b = i;
}
}
}
if(b!=0){
cout << "Biggest number is :" <frequency[max]){
max = i;
}
}else{
14. if(i0){
if(frequency[i]==1){
count++;
}
else{
count+=frequency[i];
}
}
}
if(count!=0){
cout << "Total Number entered are : "<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;
}
}