SlideShare a Scribd company logo
1 of 15
Download to read offline
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
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"<> 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){
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{
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;
}
}
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 : "<1){
count += frequency[i];
k=i;
}
else{
count++;
k = i;
}
}
i++;
}while(count!=middle+1);
mdn = k;
cout << " The median is :"<

More Related Content

Similar to Please help. C++ The program is an interactive program th.pdf

Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codepradesigali1
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxgerardkortney
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxABDULAHAD507571
 
Introduction to computer_lec_04_fall_2018
Introduction to computer_lec_04_fall_2018Introduction to computer_lec_04_fall_2018
Introduction to computer_lec_04_fall_2018Ramadan Babers, PhD
 
Programming basics
Programming basicsProgramming basics
Programming basicsillidari
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation filesantoshkumarhpu
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsgovendaagoovenda
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsnoahjamessss
 
Part I (1.5 points) Write a C++ program that reads a line from the key...
Part I (1.5 points)        Write a C++ program that reads a line from the key...Part I (1.5 points)        Write a C++ program that reads a line from the key...
Part I (1.5 points) Write a C++ program that reads a line from the key...hwbloom104
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 

Similar to Please help. C++ The program is an interactive program th.pdf (17)

3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source code
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Introduction to computer_lec_04_fall_2018
Introduction to computer_lec_04_fall_2018Introduction to computer_lec_04_fall_2018
Introduction to computer_lec_04_fall_2018
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Introduction to computer_lec_04
Introduction to computer_lec_04Introduction to computer_lec_04
Introduction to computer_lec_04
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functions
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functions
 
Part I (1.5 points) Write a C++ program that reads a line from the key...
Part I (1.5 points)        Write a C++ program that reads a line from the key...Part I (1.5 points)        Write a C++ program that reads a line from the key...
Part I (1.5 points) Write a C++ program that reads a line from the key...
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
paython practical
paython practical paython practical
paython practical
 
C program
C programC program
C program
 

More from fsenterprises

Why do you believe money laundering is a difficult fraud to investig.pdf
Why do you believe money laundering is a difficult fraud to investig.pdfWhy do you believe money laundering is a difficult fraud to investig.pdf
Why do you believe money laundering is a difficult fraud to investig.pdffsenterprises
 
Which of the following is a characteristic of Baroque instrumental m.pdf
Which of the following is a characteristic of Baroque instrumental m.pdfWhich of the following is a characteristic of Baroque instrumental m.pdf
Which of the following is a characteristic of Baroque instrumental m.pdffsenterprises
 
What was the energy that was not passed on to the next trophic le.pdf
What was the energy that was not passed on to the next trophic le.pdfWhat was the energy that was not passed on to the next trophic le.pdf
What was the energy that was not passed on to the next trophic le.pdffsenterprises
 
What sort of religious ideas does the megalith Stonehenge suggest A.pdf
What sort of religious ideas does the megalith Stonehenge suggest A.pdfWhat sort of religious ideas does the megalith Stonehenge suggest A.pdf
What sort of religious ideas does the megalith Stonehenge suggest A.pdffsenterprises
 
What are successful approaches to forecasting and creating a needed .pdf
What are successful approaches to forecasting and creating a needed .pdfWhat are successful approaches to forecasting and creating a needed .pdf
What are successful approaches to forecasting and creating a needed .pdffsenterprises
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
What are the major challenges for managing health care information t.pdf
What are the major challenges for managing health care information t.pdfWhat are the major challenges for managing health care information t.pdf
What are the major challenges for managing health care information t.pdffsenterprises
 
Using the Tustin equivalence with the prewarping method, fnd the dis.pdf
Using the Tustin equivalence with the prewarping method, fnd the dis.pdfUsing the Tustin equivalence with the prewarping method, fnd the dis.pdf
Using the Tustin equivalence with the prewarping method, fnd the dis.pdffsenterprises
 
Use Java programming Thank you very much Programing requirement for.pdf
Use Java programming Thank you very much Programing requirement for.pdfUse Java programming Thank you very much Programing requirement for.pdf
Use Java programming Thank you very much Programing requirement for.pdffsenterprises
 
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdf
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdfTranslate the following C++ code segment into Mic-1 IJVM machine lan.pdf
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdffsenterprises
 
