/* --------------------------------------------------------------------- // Figure 9.13: Eliminating the global variable. // Figure 9.14: Functions for gas models after global elimination. // --------------------------------------------------------------------- */ #include "tools.h" #define R 8314 /* universal gas constant */ float ideal ( float v, float temp ); float vander ( float v, float temp ); void main( void ) { float temp; /* temperature of CO gas */ float m; /* mass of CO gas, in kilograms */ float vol; /* tank volume, in cubic meters */ float vmol; /* molar specific volume */ float pres; /* pressure (to be calcualted) */ banner(); printf( "\n Input the temperature of CO gas (Kelvin degrees): " ); scanf( "%g", &temp ); printf( "\n The mass of the gas (kg) is: " ); scanf( "%g", &m ); printf( "\n The tank volume (cubic m) is: " ); scanf( "%g", &vol ); vmol = 28.011 * vol / m; /* molar volume of CO gas */ pres = ideal( vmol, temp ); /* pressure; ideal gas model */ printf( "\n The ideal gas at %.3g K has a pressure of " "%.3g kPa \n", temp, pres ); pres = vander ( vmol, temp ); /* pressure; Van der Waal's model */ printf( " Van der Waal's gas at %.3g K has a pressure of " "%.3g kPa \n\n", temp, pres ); bye(); } /* ---------------------------------------------------------------------- ** Pressure of CO gas in a tank, using the ideal gas equation PV = RT. */ float ideal( float v, float temp ) { float p; /* LOCAL variable DECLARATION */ p = R * temp / v; /* pressure in Pascals */ return p / 1000.0; /* pressure in kilo Pascals (kPa) */ } /* ---------------------------------------------------------------------- ** Pressure of CO gas in a tank, using Van der Waal's equation, ** P = RT/(v-b) - a/(v*v). */ float vander( float v, float temp ) { float p; /* LOCAL declaration, not same p as above */ const float a = 1.474E+05; /* constants for CO gas */ const float b = .0395; p = R * temp / (v - b) - a / (v * v); /* pressure in Pascals */ return p / 1000.0; /* kPa pressure */ }