..ooo AT&T; 6:50 PM ELET 2300-03 Homework No. 6 Dr. E Attarzadeh 70 Points Due 0
ID: 3689594 • Letter: #
Question
..ooo AT&T; 6:50 PM ELET 2300-03 Homework No. 6 Dr. E Attarzadeh 70 Points Due 04/14/2016 03/29/2016 9 PM It is very important that you read the notes at the end of each assignment for this and all other assignments. Develop a flowchart and then write a menu-driven C+ program that uses functions, arrays and references. Upon program execution, the screen will be cleared and the menu shown above wl appear at the top of the screen and centered. The menu items are explained below Largest Frequency Quit H or h ( for Help) option will invoke a function named help0 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. Once the user's input is processed, the screen will be cleared and the menu is displayed again. L or l (for Largest) option will invoke a function named largestLwhich will prompt the user for the number of elements of a float type array to be examined. The program will use a function named tray( which will read from the keyboard, and then returns the number of elements, followed another prompt to get the actual elements, using the function getInputs.IThe program will then call a function named findLargest) which will compute and return the largest numberExplanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{ char ch;
float array[30];
int n;
do{int a=0;
printf(Enter the number of elements you want to enter);
scanf(%d,n);
if(n>30)
{printf(elements must not exceed 30);
a=1;}}while(a==1);
do{clrscr();
printf( Enter: H Help S-Smallest L-Largest Q-Quit );
scanf(%c,&ch);
switch(ch)
{
case h
{clrscr();help();
break;}
case H
{ clrscr();help();
break;}
}
case s
{ clrscr();int size=smallest();
int chk=sizeOfArray(size );
if(chk==1)
{ getInputs(array, size);
float min=findSmallest(array,size );
int count=frequency(min,array);
display(array,min,count);
printf(Strike any key to continue...);
getch();
}
break;}
case S
{ clrscr();int size=smallest();
int chk=sizeOfArray(size );
if(chk==1)
{ getInputs(array, size);
float min=findSmallest(array,size );
int count=frequency(min,array);
display(array,min,count);
printf(Strike any key to continue...);
getch();
}
break;}
case l
{ clrscr();int size=largest();
int chk=sizeOfArray(size );
if(chk==1)
{ getInputs(array, size);
float max=findLargest(array,size );
int count=frequency(max,array);
display(array,max,count);
printf(Strike any key to continue...);
getch();
}
break;}
case L
{ clrscr();int size=largest();
int chk=sizeOfArray(size );
if(chk==1)
{ getInputs(array, size);
float max=findLargest(array,size );
int count=frequency(max,array);
display(array,max,count);
printf(Strike any key to continue...);
getch();
}
break;}
}while((ch!=Q)||(ch!=q));
}
void help()
{printf(The option S will display the array elements, the smallest number, and its frequency of occurrence on the screen. The option L will display the array elements, the largest number, and its frequency of occurrence on the screen. ); }
int smallest()
{int num;
printf(Enter the number of elements of array);
scanf(%d,&num);
return num;}
int largest()
{int num;
printf(Enter the number of elements of array);
scanf(%d,&num);
return num;}
int sizeOfArray(int n )
{ if(n>30)
{printf(elements must not exceed 30);
return 0;}
else return 1;
}
getInputs(float array[], int size)
{printf(Enter the elements);
for(int i=0;i<size;i++)
{scanf(%f,&array[i]);
}
}
float findSmallest(float array[],int size )
{float temp=array[0];
for(inti=0;i<size;i++){
if(array[i]<temp;
{temp=array[i];}}
return temp;
}
float findLargest(float array[],int size )
{float temp=array[0];
for(inti=0;i<size;i++){
if(array[i]>temp;
{temp=array[i];}}
return temp;
}
int frequency(float min,float array[])
{int count=0;
for(inti=0;i<array.length;i++){
if(array[i]==min)
count++;}
return count;
}
void display(float array[],float min, int count)
{ for(inti=0;i<array.length;i++){
printf(%f ,array[i]);}
printf(The smallest numberin array is %f and it occurred %d times,min,count);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.