The program should be written in C not C++ or C#. Pressure is a measure of force
ID: 3722091 • Letter: T
Question
The program should be written in C not C++ or C#.
Pressure is a measure of force applied to the surface of an object per unit area. There are several units that can be used to measure pressure . Pascal (Pa) which is one Newton per square meter Pound-force Per Square Inch (psi) Atmosphere (atm) or standard atmospheric pressure The torr, an absolute scale for pressure To convert between these units, you can use the following formulas. psi is equal to 6.89475729 Pascals, 1 psi is equal to 0.068045964 atmospheres · 1 atmosphere is equal to 101,325 Pascals orr is equal to atmosphere an . l t ·1 t d 101 Pascals dPasC 760 760Explanation / Answer
#include<stdio.h>
//pressure.h
enum SCALE{PASCAL = 0,PSI,ATOM,TORR,MAX};
int convertPressure(double* pa, double * psi, double * atom, double * torr,SCALE scale);
//pressure.c
int convertPressure(double* pa, double * psi, double * atom, double * torr,SCALE scale)
{
if(scale >= MAX)
{
printf("invalid scale ");
return MAX;
}
if(scale == PASCAL)
{
*psi = (6894.75729) * (* pa);
*atom = (double)(101325.00) * (*pa);
*torr = ((double) (*atom))/ ((double)(760.00));
}
else if(scale == PSI)
{
*atom =((double)(*psi)) / ((double)(0.068045964));
*pa = ((double)(*atom) / ((double)(101325.00)));
*torr = ((double) (*atom))/ ((double)(760.00));
}
else if(scale == ATOM)
{
*pa = ((double)(*atom) / ((double)(101325.00)));
*psi = (double) (6894.75729) * (* pa);
*torr = ((double) (*atom))/ ((double)(760.00));
}
else if(scale == TORR)
{
*atom = ((double)(760.00)) * ((double)(*torr));
*pa = ((double)(*atom) / ((double)(101325.00)));
*psi = (double)(6894.75729) * (double)(* pa);
}
return 0;
}
//pressureDemp.c
int main()
{
double pa,psi,atom,tor;
int ret = 0;
pa = 100;
ret = convertPressure(&pa,&psi,&atom,&tor,PASCAL);
if (ret == 0)
printf("ps = %lf psi= %lf atom = %lf tor =%lf ",pa,psi,atom,tor);
else
printf("got error")
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.