Question

Write a C++ program to solve:

DISCUSSION: Your program will ultimately need to determine overall savings (in dollars) for each thickness. The savings is foThe only two quantities that are not constant in our problem are the insulation thickness and the air temperature (Tair). For

The completed program should include the following:

—Program input and output
—Allow the user to input the starting, stopping and increment values for the insulation thickness and the air temperature. Also, at the end of the program, provide an opportunity for the user to use the program again without having to re-execute the program (ie. Ask them if they want to use the program again).
—your program must find and output the value of the optimum thickness for each air temperature (you must have the program sort through the savings column for each air temperature and find the maximum value). Also, you must store the values you calculate for CF, CI, and overall savings in an array(s). You may store additional values in array(s) as well if you’d like.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*Following program contains all the required functions. All of them are self explainatory, Comments have been added at relevent lines for better understanding. Still if there is any doubt, feel free to ask in the comment section. Hope it helps :)*/

#include <bits/stdc++.h>

using namespace std;

// printTable function to print the output.
void printTable(double Ts, double Ti, vector<double> &maxSavings,
vector<double> &CFs, vector<double> &CIs, vector<double> &thickness) {
  
cout << "Temperatue Thickness CF CI Savings" << endl;
  
for(int i = 0; i < maxSavings.size(); i++) {
cout << (Ts + Ti*i) << " " << (thickness[i] * 100) << "cm $" << CFs[i];
cout << " $" << CIs[i] << " $" << maxSavings[i] << endl;
}
  
}

//CalculateCost function to find the savings at all the Temperatue and thicknesses and store them in an array.
void CalculateCost(double Ts, double Te, double Ti, double ts, double te, double ti) {
  
// set values to all the given constants
double a = 0.05;
double L = 100;
double Ta = 150;
double k = 0.1;
double F = 3.0;
double Cvol = 325;
double Cl = 1.50;
double Cstheat = 1.11 * pow(10, -9);
  
// convert thickness from cm to m.
ts = ts * 0.01;
te = te * 0.01;
ti = ti * 0.01;
  
// create vectors(dynamic arrays, functions same as that of arrays, but thier size is not fixed)
// (Size of vector increases as the requirement increases)
// these vectors store the optimal value of Savings, CIs, CFs at every Temperatue.
double Tair = Ts;
vector<double> maxSavings;
vector<double> CFs;
vector<double> CIs;
vector<double> thickness;
while(Tair <= Te) {
// these vectors store the optimal value of Savings, CIs, CFs at every Thickness.
vector<double> Savings;
vector<double> CF1s;
vector<double> CI1s;
  
double t = ts;
while(t <= te) {
double b = a + t;
double CI = (b*b - a*a)*L*Cvol + L*Cl;
double Q3 = 2*3.14*a*F*(Ta - Tair)*L;
double dQ = Q3*(1 - (b/a)/(1 + (b*F/k)*log(b/a)));
double CF = dQ*(1.578*pow(10, 8))*Cstheat;
CI1s.push_back(CI);
CF1s.push_back(CF);
Savings.push_back(CF - CI);
t = t + ti;
}
  
// we find the max saving from all the thicknesses of pipe available
double max = -9999999;
double max_index = -1;
for(int i = 0; i < Savings.size(); i++) {
double diff = CF1s[i] - CI1s[i];
Savings[i] = diff;
if(diff > max) {
max = diff;
max_index = i;
}
}
  
// We put the max values in the Temperatue vectors.
maxSavings.push_back(Savings[max_index]);
CFs.push_back(CF1s[max_index]);
CIs.push_back(CI1s[max_index]);
thickness.push_back(ts + ti*(max_index));
Tair = Tair + Ti;
}
  
// prints the table.
printTable(Ts, Ti, maxSavings, CFs, CIs, thickness);
}

int main()
{
// ask the user what to do ?
while(1) {
cout<<"Do you wish to use the system ? (1)Yes (2)No : ";
int choice;
cin >> choice;
if(choice == 1) {
// take input
double Ts, Te, Ti;
double ts, te, ti;
cout << "Enter starting, ending and incremental value for the Temperatue(C): " << endl;
cin >> Ts;
cin >> Te;
cin >> Ti;
cout << "Enter starting, ending and incremental value for the Thickness(cm): " << endl;
cin >> ts;
cin >> te;
cin >> ti;
// call the function
CalculateCost(Ts, Te, Ti, ts, te, ti);
} else if(choice == 2) {
// terminate program
cout << "Program Treminated. Have a nice day!" << endl;
break;
} else {
cout << "Invalid Choice." << endl;
}
}

return 0;
}

Sample Output:-

Do you wish to use the system ? (1) Yes (2) No : 1 Enter starting, ending and incremental value for the Temperatue (C): -20 2

For Indentation:-

#include <bits/stdc++.h> using namespace std; // printTable function to print the output. void printTable double Ts, double T

Il convert thickness from cm to m. ts = ts * 0.01; te = te * 0.01; ti = ti * 0.01; // create vectors (dynamic arrays, functio

// we find the max saving from all the thicknesses of pipe available double max = -9999999; double max_index = -1; for(int i

int main() // ask the user what to do ? while(1) { cout<<Do you wish to use the system ? (1) Yes (2)No : ; int choice; cin

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to solve: The completed program should include the following: —Program input and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *Using C++ (no printf command)* So, this is a basic cost vs. benefit problem.  For different...

    *Using C++ (no printf command)* So, this is a basic cost vs. benefit problem.  For different thicknesses of insulation, we will need to calculate the cost of purchasing and installing that thickness of insulation and compare that to the fuel savings generated by insulating the pipe with that thickness. DISCUSSION:  Your program will ultimately need to determine overall savings (in dollars) for each thickness and then find the thickness that corresponds to the largest overall savings. The overall savings is...

  • C Programming QUESTION 9 Write a program that prompts for and reads four integer input values,...

    C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...

  • 1. A ¾ inch (nominal), Schedule 40, mild steel pipe carries 40 psia steam through a...

    1. A ¾ inch (nominal), Schedule 40, mild steel pipe carries 40 psia steam through a room having an air temperature of 80°F. The pipe is covered with a 0.125 ft thick layer of fiberglass insulation having a thermal conductivity of 0.037 Btu/(h ft ‘F). The hi value on the steam side of the pipe is 1000 Btu/h ft2 °F. The ho value on the outside of the insulation is 2.0 Btu/(h ft2 ’F). For the mild steel, k=26Btu/(ft H...

  • you are going to write a program, fastfactor, to find all the inegral factors of a...

    you are going to write a program, fastfactor, to find all the inegral factors of a number (integer). the program must be written in C. note that in C (as in most languages) % is a remainder operator, so if x % 3 == 0 that means 3 is a factor of x. you are going to write fastfactor to work like a "standard" UNIX command: the user can invoke the command like fastfactor 12 13 which would output 12:...

  • Please help with the following problem and show work thank you 2. (40 pts) A simple...

    Please help with the following problem and show work thank you 2. (40 pts) A simple cross-flow heat exchanger consists of a thin-walled copper pipe that carries cold water and is exposed to side flow of hot air. You can neglect entry length effects. a) (10 pts) What is the heat transfer coefficient on the air side? b) (10 pts) What is the heat transfer coefficient on the liquid side? c) (5 pts) What is the overall heat transfer coefficient...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • Write a C++ program that calculates the discount of the original price of an item and...

    Write a C++ program that calculates the discount of the original price of an item and displays the new price, and the total amount of savings. This program should have a separate header (discount.h), implementation (discount.cpp) and application files (main.cpp). The program must also have user input: the user must be prompted to enter data (the original price, and the percent off as a percentage). There must also be a validation, for example: Output: “Enter the original price of the...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • NOTE: All C++ programs that you write must have comments at the top with the program...

    NOTE: All C++ programs that you write must have comments at the top with the program name, your name, and the pseudocode describing what the program will do. 1. Create a new program that will calculate the total cost for software purchased from a store. Each software package costs $99.00, but discounts are given on the total cost, based on the number of packages purchased. a. Ask the user for the number of packages they want to buy b. Calculate...

  • please code in basic c++ program Write a program that uses the following formula: n (ax...

    please code in basic c++ program Write a program that uses the following formula: n (ax - ib) i=1 Your program will prompt the user for the number of iterations for the calculation. input values for n, x, a, b, and c. n must be a positive integer, but x, a, b, and c can be any real numbers. Then it will perform the calculation and output the result. Then, it will ask the user if they would like to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT