Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C++ Visual Studio Goals: Developing problem-solving skills, using functions

ID: 3601152 • Letter: U

Question

Use C++ Visual Studio

Goals: Developing problem-solving skills, using functions

Problem: The company, HeatTransfer, for which your analyzed data in Lab 5 is developing 8 new formulations to use for their widgets. To ensure that the formulations produce similar results when they are prepared by 6 plants in different locations, the company has asked each of the six plants to prepare each formulation and measure the thermal conductivity of the different formulations. 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 thermal conductivity is between 3 and 10 inclusive. This function should accept the thermal conductivity to be checked and the plant number that measured this thermal conductivity and prompt the user to re-enter the thermal conductivity for that plant until a valid value is entered. This function should return a valid value to the function call.

One function should accept all 6 thermal conductivities (one for each of the plants) for a specific formulation at one time and send back to function call the highest and lowest of the 6 thermal conductivities to the function call.

One function should accept all the thermal conductivities of a specific formulation and calculate the average of the thermal conductivities for that formulation without the highest and lowest thermal conductivity. This function should call the function to determine the lowest and highest thermal conductivity 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 thermal conductivity 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 8 formulations. The main function should output the average for each formulation to two decimal places.

Sample output is given below for first 2 formulations (your code should work for all 8).

Do not use any concepts beyond Chapter 6 (e.g. do not use arrays) to complete this project. Make sure that you have included your introductory comments containing the purpose of the program i.e. what problem or task is being solved plus the input needed from user to complete the problem/task, output expected from the program, and the processing needed to get the output from the input. The description of the purpose should be detailed enough

Programming Project 2 1 CMPSC 201 – Fall 2016

that a person reading your code would not need any additional information to understand the problem. The processing comments should not include any C++ commands.

Enter the information for formulation 1. Enter the thermal conductivity for formulation 1 from plant 1 in W/mK 7 Enter the thermal conductivity for formulation 1 from plant 2 in W/mK 3.18 Enter the thermal conductivity for formulation 1 from plant 3 in W/mK 9.'9 Enter the thermal conductivity for formulation 1 from plant 4 in W/mK 5.3 Enter the thermal conductivity for formulation 1 from plant 5 in W/mK 8.7 Enter the thermal conductivity for formulation 1 from plant 6 in W/mK 9.5 The average thermal conductivity for formulation 1 was 7.63 W/mK. Enter the information for formulation 2 Enter the thermal conductivity for formulation 2 from plant 1 in W/mK 2.5 The thermal conductivity should be between 3 and 10 W/mK inclusive! Enter the thermal conductivity from plant 1 3.8 Enter the thermal conductivity for formulation 2 from plant 2 in W/mK 8 Enter the thermal conductivity for formulation 2 from plant 3 in W/mK 11 The thermal conductivity should be between 3 and 10 W/mK inclusive! Enter the thermal conductivity from plant 3 10.5 The thermal conductivity should be between 3 and 10 W/mK inclusive! Enter the thermal conductivity from plant 3 9.2 Enter the thermal conductivity for formulation 2 from plant 4 in W/mK 5.3 Enter the thermal conductivity for formulation 2 from plant 5 in W/mK 6.18 Enter the thermal conductivity for formulation 2 from plant 6 in W/mK 7.!9 The average thermal conductivity for formulation 2 was 7.00 W/mK

Explanation / Answer

the required code is as below :

----------------------------------------------------------------------------------------------------------------------------

#include <iostream>


/* function to calculate max val */
double maxVal((double t1, double t2, double t3, double t4, double t5, double t6){
    if(t1 > t2 && t1>t3 && t1>t4 && t1>t5 && t1>t6) /* if t1 is greater among all return t1 */
    return t1;
else if (t2 > t1 && t2>t3 && t2>t4 && t2>t5 && 21>t6)/* if t1 is greater among all return t2 */
    return t2;
else if (t3 > t1 && t3>t2 && t3>t4 && t3>t5 && t3>t6)/* if t1 is greater among all return t3 */
    return t3;
else if (t4 > t1 && t4>t2 && t4>t3 && t4>t5 && t4>t6)/* if t1 is greater among all return t4 */
    return t4;
else if (t5 > t2 && t5>t3 && t5>t4 && t5>t1 && t5>t6)/* if t1 is greater among all return t5 */
    return t5;
else/* if t1 is greater among all return t6 */
    return t6;
}

double minVal(double t1, double t2, double t3, double t4, double t5, double t6){
if(t1 < t2 && t1<t3 && t1<t4 && t1<t5 && t1<t6)/* if t1 is lesser among all return t1 */
    return t1;
else if (t2 < t1 && t2<t3 && t2<t4 && t2<t5 && t2<t6)/* if t1 is lesser among all return t2 */
    return t2;
else if (t3 < t1 && t3<t2 && t3<t4 && t3<t5 && t3<t6)/* if t1 is lesser among all return t3 */
    return t3;
else if (t4 < t1 && t4<t2 && t4<t3 && t4<t5 && t4<t6)/* if t1 is lesser among all return t4 */
    return t4;
else if (t5 < t2 && t5<t3 && t5<t4 && t5<t1 && t5<t6)/* if t1 is lesser among all return t5 */
    return t5;
else/* if t1 is lesser among all return t6 */
    return t6;
}

bool checkVal( double num ){
if(num >=3 && num <=10)/* if num doesn't lie between 3 and 10 return false */
    return true;
else
    return false;
}

/* calculates the average */
double avg(double t1, double t2, double t3, double t4, double t5, double t6){
double sum = t1 + t2 + t3 + t4 + t5 + t6;
double max = maxVal(t1,t2,t3,t4,t5,t6);
double min = minVal(t1,t2,t3,t4,t5,t6);
return (sum - max - min)/4;
}

int main(){
int i =0;
while (i<8){
    double t1,t2,t3,t4,t5,t6;
    std :: cout << " Enter the information for formulation " << i+1;
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 1 in W/mK";
    std :: cin >> t1;
    while( !checkVal(t1) ){ /* reads t1 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t1;
    }
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 2 in W/mK";
    std :: cin >> t2;
    while( !checkVal(t2) ){/* reads t2 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t2;
    }
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 3 in W/mK";
    std :: cin >> t3;
    while( !checkVal(t3) ){/* reads t3 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t3;
    }
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 4 in W/mK";
    std :: cin >> t4;
    while( !checkVal(t4) ){/* reads t4 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t4;
    }
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 5 in W/mK";
    std :: cin >> t5;
    while( !checkVal(t5) ){/* reads t5 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t5;
    }
    std :: cout << " Enter the thermal conductivity for formulation "<<i+1<< " from plant 6 in W/mK";
    std :: cin >> t6;
    while( !checkVal(t6) ){/* reads t6 until it is valid */
      std :: cout << " the thermal conductivity should be between 3 and 10 inclusive!";
      std :: cin >> t6;
    }
    std :: cout << " The average thermal conductivity for formulation "<<i+1 <<" is" << avg(t1,t2,t3,t4,t5,t6);
    i = i + 1; /* loop control variable */
}
return 0;
}


------------------------------------------------------------------------------------------------------------------

/* hope this helps */

/* ifa ny queries please comment */

/* thank you */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote