Question

Write a C++ program that would report all of the Min and Max. example: 1. 95...

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;
}


Homework Answers

Answer #1
#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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
1) Create a flowchart for the program below and Trace the program below with input of...
1) Create a flowchart for the program below and Trace the program below with input of 3 and then again with input of 5. #include <iostream> using namespace std; int Fall(int x, int m) { int Xm = 1, i=x; while(i>=x-m+1) { Xm = Xm*i; i=i-1; } return Xm; } int Delta(int x, int m) { int ans = 0; ans = Fall(x+1,m); ans = ans - Fall(x,m); return ans; } void main() { int x = 0, m =...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum of the digits of n. Use the following main function to test your code: int main() { int n, sn; cout << "Enter q to quit or an integer: "; while ( cin >> n ) { sn = sumofdigits(n); cout << "sumofdigits( " << n << " ) = " << sn; cout << "\nEnter q to quit or an integer: "; }...
write a program that automates the process of generating the final student report for DC faculty...
write a program that automates the process of generating the final student report for DC faculty considering the following restrictions. Consider declaring three arrays for processing the student data: studID studName studGrade The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers. Consider the following to generate the random number: Add the libraries: #include <stdlib.h> #include <ctime>...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...