Question: How to using function to rewrite this code? Function Requirements: instructions a void function with no parameters print out instructions message as per output example
How to using function to rewrite this code?
Function Requirements: instructions a void function with no parameters print out instructions message as per output example (see below) intputData a void function with three parameters prompts user for the values of total pressure, static pressure and temperature and then puts these values into variables that were declared in main. processResults a void function with five parameters that calculates velocity and mach number from total pressure, static pressure and temperature. printReport a void function with five parameters that prints to the monitor an output report that meets the requirements shown below. Calculation of Mach number: Mach number is the velocity divided by the speed of sound.
Mach Number= velocity/speed of sound
Calculation of speed of sound:
The speed of sound is proportional to the absolute temperature. The formula below will give an estimate of the speed of sound in ft/sec using temperature in degrees Fahrenheit. Speed of Sound vs (Temperature in degrees Fahrenheit )
Vs=1086*sqrt((T+460)/460) ft/sec
Input Data Run the program with these two sets of input data:
| Input Data Set | Total Pressure (psi) | Static Pressure (psi) | Temperature (deg F) |
| #1 | 30 | 14.7 | 90 |
| #2 | 23 | 14.7 | 90 |
Output Requirements Your output should look like this: This program computes the velocity and Mach number based on two pressure values and a temperature. Follow the prompts.
Re-use code:
#include "stdafx.h"
#include
#include
using namespace std;
.
const double k = 1.4; // k is ratio of Specific heats for air
const double airDENSITY = 0.002378; // airDENSITY is at sea level standard conditions
. // units are in slugs per cubic foot
int main()
{
double totalPressure, staticPressure, airSpeed;
char answer;
.
cout << endl << "Do you want to enter pressure in psi? (Y or N) ";
cin >> answer; if (answer == 'y' || answer == 'Y')
{ cout << endl << "Type in the Total Pressure in psi >>>>> ";
cin >> totalPressure;
cout << endl;
cout << "Type in the Static Pressure in psi >>>>> ";
cin >> staticPressure;
totalPressure = totalPressure * 144.;
staticPressure = staticPressure * 144.; // These statements convert psi to pounds psf
}
else
{ cout << endl << "Do you want to enter pressure in psf? (Y or N) ";
cin >> answer;
if (answer == 'y' || answer == 'Y')
{ cout << " Type in the Total Pressure in psf >>>>> ";
cin >> totalPressure;
cout << " Type in the Static Pressure in psf >>>>> ";
cin >> staticPressure;
}
else
{ cout << " Then I can't help you. Good bye. " << endl << endl;
exit(1);
}
}
.
airSpeed =
sqrt
( ( (2 * k)/(k-1))* (staticPressure / airDENSITY) *
(pow ( ( ( (totalPressure-staticPressure)/staticPressure) + 1) , (k-1)/k
) - 1
)
);
/* this calcuation gives airSpeed in units of ft/s as long as the pressures are in psf and the air density is in slugs per cubic foot and the air density is in slugs per cubic foot */
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1); // These statements merely format the output
cout << endl << endl << endl;
cout << "************Output*********Results******************* ";
cout << "* * ";
cout << "* Pressure Total ---------- " << totalPressure/144 << " psi * ";
cout << "* * ";
cout << "* Pressure Static --------- " << staticPressure/144 << " psi * ";
cout << "* * ";
cout << "* * ";
cout << "* Air Speed --------------- " << airSpeed << " ft/sec * ";
cout << "* * ";
cout << "* " << airSpeed * 3600/5280 << " mph * ";
cout << "* * ";
cout << "**************************************************** ";
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
