C++ PROGRAMMING
The "TRC Institute" records and monitors performance of three (3) machines over a period of four (4) days (l to 4) as shown in the Table 1, 2 and 3 respectively. The production ranges between 15.5 and 75.5
Table 1- Machine "A" Production
Day 1 2 3 4
Array index 0 1 2 3
Production 15.5 25.5 27.5 60.5
Table 2- Machine "B" Production
Day 1 2 3 4
Array index 0 1 2 3
Production 50 45.5 25.5 18
Table 3- Machine "C" Production
Day 1 2 3 4
Array index 1 2 3 4
Production 35.5 65 71 74.5
1) Write a function using C++ statements called GetProduction() which takes a float array and an integer (as the day) as parameters. The function returns the production of that day.
#include <iostream>
using namespace std;
float getProduction(float *array, int day){
if(day < 1 || day > 4) return 0;
return array[day - 1];
}
int main(){
float machineAproduction[4] = {15.5, 25.5, 27.5, 60.5},
machineBproduction[4] = {50, 45.5, 25.5, 18},
machineCproduction[4] = {35.5, 65, 71, 74.5},
totalProduction[4];
for(int i = 0; i < 4; i++)
totalProduction[i] = machineAproduction[i] + machineBproduction[i] + machineCproduction[i];
cout<<"\nEnter day to get production: ";
int x; cin>>x;
cout<<getProduction(totalProduction, x);
return 0;
}
Comments
Leave a comment