//James Hill and Daniel Shelley
//Period 7
//5-4-02
//The Perfect Engine
//Libraries
//function prototypes
//finding number of variables in chart.dat
int main ()
//arrays
//declare variables
fstream InFile("chart.dat",ios::in);
//stores information into Arrays
cout<<" "<
//get limits
//function calls
//matching volume with min and max Temps
for (int k=0; k<=num; ++k)
//getting compresion ratio
//Isentropic compression
for (int h=0; h<=num; ++h)
else
cout<<"Enter the starting atmospheric pressure:"<
//finding pressure at the ideal gas state
cout<<"The first pressure at ideal gas state is "<
//finding pressure at ideal gas state
//matching volume and internal energy with temp
//Isentropic expansion
for (int h=0; h<=num; ++h)
cout<<"The temperature after Isentropic expansion is "<
//finding pressure at isentropic expansion
//finding Thermal Efficiency
cout<<"The thermal efficiency of your car is "<
//function definition for hot
fstream InFile("chart.dat",ios::in);
for (int i=0; i<=num; ++i)
//function definition for cold
//arrays
fstream InFile("chart.dat",ios::in);
for (int i=0; i<=num; ++i)
for (int j=0; j<=num; ++j)
#include
#include
#include
#include
double hot(double);
double cold(double);
int num = 111;
{ //opening main
double T[num];
double Pr[num];
double U[num];
double Vr[num];
double V2; //volume at ideal gas state
double V3; //Volume at hottest Temp
double V4; //Volume at isentropic expansion
double r; //compression ratio
double Tb; //Beginning Temp
double Th; //Hottest Temp
double max; //exact hottest temp
double min; //exact lowest temp
double max; //exact hottest temp
double min; //exact lowest temp
double Ta; //Actual Temp
double T4; //Temp at isentropic expansion
double minV; //lowest volume of intervals
double maxV; //highest volume of intervals
double p1; //staring atmospheric pressure
double p2; //pressure of atm at first compression
double p3; //pressure of atm at second compression
double p4; //pressure of atm at isentropic expansion
double U1; //Internal energy at lowest temp
double U2; //Internal energy at isentropic compression
double U3; //Internal energy at hottest temp
double U4; //Internal energy at isentropic expansion
double TE; //Thermal Efficincy
if (InFile.fail())
{ //open if loop
if (InFile.fail())
{ //open if loop
cout<<"File Don't work!! Moron!!"<
} //close if loop
else
{ //open else loop
for (int i=0; i<=num; ++i)
{
InFile>> T[i];
InFile>> Pr[i];
InFile>> U[i];
InFile>> Vr[i];
cout<
} //close else loop
} //close else loop
cout<<"Enter the starting temp of the Engine:"<
cout<<"Enter the hottest tempature your engine can take:"<
min = cold(Tb);
max = hot(Th);
for (int k=0; k<=num; ++k)
{ //opening for loop
if ((min>=T[k])&&(min
{ //open if loop
minV = (((min-T[k])/(T[k+1]-T[k]))*(Vr[k+1]-Vr[k]))+T[k];
U1 = (((min-T[k])/(T[k+1]-T[k]))*(U[k+1]-U[k]))+U[k];
} //close if loop
} //close for loop
{ //opening for loop
if ((max>=T[k])&&(max
maxV = (((max-T[k])/(T[k+1]-T[k]))*(Vr[k+1]-Vr[k]))+T[k];
U3 = (((max-T[k])/(T[k+1]-T[k]))*(U[k+1]-U[k]))+U[k];
V3 = (((max-T[k])/(T[k+1]-T[k]))*(Vr[k+1]-Vr[k]))+Vr[k];
} //close if loop
} //close for loop
cout<<"Enter the compresion ratio"<
V2=minV/r;
{ //open for loop
if ((V2<=Vr[h])&&(V2>Vr[h+1]))
{ //open if loop
Ta = (((V2-Vr[h])/(Vr[h+1]-Vr[h]))*(T[h+1]-T[h]))+T[h];
U2 = (((V2-Vr[h])/(Vr[h+1]-Vr[h]))*(U[h+1]-U[h]))+U[h];
} //close if loop
} //close for loop
if (Ta<=Th)
{ //open if loop
cout<<"I hope you have money becasue you just melted your engine."<
{ //open else loop
cout<<"Tempature after Isentropic compression is "<
p2 = p1*(Ta/Tb)*r;
p3 = p2*(Th/Ta);
cout<<"The second pressure at the ideal gas state is "<
for (int k=0; k<=num; ++k)
{ //opening for loop
if ((Th>=T[k])&&(Th
U3 = (((Th-T[k])/(T[k+1]-T[k]))*(U[k+1]-U[k]))+U[k];
V3 = (((Th-T[k])/(T[k+1]-T[k]))*(Vr[k+1]-Vr[k]))+Vr[k];
} //close if loop
} //close for loop
V4 = V3*r;
{ //open for loop
if ((V4<=Vr[h])&&(V4>Vr[h+1]))
{ //open if loop
T4 = (((V4-Vr[h])/(Vr[h+1]-Vr[h]))*(T[h+1]-T[h]))+T[h];
U4 = (((V4-Vr[h])/(Vr[h+1]-Vr[h]))*(U[h+1]-U[h]))+U[h];
} //close if loop
} //close for loop
p4 = p1*(T4/Tb);
TE = (1-((U4-U1)/(U3-U2)))*100;
return (0);
} //close main
double hot(double x)
{ //opening function
//arrays
double T[num];
{ //opening for loop
InFile>> T[i];
} //closeing for loop
for (int j=0; j<=num; ++j)
{ //open for loop
if ((x>=T[j])&&(x
x = (((x-T[j])/(T[j+1]-T[j]))*(T[j+1]-T[j]))+T[j];
} //close if loop
} //closing for loop
return (x);
} //close hot funtion
double cold(double x)
{ //opening function
double T[num];
{ //open for loop
InFile>> T[i];
} //close for loop
{ //open for loop
if (T[j]>=x);
{ //open if loop
x = (((x-T[j])/(T[j+1]-T[j]))*(T[j+1]-T[j]))+T[j];
} //closing if loop
} //closing for loop
return (x);
} //closing function