1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
//Interface Temp Calculator for Composite Planar Wall with a Variable # of Materials
//Use of Structure, Loop and Array
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
double flux(double H, double tsurf, double tfluid)
{
double Q;
Q = H * (tfluid - tsurf);
return Q;
}
const int MAXNUMWALLS = 50;
struct tWallData
{ //20
double L;
double K;
};
double intTemp(double Q, double tsurf, int numWalls, wallCalc[j].L, wallCalc[j].K)
{
double Tout;
for (int j = 0; j < numWalls; j++)
{
Tout = tsurf - ((Q * (wallCalc[j].L)) / (wallCalc[j].K));
tsurf = Tout;
}
return Tout;
}
int main()
{
//input for flux calc
double T2;
double q;
double h;
cout << "Enter Outside Convection Coefficient (w/m^2*K): ";
cin >> h;
double T1;
cout << "Enter Outside Material Surface Temp. (Deg C): ";
cin >> T1;
double Tfluid;
cout << "Enter Outside Fluid Temp. (Deg C): ";
cin >> Tfluid;
q = flux(h, T1, Tfluid);
// array of structures
tWallData wallCalc[MAXNUMWALLS];
int numWalls;
do
{
cout << "Enter # of materials in wall (1-50): ";
cin >> numWalls;
cout << endl;
} while ( numWalls < 1 || numWalls > 50);
// store data
for (int k = 0; k < numWalls; k++)
{
cout << "Enter thickness of material (m) " << k+1 << ": ";
cin >> wallCalc[k].L;
cout << "Enter conductivity of material (w/m*k) " << k+1 << ": ";
cin >> wallCalc[k].K;
if (wallCalc[k].K < .0001)
{
cout << setw(12) << " " << "K value must be larger than .0001 w/m*k" << endl;
return 0;
}
if (wallCalc[k].K > 300)
{
cout << setw(12) << " " << "K value must be smaller than 300 w/m*k" << endl;
return 0;
} //80
cout << endl;
}
// Calculate with stored data from structure
cout << endl << endl;
cout << "Interface Temperatures" << endl;
cout << setfill('-') << setw(60) << "-" << setfill(' ') << endl;
for (int j = 0; j < numWalls; j++)
{
T2 = intTemp(q, T1, numWalls, wallCalc[j].L, wallCalc[j].K);
cout << setw(12) << " " << "The exit surface temp of material # " << j + 1 << " is: " << T2 << endl;
}
return T1;
cout << endl << endl << endl;
return 0;
}
|