Read the notes and hints very carefully! Develo arrays, and a random number gene
ID: 3701251 • Letter: R
Question
Read the notes and hints very carefully! Develo arrays, and a random number generator. p a system flowchart and then write a menu-driven Ct+ program that uses user-defined functions program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Largest Quit or Help ) option will invoke a function named helpl) which will display a help screen. The help be used, and what screen(s) should guide the user how to interact with the program, type of data to results would the program produce. Each help screen should remain on the monitor until the user st any key. Once the rikes user completes reading the helpl) screens, striking any key will clear the screen and the menu is displayed again. The main() function will declare an array of 15 elements. The elements are of type float. The menu opt L will ask the user for the actual number of elements for the array. The program must verify that the number of elements does not exceed 15 and is not a negative number or Q. Your code must check these. actual for L or I for Largest ) option will invoke a function named largest! ) which will prompt the user for the number of elements for the array to be examined using the function sizeofArrayl ] which will read and validate the desired array elements and returns it to the calling function. The program will then use the returned size of the array to fill the array using the number generator functions shown at the end of this assignment. Your program will ask the user for the range of values for the elements of the array and uses these numbers in a random generator function to fill the array. Once the array is filled, the program will call the function findLargestf ) which will find and return the largest number in the array to the calling function. The program will then call the function frequency), that will compute and return the frequency of occurrence of the largest number. The program will then display the array elements, the largest number, and its frequency of occurrence using the function displayl ) in the format shown below. The output shown is for an array of five elements with an array identifier a. a101 “ xxxx .xx al1] ·Kxxx .xx (2)x ?13-xxxx .xx Largest no.XXX.xx FrequencyxxExplanation / Answer
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
float randMToN(float M, float N)
{
return M+(rand() / (RAND_MAX/(N-M)));
}
void printWait();
void printHelp()
{
char ch;
system("clear");//Replace clear with cls for windows
cout<<"This program calucates the largest number and its frequency in a given array of size atmost 15"<<endl;
cout<<"To calucate the largest number, input 'L' or 'l' in the main menu and provide the required information"<<endl;
cout<<"To quit the program, press 'Q' or 'q'"<<endl;
printWait();
}
void largest(float a[], int size);
int sizeOfArray(void);
float findLargest(float a[], int myS);
int frequency(float a[], float largestNo, int myS);
void display(float a[], float largestNo, int freq, int myS);
int main()
{
float array[15];
int size;
char choice;
while(1)
{
system("clear"); // Replace clear with cls for windows
cout<<"e[1mHe[0melp e[1mLe[0margest e[1mQe[0muit"<<endl;
cin>>choice;
switch(choice){
case 'H':
case 'h':
printHelp();
break;
case 'L':
case 'l':
largest(array,15);
break;
case 'Q':
case 'q':
return 0;
default:
cout<<"You have selected an invalid option"<<endl;
printWait();
break;
}
}
return 0;
}
void largest(float a[], int size)
{
int myS;
float min, max;
float largestNo;
int freq;
char ch;
myS = sizeOfArray();
cout<<"Enter the minimum value for array elements: ";
cin>>min;
cout<<"Enter the maximum value for array elements: ";
cin>>max;
for(int i=0; i<myS;i++)
{
a[i] = randMToN(min,max);
}
largestNo = findLargest(a,myS);
freq = frequency(a,largestNo,myS);
display(a,largestNo,freq,myS);
cin.get();
}
int sizeOfArray(void)
{
int size;
cout<<"Enter the size of array: ";
cin>>size;
if(size <=0 || size>15)
{
cout<<"Size is out of bounds"<<endl;
}
else return size;
}
float findLargest(float a[], int myS)
{
float largest = 0;
for(int i=0; i<myS;i++)
{
if(a[i] > largest){
largest = a[i];
}
}
return largest;
}
int frequency(float a[], float largestNo, int myS)
{
int freq = 0;
for(int i = 0; i < myS; i++)
{
if(a[i] == largestNo)
freq++;
}
return freq;
}
void display(float a[], float largestNo, int freq, int myS)
{
int y = 90;
cout<<setprecision(2)<<fixed;
for(int i = 0; i < myS; i++)
{
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}
cout<<"Largest no. = "<<largestNo<<" Frequency = "<<freq<<endl;
printWait();
}
void printWait(){
int x = 100; //Coordinates to print Strike any key to continue
int y = 90; // Please change it according to your console
cout<<"["<<x<<";"<<y<<"HStrike any Key to continue..."<<endl;
cin.get();
}
/* I have written this code on linux machine. Please make changes accordingly if yoiu are using windows */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.