Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.119.167.189
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/lmking1/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/lmking1/bgarrayfunction.cpp
// 
//  Simple Max / Min Grade Program
//
//  Now using both arrays and functions
//

#include <iostream>
#include <iomanip>
using namespace std;

const int MAXGRADES = 50;

//---------------------------------------------------------
// InputGrades gets the grades from the file into the array
//             and finds the max and min grades
//---------------------------------------------------------
// Accepts: the number of grades
// Returns: the grade array
//          the minimum grade
//          the maximum grade
//---------------------------------------------------------

void InputGrades (int grades[],
                  int numgrades,
                  int& mingrade,
                  int& maxgrade)
{
   for (int i = 0; i < numgrades; i++)
   {
      cin >> grades[i];

      if (grades[i] < mingrade)
         mingrade = grades[i];
      if (grades[i] > maxgrade)
         maxgrade = grades[i];
   }
}

//---------------------------------------------------------
// ProduceReport uses the grade array, max and min grades 
//               to produce the grade summary report
//---------------------------------------------------------
// Accepts: the number of grades
//          the grade array
//          the minimum grade
//          the maximum grade
// Returns: nothing
//---------------------------------------------------------

void ProduceReport (int grades[],
                    int numgrades,
                    int mingrade,
                    int maxgrade)
{
   cout << "\n    Grades";
   cout << "\n    ------\n\n";

   for (int i = 0; i < numgrades; i++)
   {
      cout << setw(8) << grades[i];

      if (grades[i] == mingrade)
         cout << " ** Lowest Grade\n";
      else if (grades[i] == maxgrade)
         cout << " ** Highest Grade\n";
      else
         cout << "\n";
   }
}

//---------------------------------------------------------
// main function
//---------------------------------------------------------

int main ()
{

// ---- Variables

int grades[MAXGRADES],// grades to be input
    numgrades,        // number of grades
    mingrade = 500,   // lowest grade
    maxgrade = 0,     // highest grade
    i;                // for loop counter

// Get the actual number of grades first

cin >> numgrades;

// First input the grades and find max/min

InputGrades (grades, numgrades, mingrade, maxgrade);

// Then produce the report

ProduceReport (grades, numgrades, mingrade, maxgrade);

cout << "\n\n"; 
return 0;

}

Stv3n404 - 2023