Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

..ooo Cricket 12:52 AM 27% Back MyTCC Objective: Demonstrate knowledge of the cl

ID: 3882699 • Letter: #

Question

..ooo Cricket 12:52 AM 27% Back MyTCC Objective: Demonstrate knowledge of the classic array data structure and functions by creating and compiling a simple command line program. C or C++ may be used for this Grade Table ask Programming guidelines and turn in instructions are followed 10 20 10 25 20 Program displays a welcome message when run Program makes use of the argv array for Program calculates the average of command line a Program has function to show highest input value Program has function to show lowest input value Program gracefully handles the case when no arguments are given TOTAL user input 10 125 Possble) Create a simple command line program to calculate the average, highest, and lowest values of a variable quantity of integers that are passed as an argument when the program is called. This uses the argv array from main-you should not use "scanf or cin" functions to complete this project. When the program is launched, have it display a welcome message. Also make sure to have the program display a help message if the user forgets to give any integers as the argument. Assuming valid input, the program should calculate the average of the values input and via at least two separate functions find the highest and lowest values. The below examples demonstrate the program on a Windows system. If you use a Mac or Linux your program likely will not have the exe extension which is fine. Example of calling the program with correct arguments The result of the above should be something similar to: average.exe 1 2 3456

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

int find_max(int argc, char const *argv[])
{
   int max= INT_MIN;
   for (int i=1;i<argc;i++)
   {
       if(max<atoi(argv[i]))
           max=atoi(argv[i]);
   }
   return max;

}
int find_min(int argc, char const *argv[])
{

   int min= INT_MAX;
   for (int i=1;i<argc;i++)
   {
       if(min>atoi(argv[i]))
           min=atoi(argv[i]);
   }
   return min;
  
}


int main(int argc, char const *argv[])
{
   cout<<"welcome to the Average Program. It is very average really."<<endl;
   if(argc==1)
   {
       cout<<"Usage: average x (x is 1 or more integers)"<<endl;
       exit(0);
   }
   float sum=0;
   for (int i=1;i<argc;i++)
   {
       sum+=atof(argv[i]);
   }
   cout<<"The average is: "<<sum/(argc-1)<<endl;
   cout<<"The highest value is: "<<find_max(argc,argv)<<endl;
   cout<<"The lowest value is: "<<find_min(argc,argv)<<endl;

   return 0;
}