Use C A concrete manufacturing company is developing five ne
(Use C++) A concrete manufacturing company is developing five new formulations to use for
highways. To ensure that the formulations produce similar results when they are prepared by
plants in different locations, the company has asked each of the seven plants to prepare each
formulation and measure the compressive strength after 180 days of curing. You have been asked to develop a program to help analyze the data. Your program should have a main function
and 3 other functions as described below.
One function should confirm that the entered value for compressive strength is between 15 and
75 MPa inclusive. This function should accept the compressive strength to be checked and the
plant number that measured this strength and prompt the user to re-enter the compressive
strength for that plant until a valid value is entered. This function should return a valid value to
the function call.
One function should accept the 7 compressive strengths from a plant and send back to function
the highest and lowest of the 7 compressive strengths to the function call.
One function should accept the 7 compressive strengths of a specific formulation and calculate
the average of the strengths for that formulation without the highest and lowest strength. This
function should call the function to determine the lowest and highest compressive strength for a
plant, then calculate the average. The average should be returned to the function call.
The main function should prompt the user to enter the compressive strength for a formulation
from each plant one at a time and call the function to ensure the entered value was valid . Next
main should call the function to calculate the average of the values from the plants. This process
should be repeated for each of the 5 formulations. The main function should output the average
for each formulation to two decimal places.
Sample output is given below.
Do not use any concepts beyond Chapter 6 (e.g. do not use arrays)
Sample output
Enter the information for formulation 1.
Enter the compressive strength for formulation 1 in MPa from plant 1 26
Enter the compressive strength for formulation 1 in MPa from plant 2 28.4
Enter the compressive strength for formulation 1 in MPa from plant 3 45.6
Enter the compressive strength for formulation 1 in MPa from plant 4 20.4
Enter the compressive strength for formulation 1 in MPa from plant 5 36.2
Enter the compressive strength for formulation 1 in MPa from plant 6 29.1
Enter the compressive strength for formulation 1 in MPa from plant 7 18
The average strength for formulation 1 was 28.02.
Enter the information for formulation 2.
Enter the compressive strength for formulation 2 in MPa from plant 1 10
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 1 90
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 1 61.1
Enter the compressive strength for formulation 2 in MPa from plant 2 62.2
Enter the compressive strength for formulation 2 in MPa from plant 3 83.3
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 3 63.3
Enter the compressive strength for formulation 2 in MPa from plant 4 61.4
Enter the compressive strength for formulation 2 in MPa from plant 5 15.5
Enter the compressive strength for formulation 2 in MPa from plant 6 13.6
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 6 62.6
Enter the compressive strength for formulation 2 in MPa from plant 7 84.75
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 7 64.75
The average strength for formulation 2 was 62.12.
Enter the information for formulation 3.
Enter the compressive strength for formulation 3 in MPa from plant 1 72.56
Enter the compressive strength for formulation 3 in MPa from plant 2 13.98
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 2 63.98
Enter the compressive strength for formulation 3 in MPa from plant 3 68.34
Enter the compressive strength for formulation 3 in MPa from plant 4 88.78
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 4 58.78
Enter the compressive strength for formulation 3 in MPa from plant 5 76.4
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 5 74.6
Enter the compressive strength for formulation 3 in MPa from plant 6 72.99
Enter the compressive strength for formulation 3 in MPa from plant 7 66.66
The average strength for formulation 3 was 68.91.
Enter the information for formulation 4.
Enter the compressive strength for formulation 4 in MPa from plant 1 38
Enter the compressive strength for formulation 4 in MPa from plant 2 44
Enter the compressive strength for formulation 4 in MPa from plant 3 50
Enter the compressive strength for formulation 4 in MPa from plant 4 48
Enter the compressive strength for formulation 4 in MPa from plant 5 42
Enter the compressive strength for formulation 4 in MPa from plant 6 40
Enter the compressive strength for formulation 4 in MPa from plant 7 46
The average strength for formulation 4 was 44.00.
Enter the information for formulation 5.
Enter the compressive strength for formulation 5 in MPa from plant 1 39.2
Enter the compressive strength for formulation 5 in MPa from plant 2 46.8
Enter the compressive strength for formulation 5 in MPa from plant 3 43.67
Enter the compressive strength for formulation 5 in MPa from plant 4 41.88
Enter the compressive strength for formulation 5 in MPa from plant 5 50.65
Enter the compressive strength for formulation 5 in MPa from plant 6 49.78
Enter the compressive strength for formulation 5 in MPa from plant 7 54,78
The average strength for formulation 5 was 46.56.
Press any key to continue . . .
Solution
Please follow the code and comments for description :
CODE :
#include <iostream> // required header files
using namespace std;
double validateStrengths (double value, int plant); // function declarations
void maxMin (double val1, double val2, double val3, double val4, double val5, double val6, double val7, double &max, double &min);
double avg (double val1, double val2, double val3, double val4, double val5, double val6, double val7);
double validateStrengths (double value, int plant) { // function to return the valid data
bool validData = false;
double val = value;
while(validData == false) {
if(val >= 15 && val <= 75) {
validData = true;
} else {
cout << \"The compressive strength should be between 15 and 75 MPa!\" << endl;
cout << \"Enter the strength from plant \" << plant << \" : \";
cin >> val;
}
}
return value;
}
void maxMin (double val1, double val2, double val3, double val4, double val5, double val6, double val7, double &max, double &min) { // function to return the max and min values
max = 0;
min = 0;
if((val1 > val2) && (val1 > val3) && (val1 > val4) && (val1 > val5) && (val1 > val6) && (val1 > val7)) {
max = val1;
} else if ((val2 > val1) && (val2 > val3) && (val2 > val4) && (val2 > val5) && (val2 > val6) && (val2 > val7)) {
max = val2;
} else if ((val3 > val1) && (val3 > val2) && (val3 > val4) && (val3 > val5) && (val3 > val6) && (val3 > val7)) {
max = val3;
} else if ((val4 > val1) && (val4 > val2) && (val4 > val3) && (val4 > val5) && (val4 > val6) && (val4 > val7)) {
max = val4;
} else if ((val5 > val1) && (val5 > val2) && (val5 > val3) && (val5 > val4) && (val5 > val6) && (val5 > val7)) {
max = val5;
} else if ((val6 > val1) && (val6 > val2) && (val6 > val3) && (val6 > val4) && (val6 > val5) && (val6 > val7)) {
max = val6;
} else if ((val7 > val1) && (val7 > val3) && (val7 > val4) && (val7 > val5) && (val7 > val6) && (val7 > val2)) {
max = val7;
}
if((val1 < val2) && (val1 < val3) && (val1 < val4) && (val1 < val5) && (val1 < val6) && (val1 < val7)) {
min = val1;
} else if ((val2 < val1) && (val2 < val3) && (val2 < val4) && (val2 < val5) && (val2 < val6) && (val2 < val7)) {
min = val2;
} else if ((val3 < val1) && (val3 < val2) && (val3 < val4) && (val3 < val5) && (val3 < val6) && (val3 < val7)) {
min = val3;
} else if ((val4 < val1) && (val4 < val2) && (val4 < val3) && (val4 < val5) && (val4 < val6) && (val4 < val7)) {
min = val4;
} else if ((val5 < val1) && (val5 < val2) && (val5 < val3) && (val5 < val4) && (val5 < val6) && (val5 < val7)) {
min = val5;
} else if ((val6 < val1) && (val6 < val2) && (val6 < val3) && (val6 < val4) && (val6 < val5) && (val6 < val7)) {
min = val6;
} else if ((val7 < val1) && (val7 < val3) && (val7 < val4) && (val7 < val5) && (val7 < val6) && (val7 < val2)) {
min = val7;
}
}
double avg (double val1, double val2, double val3, double val4, double val5, double val6, double val7) { // function to return the average value
double max = 0, min = 0, sum, average;
maxMin (val1, val2, val3, val4, val5, val6, val7, max, min); // call the maxMin function
sum = (val1 + val2 + val3 + val4 + val5 + val6 + val7);
average = (sum - (max + min)) / 5;
return average;
}
int main() { // driver method
double value, value1 = 0, avgVal = 0, value2 = 0, value3 = 0, value4 = 0, value5 = 0, value6 = 0, value7 = 0; // local variables
for(int i = 1; i <= 5; i++) { // iterate over the loop
cout << \"\ Enter the information for formulation \" << i << \".\" << endl; // prompt for the data
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 1 : \";
cin >> value;
value1 = validateStrengths (value, 1); // check the input
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 2 : \";
cin >> value;
value2 = validateStrengths (value, 2);
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 3 : \";
cin >> value;
value3 = validateStrengths (value, 3);
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 4 : \";
cin >> value;
value4 = validateStrengths (value, 4);
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 5 : \";
cin >> value;
value5 = validateStrengths (value, 5);
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 6 : \";
cin >> value;
value6 = validateStrengths (value, 6);
cout << \"Enter the compressive strength for formulation \" << i << \" in MPa from plant 7 : \";
cin >> value;
value7 = validateStrengths (value, 7);
avgVal = avg (value1, value2, value3, value4, value5, value6, value7); // call the avg function to get the average value
cout << \"The average strength for formulation \" << i << \" was : \" << avgVal << endl; // print the data to console
}
return 0;
}
OUTPUT :
Enter the information for formulation 1.
Enter the compressive strength for formulation 1 in MPa from plant 1 : 15
Enter the compressive strength for formulation 1 in MPa from plant 2 : 20
Enter the compressive strength for formulation 1 in MPa from plant 3 : 25
Enter the compressive strength for formulation 1 in MPa from plant 4 : 30
Enter the compressive strength for formulation 1 in MPa from plant 5 : 35
Enter the compressive strength for formulation 1 in MPa from plant 6 : 40
Enter the compressive strength for formulation 1 in MPa from plant 7 : 45
The average strength for formulation 1 was : 30
Enter the information for formulation 2.
Enter the compressive strength for formulation 2 in MPa from plant 1 : 16
Enter the compressive strength for formulation 2 in MPa from plant 2 : 30.2
Enter the compressive strength for formulation 2 in MPa from plant 3 : 20.5
Enter the compressive strength for formulation 2 in MPa from plant 4 : 45.3
Enter the compressive strength for formulation 2 in MPa from plant 5 : 55.2
Enter the compressive strength for formulation 2 in MPa from plant 6 : 65.3
Enter the compressive strength for formulation 2 in MPa from plant 7 : 75
The average strength for formulation 2 was : 43.3
Enter the information for formulation 3.
Enter the compressive strength for formulation 3 in MPa from plant 1 72.56
Enter the compressive strength for formulation 3 in MPa from plant 2 13.98
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 2 63.98
Enter the compressive strength for formulation 3 in MPa from plant 3 68.34
Enter the compressive strength for formulation 3 in MPa from plant 4 88.78
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 4 58.78
Enter the compressive strength for formulation 3 in MPa from plant 5 76.4
The compressive strength should be between 15 and 75 MPa!
Enter the strength from plant 5 74.6
Enter the compressive strength for formulation 3 in MPa from plant 6 72.99
Enter the compressive strength for formulation 3 in MPa from plant 7 66.66
The average strength for formulation 3 was 68.91.
Enter the information for formulation 4.
Enter the compressive strength for formulation 4 in MPa from plant 1 38
Enter the compressive strength for formulation 4 in MPa from plant 2 44
Enter the compressive strength for formulation 4 in MPa from plant 3 50
Enter the compressive strength for formulation 4 in MPa from plant 4 48
Enter the compressive strength for formulation 4 in MPa from plant 5 42
Enter the compressive strength for formulation 4 in MPa from plant 6 40
Enter the compressive strength for formulation 4 in MPa from plant 7 46
The average strength for formulation 4 was 44.00.
Enter the information for formulation 5.
Enter the compressive strength for formulation 5 in MPa from plant 1 39.2
Enter the compressive strength for formulation 5 in MPa from plant 2 46.8
Enter the compressive strength for formulation 5 in MPa from plant 3 43.67
Enter the compressive strength for formulation 5 in MPa from plant 4 41.88
Enter the compressive strength for formulation 5 in MPa from plant 5 50.65
Enter the compressive strength for formulation 5 in MPa from plant 6 49.78
Enter the compressive strength for formulation 5 in MPa from plant 7 54,78
The average strength for formulation 5 was 46.56.
Hope this is helpful.




