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

Develop a program flowchart and then write a menu-driven C++ program that will s

ID: 3724003 • Letter: D

Question

Develop a program flowchart and then write a menu-driven C++ program that will solve the following problem. The menu is shown below. Note: the letters shown as bold are for emphasis and you do not have to make them bold in your program. The program uses arrays, references, pointers, and functions to accomplish the tasks outlined below.

Help InputData Minimum maXimum miNmax Quit

Upon program execution, the screen will be cleared and the menu shown above will appear at the top of the screen and properly centered. The menu items are explained below. H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user how to interact with the program, type of data to be entered, and what results would the program produce. Each help screen should remain on the monitor until the user strikes any key (e.g., strike the space bar followed by a carriage return). Once the user strikes a key, the screen will be cleared and the menu is displayed again. Restrictions on the options M, m, X, x, N, and n would be mentioned here.

I or i ( for InputData ) option will prompt the user for the number of inputs to be tested. The program uses this number to fill a double array declared to store up to 35 elements. This option must be executed before options M, X, and N. A boolean flags are to be used here. See data to be used later on this assignment.

M or m ( for Minimum ) option will compute and display the minimum and frequency of occurrences of this minimum on the screen. This option implements the following two function prototypes:

Double~& minfunc(double& d1, double& d2);

void frequency(double& d1, short& freq);

The function minfunc() will receive two references, representing two data items, and returns a reference to the minimum to the calling function. Function frequency() will compute the frequency of occurrences for the minimum number in a data set. This function may be called from within minfunc() function. Once the user viewed the results, striking any key will clear the screen followed by the menu display. This option must be executed after option I or i.

X or x ( for maXimum ) option will compute and display the maximum and frequency of occurrences of this maximum on the screen. This option implements the following two function prototypes:

double& maxfunc( double& d1, double& d2);

void frequency( double& d1, short& freq);// this is the same as above

The function maxfunc() will receive two references, representing two data items, and returns a reference to the maximum to the calling function. Function frequency() will compute the frequency of occurrences for the maximum number in a data set. This function may be called from within maxfunc() function. Once the user viewed the results, striking any key will clear the screen followed by the menu display. This option must be executed after option I or i.

N or n ( for miNmax ) option will compute and display the minimum, the maximum, and their frequencies of occurrences. This option uses the functions mentioned above and the following function prototype:

void minmax( double* minv, short* minFreq, double* maxv, short* maxFreq);

the function minmax() receives values calculated before and processes them accordingly. The minimum value, the maximum value, and their frequencies of occurrences are displayed on the monitor. Once the user viewed the results, striking any key will clear the screen followed by the menu display. This option must be executed after options M and X. Again, you need to have mechanism in place so that this condition is met.

Q or q (for Quit) option will clear the screen and returns the control to the Visual Studio IDE. Sample Data to be used is shown below. Of course, your program will work with any set of numbers within the specified range of elements.

Explanation / Answer

// File Name: ArrayMinMax.cpp
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#define MAX 35
using namespace std;
// To store number of elements to be stored in array
int no;
// Array to store numbers
double arr[MAX];

// Function to display menu, accept user choice and return it
char menu()
{
char choice;
cout<<" H or h for Help";
cout<<" I or i for Input Data";
cout<<" M or m for Minimum";
cout<<" X or x for Maximum";
cout<<" N or n for MinMax";
cout<<" Q or q for Quit";
cout<<" Enter your choice: ";
cin>>choice;
return choice;
}// End of function

// Function to display help
void help()
{
cout<<" Enter a lowercase alphabet or upper case alphabet from the menu.";
cout<<" I or i ( for InputData ) option will prompt the user for the number of inputs to be tested.
The program uses this number to fill a double array declared to store up to 35 elements.
This option must be executed before options M, X, and N.";
cout<<" M or m ( for Minimum ) option will compute and display the minimum and frequency of occurrences of this minimum on the screen.
This option must be executed after option I or i";
cout<<" X or x ( for maXimum ) option will compute and display the maximum and frequency of occurrences of this maximum on the screen.
This option must be executed after option I or i";
cout<<" N or n ( for miNmax ) option will compute and display the minimum, the maximum, and their frequencies of occurrences.
This option must be executed after option M and X";
cout<<" Q or q (for Quit) option will clear the screen and returns the control to the Visual Studio IDE. ";
}// End of function

// Function to accept numbers to store in array
void input()
{
cout<<" Enter "<<no<<" elements. ";
// Loops no times
for(int x = 0; x < no; x++)
// Accepts data and stores it in x index position
cin>>arr[x];
}// End of function

// Function to calculate the frequency of number d1 in array arr and return the result by reference freq
void frequency(double& d1, short& freq)
{
// Loops no times
for(int x = 0; x < no; x++)
{
// Checks if arr x index position number is equals to number d1
if(arr[x] == d1)
// Increase the frequency counter by one
freq++;
}// End of for loop
}// End of function

