Write a C++ program that would report all of the Min and Max.
example:
1. 95
2. 95
3. 80
4. 80
lowest 80 on test(s): 3, 4
highest 95 on test(s): 1, 2
I have started it, however, this only outputs one of the Min and Max and not all of the other instances.
#include<iostream> using namespace std; int main() { int grades[10] , min , max , minIndex , maxIndex ; int n , choice , rt , fix ; int d = 0 ; do{ cout<<"\n\n\nGRADE CENTER\n------------" <<"\n1) Enter new grades" <<"\n2) Print grades" <<"\n3) Print average" <<"\n4) Minimum and Maximum " <<"\n5) Change a grade" <<"\n6) EXIT "; do{cout<<"\nYour selection? (1-6) "; cin>>choice; }while((choice<1)||(choice>6)); if((d==0)&&((choice==2)||(choice==3)||(choice==4)||(choice==5))) cout<<"\nNo data entered yet!!"; if(choice==1) {d = 1 ; cout<<"\nHow many tests? "; cin>> n; for(int i=1 ; i<=n; i++) {cout<<"\ntest "<< i << " ? "; cin>>grades[i]; } } if((choice==2)&&(d==1)) {cout<<"\nGrade Data\n------------"; for(int i=1 ; i<= n ; i++) cout<<"\ntest "<<i<<" : "<<grades[i]; } if((choice==3)&&(d==1)) {rt=0; for(int i=1 ; i<=n; i++) rt=rt+grades[i]; cout<<"\nAverage is "<< rt/n ; } if((choice==4)&&(d==1)) {min = max = grades[1] ; minIndex = maxIndex = 1 ; for(int i=1 ; i<=n; i++) {if (grades[i]<min) { min=grades[i]; minIndex = i ;} if (grades[i]>max) { max=grades[i]; maxIndex = i ;} } cout<<"\nLowest was "<< min << " on test " << minIndex <<"\nHighest was "<< max << " on test "<< maxIndex ; } if((choice==5)&&(d==1)) {cout<<"\nChange test # "; cin>> fix ; cout<<"\nChange grade "<<fix<<" from "<<grades[fix]<<" to? "; cin>>grades[fix]; if (grades[fix]<min) { min=grades[fix]; minIndex = fix ;} if (grades[fix]>max) { max=grades[fix]; maxIndex = fix ;} } }while(choice!=6); cout<<"\n\n"; system("pause"); return 0; }
#include <iostream>
using namespace std;
#define SIZE 50
int main()
{
int array[SIZE];
int i, max, min, size;
cout<<"Enter size of the array: ";
cin>>size;
cout<<"\n Enter "<<size <<" elements in the array: ";
for(i=0; i<size; i++)
cin>>array[i];
max = array[0];
min = array[0];
for(i=1; i<size; i++)
{
if(array[i] > max)
max = array[i];
if(array[i] < min)
min = array[i];
}
cout<<"\nMaximum element =" << max << "\n";
cout<<"Minimum element =" << min;
return 0;
}
c++ program to find minimum and maximum element is give above
Get Answers For Free
Most questions answered within 1 hours.