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

A. Write a function that takes an array of ints, and the size of the array – ano

ID: 3686699 • Letter: A

Question

A. Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} B. Write a function that takes one double parameter, and returns a char. The parameter represents a grade, and the char represents the corresponding letter grade. If you pass in 90, the char returned will be ‘A’. If you pass in 58.67, the char returned will be an ‘F’ etc. Use the grading scheme on the syllabus for this course to decide what letter to return. C. Write a function that takes 3 int arguments and returns the largest of the 3. (3 different codes)

Explanation / Answer

a)/**C++ program that demonstrate the method average and
print the average of array to console*/

//averageprogram.cpp
#include<iostream>
using namespace std;
double average(int values[], int size);
int main()
{
  
   //declare a constant value
   const int SIZE=7;
   //declare an array of type integer
   int values[]= {78, 90, 56, 99, 88, 68, 92};

   //call method
   cout<<"Average of array values :"<<average(values,SIZE)<<endl;

   system("pause");
   return 0;

}

/**The method average that takes an array of type integer
and an integer value and returns the average of values in
the array,*/
double average(int values[], int SIZE)
{

   //intialize the total =0
   double total=0;
   //for loop to find the sum of values in the array
   for(int index=0;index<SIZE;index++)
       total+=values[index];

   //calcualte average
   double avg=total/SIZE;
   //return avg to calling function
   return avg;
}

-------------------------------------------------------------------------------
b)

//grade.cpp

/**C++ program that demonstrate the method getgradeLetter and
print the grade letter to console*/
#include<iostream>
using namespace std;
//function prototype
char getgradeLetter(double grademarks);
int main()
{
  
   //Set grademarks
   double grademarks=90;
   //call method
   cout<<"Grade :"<<getgradeLetter(grademarks)<<endl;

   system("pause");
   return 0;

}
/**The method getgradeLetter that takes grademarks
and returns the correponding grade letter.*/
char getgradeLetter(double grademarks)
{
  
   if(grademarks>=90)
       //return A if grademarks >=90
       return 'A';
   else if(grademarks>=80)
       //return B if grademarks >=80
       return 'B';
   else if(grademarks>=70)
       //return C if grademarks >=70
       return 'C';
   else if(grademarks>=60)
       //return D if grademarks >=60
       return 'D';
   else if(grademarks>=50)
       //return E if grademarks >=50
       return 'E';
   else
       //return F if grademarks <50
       return 'F';
}

-------------------------------------------------------------------------------------
c)

//largestprogram.cpp
/**C++ program that demonstrate the method largest and
print the largest of three numbers to console*/
#include<iostream>
using namespace std;
//function prototype
int largest(int a,int b,int c);
int main()
{
  
   int a=10;
   int b=8;
   int c=6;
   //call method largest
   cout<<"Largest :"<<largest(a,b,c)<<endl;

   system("pause");
   return 0;

}

/**The method largest that takes three integer variables a, b and c
and returns largest of three integer values*/
int largest(int a,int b,int c)
{

   //Check if a greater than b and a greater than c
   if(a>b && a>c)
       //return a
       return a;
   //Check if b greater than a and b greater than c
   else if(b>a && b>c)
       return b;
   else
       //otherwise return c
       return c;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote