Answer to Question #207892 in C++ for Binura Thiranjaya

Question #207892

Write the code using C++,


(i) 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.

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 mimmum, maximum, total and average.

(j)   Implement the main method of a C++ program to do the followings:

1. Create 3 float arrays with the names machine A, machine B and machine C. The arrays are of size 4.

2.Insert machine A, B and C production to the respective array using the function InputProduction().

3. Print chart of all four (4) days by using the function PrintChart().

4.Print the report using the function PrintReport().


1
Expert's answer
2021-06-17T04:40:51-0400
#include <iostream>
#include <math.h>
using namespace std;
char min(float v1, float v2, float v3){
    float minimum[3] = {v1, v2, v3};
    char c[3] = {'A', 'B', 'C'};
    int pos = 0;
    float m = INT_MAX;
    for(int i = 0; i < 3; i++){
        if(minimum[i] < m) m = minimum[i];
    }
    for(int i = 0; i < 3; i++){
        if(m == minimum[i]) pos = i;
    }
    return c[pos];
}
char max(float v1, float v2, float v3){
    float maximum[3] = {v1, v2, v3};
    float m = INT_MIN;
    int pos = 0;
    for(int i = 0; i < 3; i++){
        if(maximum[i] > m) m = maximum[i];
    }
    char c[3] = {'A', 'B', 'C'};
    for(int i = 0; i < 3; i++){
        if(m == maximum[i]) pos = i;
    }
    return c[pos];
}
float tot(float v1, float v2, float v3){
    return (v1 + v2 + v3);
}
float ave(float v1, float v2, float v3){
    return (v1 + v2 + v3) / 3;
}
void PrintReport(float value1[], float value2[], float value3[], int size){
    cout<<"\nDay\tMachine A\tMachine B\tMachine C\tMinimum\tMaximum\tTotal\tAverage\n";
    for(int i = 0; i < size; i++){
        cout<<i + 1<<"\t"<<value1[i]<<"\t\t"<<value2[i]<<"\t\t"<<value3[i]<<"\t\t"<<min(value1[i], value2[i], value3[i])<<"\t";
        cout<<max(value1[i], value2[i], value3[i])<<"\t"<<tot(value1[i], value2[i], value3[i])<<"\t";
        cout<<ave(value1[i], value2[i], value3[i])<<endl;
    }
}
void PrintBar(float value){
    int c = ceil(value / 10);
    for(int i = 0; i < c; i++) cout<<"*";
}
void PrintChart(float value1[], float value2[], float value3[], int day = 1){
    for(int i = 0; i < 4; i++){
        cout<<"\nMachine Day "<<i + 1<<" production\n";
        cout<<"A"; PrintBar(value1[i]); cout<<endl;
        cout<<"B"; PrintBar(value2[i]); cout<<endl;
        cout<<"C"; PrintBar(value3[i]); cout<<endl;
    }
}
void InputProduction(float arr[4]){
    for(int i = 0; i < 4; i++) cin>>arr[i];
}
int main(){
    float MachineA[4], MachineB[4], MachineC[4];
    char c[3] = {'A', 'B', 'C'};
    cout<<"Enter production of machine "<<c[0]<<endl;
    InputProduction(MachineA);
    cout<<"Enter production of machine "<<c[1]<<endl;
    InputProduction(MachineB);
    cout<<"Enter production of machine "<<c[2]<<endl;
    InputProduction(MachineC);


    PrintChart(MachineA, MachineB, MachineC);


    PrintReport(MachineA, MachineB, MachineC, 4);


    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