// Function to return minimum number between d1 and d2
double & minfunc(double& d1, double& d2)
{
// Checks id d1 is less than d2 then return d1
if(d1 < d2)
return d1;
// Otherwise return d2
else
return d2;
}// End of function

// Function to return maximum number between d1 and d2
double & maxfunc(double& d1, double& d2)
{
// Checks id d1 is greater than d2 then return d1
if(d1 > d2)
return d1;
// Otherwise return d2
else
return d2;
}// End of function

// Function to display result
void minmax( double* minv, short* minFreq, double* maxv, short* maxFreq)
{
cout<<" Minimum value: "<<*minv;
cout<<" Minimum frequency: "<<*minFreq;
cout<<" Maximum value: "<<*maxv;
cout<<" Maximum frequency: "<<*maxFreq;
}// End of function

// main function definition
int main()
{
// To store flag option value
char flag, flag1, flag2;
// To store the number entered by the user
double one, two;
// To store minimum and maximum number returned by the function
double minNo, maxNo;
// To store minimum and maximum frequency
short minF = 0, maxF = 0;
// Loops till user choice is not 'q' or 'Q'
do
{
// Calls the function to accept user choice from menu
switch(menu())
{
case 'h':
case 'H':
// Calls the function to display help
help();
break;
case 'i':
case 'I':
// Loops till array length not between 1 and 34
do
{
// Accepts the length of the array
cout<<" Enter the number of inputs to be tested. ";
cin>>no;
// Checks the number of elements entered by the user
if(no > 0 && no < 35)
break;
cout<<" Number must be between 1 and 34.";
}while(1); // End of do - while loop
// Calls the function to accept data
input();
// Sets the flag to 'i' option
flag = 'i';
break;
case 'm':
case 'M':
// Checks if the flag value is not 'i'
if(flag != 'i')
{
// Display error message
cout<<" ERROR: You must user i or I before this option.";
break;
}// End of if condition
// Otherwise option 'i' is selected before
else
{
// Accepts two numbers
cout<<" Enter two numbers to find minimum number frequency of 2 numbers: ";
cin>>one>>two;
// Calls the function to find minimum value out of one and two
minNo = minfunc(one, two);
// Calls the function to calculate frequency of minimum number in array
frequency(minNo, minF);
// Displays minimum number and its frequency
cout<<" Minimum number: "<<minNo<<" Frequency: "<<minF;
// Sets the flag value to 'm'
flag1 = 'm';
}// End of else
break;
case 'x':
case 'X':
// Checks if the flag value is not 'i'
if(flag != 'i')
{
// Display error message
cout<<" ERROR: You must user i or I before this option.";
break;
}// End of if condition
// Otherwise option 'i' is selected before
else
{
// Accepts two numbers
cout<<" Enter two numbers to find maximum number frequency of 2 numbers: ";
cin>>one>>two;
// Calls the function to find maximum value out of one and two
maxNo = maxfunc(one, two);
// Calls the function to calculate frequency of maximum number in array
frequency(maxNo, maxF);
// Displays maximum number and its frequency
cout<<" Maximum number: "<<maxNo<<" Frequency: "<<maxF;
// Sets the flag value to 'x'
flag2 = 'x';
}// End of else
break;
case 'n':
case 'N':
// Checks if the flag1 value is 'm' and flag2 value is 'x'
if(flag1 == 'm' && flag2 == 'x')
// Call the function to display information
minmax(&minNo, &minF, &maxNo, &maxF);
// Otherwise display error message
else
{
cout<<" ERROR: You must user m and x option before this option.";
break;
}// End of else
break;
case 'q':
case 'Q':
exit(0);
default:
cout<<" Invalid choice";
}// End of switch - case
fflush(stdin);
cout<<" Press Enter Key to continue.";
getchar();
system("cls");
}while(1);// End of do - while condition
}// End of main function

Sample Output:

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: s

Invalid choice
Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: m

ERROR: You must user i or I before this option.
Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: x

ERROR: You must user i or I before this option.
Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: n

ERROR: You must user m and x option before this option.
Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: i

Enter the number of inputs to be tested. 10

Enter 10 elements. 3
10
3
10
5
10
3
10
4
10

Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: M

Enter two numbers to find minimum number frequency of 2 numbers: 22
3

Minimum number: 3
Frequency: 3

Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: x

Enter two numbers to find maximum number frequency of 2 numbers: 10
7

Maximum number: 10
Frequency: 5

Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: N

Minimum value: 3
Minimum frequency: 3
Maximum value: 10
Maximum frequency: 5
Press Enter Key to continue.

H or h for Help
I or i for Input Data
M or m for Minimum
X or x for Maximum
N or n for MinMax
Q or q for Quit
Enter your choice: q

Process returned 0 (0x0) execution time : 148.237 s
Press any key to continue.