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: 3686613 • 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.

Explanation / Answer

#include<iostream>

using namespace std;

// function prototype

double average(int arr[], int n);
char grade(double score);
int largest(int x, int y, int z);

int main(){
  
   int arr[] = {78, 90, 56, 99, 88, 68, 92};
  
   double avg= average(arr, 7);
   cout<<"Avg: "<<avg<<endl;
  
   cout<<"Grade: "<<grade(avg)<<endl;
  
   cout<<"Largest: (34, 21, 45) :"<<largest(34, 21, 45)<<endl;
   return 0;
}

double average(int arr[], int n){
  
   double sum = 0;
   for(int i=0; i<n; i++)
       sum = sum + arr[i];
   return sum/n;
}
char grade(double score){
      
   if(score>=90)
       return 'A';
   else if(score >=80)
       return 'B';
   else if(score >=70)
       return 'C';
   else if(score > 58.67)
       return 'D';
   else
       return 'F';
}
int largest(int x, int y, int z){  
      
   if(x>y){
       if(x>z)
           return x;
       else return z;
   }else{
       if(y > z)
           return y;
       else
           return z;
       }
}

/*

Sample run:

Avg: 81.5714
Grade: B
Largest: (34, 21, 45) :45

*/

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