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

Title: Functions A....Write a function that takes an array of ints, and the size

ID: 3687868 • Letter: T

Question

Title: Functions

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

A)

#include <iostream>
#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))
using namespace std;
/*Method Declarations*/
double calaverage(int arr[], int n);


double calaverage(int arr[], int n)
{
   int sum=0;double avg=0.0;
for(int i=0;i<n;i++)
{
   sum=sum+arr[i];
}
avg=sum/n;
return avg;
}

int main()
{
   double average;
int arr[]={78, 90, 56, 99, 88, 68, 92};
average=calaverage(arr,ARRAY_SIZE(arr));
cout<<"The average of the array of elements is :"<<average;
return 0;
}

_________________________________________________________________________________________

B)

#include <iostream>
using namespace std;
/*Method Declarations*/
double calgrade(double per);


double calgrade(double per)
{ char grade;
if(per>=90)
{
   grade='A';
}
else if(per>=80 && per<90)
{
   grade='B';
}
else if(per>=70 && per<80)
{
   grade='C';
}
else if(per>=59 && per<70)
{
   grade='C';
}
else if(per<=58.67)
{
   grade='F';
}
return grade;
}

int main()
{
   double per=0.0;char ch;
   cout<<"Enter percentage:";
   cin>>per;
   char grad=calgrade(per);

cout<<"The GRADE :"<<grad;
return 0;
}

___________________________________________________________________________________________

C)

#include <iostream>
using namespace std;
/*Method Declarations*/
int largest(int a,int b,int c);


int largest(int a,int b,int c)
{
int max;
if(a>b && a>c)
{
   max=a;
}
else if(b>c && b>a)
{
   max=b;
}
else
{
max=c;
}
return max;
}

int main()
{
   int a,b,c;
   cout<<"Enter a:";
   cin>>a;
  
   cout<<"Enter b:";
   cin>>b;
  
   cout<<"Enter c:";
   cin>>c;
   int max=largest(a,b,c);

cout<<"The max :"<<max;
return 0;
}

___________________________________________________________________________________________

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