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

C++ Question 1.Create a function that will receive an array of the type doubles

ID: 3683376 • Letter: C

Question

C++ Question

1.Create a function that will receive an array of the type doubles and a number of items in the array.

(The function should assign zeros to all of the locations.)

_______________________________________

2. Write another function that passes an array that and returns the total of all the whole array.

(The function’s parameter list should receive an array of doubles and the number of elements in the array.)

_______________________________________

3. Write another function that passes an array that and returns the largest value in the array.

(The function’s parameter list should receive an array of doubles and the number of elements in the array.)

Explanation / Answer

#include<iostream>

using namespace std;

void initialize(double [], int);
double getTotal(double [], int);
double getLargest(double [], int);

int main(){

   int n;
   cout<<"Enter size of array: ";
   cin>>n;
  
   double arr[n];
  
   //initializing with zero
   initialize(arr, n);
  
   cout<<"Enter n values: ";
   for(int i=0; i<n; i++)
       cin>>arr[i];
      
   // getting total
   double total = getTotal(arr, n);
   cout<<"Total : "<<total<<endl;
  
   // getting largest value
   double large = getLargest(arr, n);
   cout<<"Largest: "<<large<<endl;
   return 0;
}

void initialize(double arr[], int n){
   for(int i=0; i<n; i++)
       arr[i] = 0;
}

double getTotal(double arr[], int n){
   double total = 0;
   for(int i=0; i<n; i++)
       total += arr[i];
   return total;
}

double getLargest(double arr[], int n){
   double max = arr[0];
   for(int i=1; i<n; i++){
       if(arr[i] > max)
           max = arr[i];
   }
      
   return max;
}

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