Answer to Question #260131 in C++ for Akmal

Question #260131

Write a function using C++ statements called MeanProduction () which takes three integer arrays

(array1, array2, array3) and an integer as the size of the arrays as parameters. The array1 holds Outlet

1 production and array2 holds Outlet 2 production. The function calculates the average of each

product using the findMean (value1, value2) function and stored in the array 3.

Example

Consider the sample values of array1 and array2

array1 (Outlet 1)

array2 (Outlet 2).

Array index

Product Quantity

Array index Product Quantity

O

30

O

20

25

20

2

30

2

50

3

46

3

40

After calling the function MeanProduction (), array3 contains the average of each day.

Array index

O

1

2

3

array3

Average Quantity

25

22.5

40

43


1
Expert's answer
2021-11-02T17:36:21-0400


#include <iostream>


using namespace std;


int findMean (int value1, int value2){
    return (value1+ value2)/2;
}
void MeanProduction (int array1[],int array2[],int array3[],int size){
    for(int i=0;i<size;i++){
        array3[i]=findMean(array1[i],array2[i]);
    }
    cout<<"\nOutlet 1\tOutlet 2\tMean\n";
    for(int i=0;i<size;i++){
        cout<<array1[i]<<"\t"<<array2[i]<<"\t"<<array3[i]<<endl;
    }
}


int main()
{
    int size;
    cout<<"\nEnter number of elements in the arrays: ";
    cin>>size;
    
    int array1[size];
    int array2[size];
    int array3[size];
    cout<<"\nEnter elements for array 1: ";
    for(int i=0;i<size;i++){
        cin>>array1[i];
    }
    cout<<"\nEnter elements for array 2: ";
    for(int i=0;i<size;i++){
        cin>>array2[i];
    }
    
    MeanProduction(array1,array2,array3,size);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS