Program in C++

//James Hill and Daniel Shelley
//Period 7
//5-4-02
//The Perfect Engine

//Libraries
#include
#include
#include
#include

//function prototypes
double hot(double);
double cold(double);

//finding number of variables in chart.dat
int num = 111;

int main ()
{ //opening main

//arrays
double T[num];
double Pr[num];
double U[num];
double Vr[num];

//declare variables
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

fstream InFile("chart.dat",ios::in);
if (InFile.fail())
{ //open if loop
if (InFile.fail())
{ //open if loop
cout<<"File Don't work!! Moron!!"< return (0);
} //close if loop

//stores information into Arrays
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 for loop
} //close else loop
} //close else loop

cout<<" "<

//get limits
cout<<"Enter the starting temp of the Engine:"< cin>>Tb;
cout<<"Enter the hottest tempature your engine can take:"< cin>>Th;

//function calls
min = cold(Tb);
max = hot(Th);

//matching volume with min and max Temps
for (int k=0; k<=num; ++k)
{ //opening for loop
if ((min>=T[k])&&(min { //open if loop
{ //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

for (int k=0; k<=num; ++k)
{ //opening for loop
if ((max>=T[k])&&(max { //open if loop
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

//getting compresion ratio
cout<<"Enter the compresion ratio"< cin>>r;

//Isentropic compression
V2=minV/r;

for (int h=0; h<=num; ++h)
{ //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."< } //close if loop

else
{ //open else loop
cout<<"Tempature after Isentropic compression is "<

cout<<"Enter the starting atmospheric pressure:"< cin>>p1;

//finding pressure at the ideal gas state
p2 = p1*(Ta/Tb)*r;

cout<<"The first pressure at ideal gas state is "<

//finding pressure at ideal gas state
p3 = p2*(Th/Ta);
cout<<"The second pressure at the ideal gas state is "<

//matching volume and internal energy with temp
for (int k=0; k<=num; ++k)
{ //opening for loop
if ((Th>=T[k])&&(Th { //open if loop
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

//Isentropic expansion
V4 = V3*r;

for (int h=0; h<=num; ++h)
{ //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

cout<<"The temperature after Isentropic expansion is "<

//finding pressure at isentropic expansion
p4 = p1*(T4/Tb);

//finding Thermal Efficiency
TE = (1-((U4-U1)/(U3-U2)))*100;

cout<<"The thermal efficiency of your car is "< } //close else loop
return (0);
} //close main

//function definition for hot
double hot(double x)
{ //opening function
//arrays
double T[num];

fstream InFile("chart.dat",ios::in);

for (int i=0; i<=num; ++i)
{ //opening for loop
InFile>> T[i];
} //closeing for loop
for (int j=0; j<=num; ++j)
{ //open for loop
if ((x>=T[j])&&(x { //open if loop
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

//function definition for cold
double cold(double x)
{ //opening function

//arrays
double T[num];

fstream InFile("chart.dat",ios::in);

for (int i=0; i<=num; ++i)
{ //open for loop
InFile>> T[i];
} //close for loop

for (int j=0; j<=num; ++j)
{ //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