Write a function using C++ statements called PrintReport() which takes three float arrays (valuel, value2, value3) and an integer (as the size of the array) as parameters. The method prints the report as given below.
Sample Output:
Day Machine A Machine B Machine C Minimum Maximum Total Average
1 15.5 50 35.5 A B 101 33.66
2 25.5 45.5 65 A C 136 45.33
3 27.5 25.5 71 B C 124 41.33
4 60.5 18 74.5 B C 153 51
Note: Should use functions already defined to find minimum, maximum, total and average.
#include<iostream>
using namespace std;
char MaximumMachine(float value1, float value2, float value3){
char x;
if(value1>value2 && value1 >value3){
x= 'A';
}
else if(value2>value1 && value2>value3){
x ='B';
}
else if(value3>value1 && value3>value2){
x ='C';
}
return x;
}
char MinimumMachine(float value1, float value2, float value3){
char x;
if(value1<value2 && value1 <value3){
x= 'A';
}
else if(value2<value1 && value2<value3){
x ='B';
}
else if(value3<value1 && value3<value2){
x ='C';
}
return x;
}
float total(float arr[], int N){
int i;
float sum =0.0;
for( i<0; i<N; i++){
sum += arr[i];
}
return sum;
}
double average(float arr[] , int N){
double sum = 0.0;
int i;
for( i<0; i<N; i++){
sum += arr[i];
}
return sum/N;
}//Answer to the question
void PrintReport(float arr[] , int N){
cout<<"Day\tMachine A\t Machine B\t Machine C\t Minimum\t Maximum\t Total\t Average\n";
cout<<1<<"\t"<<arr[0]<<"\t\t"<<arr[1]<<"\t\t"<<arr[2]<<"\t\t"<<MinimumMachine(arr[0],arr[1], arr[2])<<"\t\t";
cout<<MaximumMachine(arr[0],arr[1], arr[2])<<"\t\t"<<total(arr,3)<<"\t";
cout<<average(arr,3)<<"\t";
}
//Main() function to test the PrintReport() function
int main(){
float arr[3] = { 15.5,50,35.5};
PrintReport(arr, 3);
}
Comments
Leave a comment