Transactions On September 1 of the current year, Joy Tucker estab.pdf
Transactions On September 1 of the current year, Joy Tucker estab.pdfTransactions On September 1 of the current year, Joy Tucker estab.pdf
Transactions On September 1 of the current year, Joy Tucker estab.pdffsenterprises
 
To correct the vision of a person who is nearR sighted, we use a div.pdf
To correct the vision of a person who is nearR sighted, we use a div.pdfTo correct the vision of a person who is nearR sighted, we use a div.pdf
To correct the vision of a person who is nearR sighted, we use a div.pdffsenterprises
 
The height of the water in the tank pictured below 7 ft. The tank is.pdf
The height of the water in the tank pictured below 7 ft. The tank is.pdfThe height of the water in the tank pictured below 7 ft. The tank is.pdf
The height of the water in the tank pictured below 7 ft. The tank is.pdffsenterprises
 
Suppose that a classroom has 4 light bulbs. The probability that eac.pdf
Suppose that a classroom has 4 light bulbs. The probability that eac.pdfSuppose that a classroom has 4 light bulbs. The probability that eac.pdf
Suppose that a classroom has 4 light bulbs. The probability that eac.pdffsenterprises
 
Security Standards Please respond to the following A number of .pdf
Security Standards Please respond to the following A number of .pdfSecurity Standards Please respond to the following A number of .pdf
Security Standards Please respond to the following A number of .pdffsenterprises
 
Real Estate Finance essay questionWhy did observers at first belie.pdf
Real Estate Finance essay questionWhy did observers at first belie.pdfReal Estate Finance essay questionWhy did observers at first belie.pdf
Real Estate Finance essay questionWhy did observers at first belie.pdffsenterprises
 
Provide your key points of Setup Reducation Provide your key points.pdf
Provide your key points of Setup Reducation  Provide your key points.pdfProvide your key points of Setup Reducation  Provide your key points.pdf
Provide your key points of Setup Reducation Provide your key points.pdffsenterprises
 
please answer this case using down picturein business ethics emplo.pdf
please answer this case using down picturein business ethics emplo.pdfplease answer this case using down picturein business ethics emplo.pdf
please answer this case using down picturein business ethics emplo.pdffsenterprises
 
Al has three times as much money as Bill. Bill has two times as much.pdf
Al has three times as much money as Bill. Bill has two times as much.pdfAl has three times as much money as Bill. Bill has two times as much.pdf
Al has three times as much money as Bill. Bill has two times as much.pdffsenterprises
 
A SURVEY is a tool used to collect information about a population. L.pdf
A SURVEY is a tool used to collect information about a population. L.pdfA SURVEY is a tool used to collect information about a population. L.pdf
A SURVEY is a tool used to collect information about a population. L.pdffsenterprises
 

More from fsenterprises (20)

Why do you believe money laundering is a difficult fraud to investig.pdf
Why do you believe money laundering is a difficult fraud to investig.pdfWhy do you believe money laundering is a difficult fraud to investig.pdf
Why do you believe money laundering is a difficult fraud to investig.pdf
 
Which of the following is a characteristic of Baroque instrumental m.pdf
Which of the following is a characteristic of Baroque instrumental m.pdfWhich of the following is a characteristic of Baroque instrumental m.pdf
Which of the following is a characteristic of Baroque instrumental m.pdf
 
What was the energy that was not passed on to the next trophic le.pdf
What was the energy that was not passed on to the next trophic le.pdfWhat was the energy that was not passed on to the next trophic le.pdf
What was the energy that was not passed on to the next trophic le.pdf
 
What sort of religious ideas does the megalith Stonehenge suggest A.pdf
What sort of religious ideas does the megalith Stonehenge suggest A.pdfWhat sort of religious ideas does the megalith Stonehenge suggest A.pdf
What sort of religious ideas does the megalith Stonehenge suggest A.pdf
 
What are successful approaches to forecasting and creating a needed .pdf
What are successful approaches to forecasting and creating a needed .pdfWhat are successful approaches to forecasting and creating a needed .pdf
What are successful approaches to forecasting and creating a needed .pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
What are the major challenges for managing health care information t.pdf
What are the major challenges for managing health care information t.pdfWhat are the major challenges for managing health care information t.pdf
What are the major challenges for managing health care information t.pdf
 
Using the Tustin equivalence with the prewarping method, fnd the dis.pdf
Using the Tustin equivalence with the prewarping method, fnd the dis.pdfUsing the Tustin equivalence with the prewarping method, fnd the dis.pdf
Using the Tustin equivalence with the prewarping method, fnd the dis.pdf
 
Use Java programming Thank you very much Programing requirement for.pdf
Use Java programming Thank you very much Programing requirement for.pdfUse Java programming Thank you very much Programing requirement for.pdf
Use Java programming Thank you very much Programing requirement for.pdf
 
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdf
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdfTranslate the following C++ code segment into Mic-1 IJVM machine lan.pdf
Translate the following C++ code segment into Mic-1 IJVM machine lan.pdf
 
Transactions On September 1 of the current year, Joy Tucker estab.pdf
Transactions On September 1 of the current year, Joy Tucker estab.pdfTransactions On September 1 of the current year, Joy Tucker estab.pdf
Transactions On September 1 of the current year, Joy Tucker estab.pdf
 
To correct the vision of a person who is nearR sighted, we use a div.pdf
To correct the vision of a person who is nearR sighted, we use a div.pdfTo correct the vision of a person who is nearR sighted, we use a div.pdf
To correct the vision of a person who is nearR sighted, we use a div.pdf
 
The height of the water in the tank pictured below 7 ft. The tank is.pdf
The height of the water in the tank pictured below 7 ft. The tank is.pdfThe height of the water in the tank pictured below 7 ft. The tank is.pdf
The height of the water in the tank pictured below 7 ft. The tank is.pdf
 
Suppose that a classroom has 4 light bulbs. The probability that eac.pdf
Suppose that a classroom has 4 light bulbs. The probability that eac.pdfSuppose that a classroom has 4 light bulbs. The probability that eac.pdf
Suppose that a classroom has 4 light bulbs. The probability that eac.pdf
 
Security Standards Please respond to the following A number of .pdf
Security Standards Please respond to the following A number of .pdfSecurity Standards Please respond to the following A number of .pdf
Security Standards Please respond to the following A number of .pdf
 
Real Estate Finance essay questionWhy did observers at first belie.pdf
Real Estate Finance essay questionWhy did observers at first belie.pdfReal Estate Finance essay questionWhy did observers at first belie.pdf
Real Estate Finance essay questionWhy did observers at first belie.pdf
 
Provide your key points of Setup Reducation Provide your key points.pdf
Provide your key points of Setup Reducation  Provide your key points.pdfProvide your key points of Setup Reducation  Provide your key points.pdf
Provide your key points of Setup Reducation Provide your key points.pdf
 
please answer this case using down picturein business ethics emplo.pdf
please answer this case using down picturein business ethics emplo.pdfplease answer this case using down picturein business ethics emplo.pdf
please answer this case using down picturein business ethics emplo.pdf
 
Al has three times as much money as Bill. Bill has two times as much.pdf
Al has three times as much money as Bill. Bill has two times as much.pdfAl has three times as much money as Bill. Bill has two times as much.pdf
Al has three times as much money as Bill. Bill has two times as much.pdf
 
A SURVEY is a tool used to collect information about a population. L.pdf
A SURVEY is a tool used to collect information about a population. L.pdfA SURVEY is a tool used to collect information about a population. L.pdf
A SURVEY is a tool used to collect information about a population. L.pdf
 

Recently uploaded

UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsISCOPE Publication
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 

Recently uploaded (20)

UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
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; } }
  • 15. 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 : "<1){ count += frequency[i]; k=i; } else{ count++; k = i; } } i++; }while(count!=middle+1); mdn = k; cout << " The median is :"<