Create a script file for conversion of temperatures. Use the input function or m
ID: 3551814 • Letter: C
Question
Create a script file for conversion of temperatures. Use the input function or menu function to allow the user to enter temperature scale of Fahrenheit, Celsius, Kelvin, or Rankine. If you are using the input function, tell the user to enter F for Fahrenheit, C for Celsius, K for Kelvin, or R for Rankine. Use the input function to prompt the user to enter the temperature value(s) to be converted. Next use a multi-way selection structure (either and if-elseif or switch) to convert the input temperature(s) to corresponding temperatures in the other 3 temperature scales. Next use fprintf to output the original temperatures and converted temperatures displaying 3 decimal places.
For example the following was output when the user entered Kelvin as the temperature scale of the input temperatures.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
Enter the temperature(s) to be converted in square brackets. [373.134, 0,273.15, 233.15]
373.134 Kelvin corresponds to 99.984 degrees Celsius,
671.641 degrees Rankine and 211.971 degrees Fahrenheit.
0.000 Kelvin corresponds to -273.150 degrees Celsius,
0.000 degrees Rankine and -459.670 degrees Fahrenheit.
273.150 Kelvin corresponds to 0.000 degrees Celsius,
491.670 degrees Rankine and 32.000 degrees Fahrenheit.
233.150 Kelvin corresponds to -40.000 degrees Celsius,
419.670 degrees Rankine and -40.000 degrees Fahrenheit.
Explanation / Answer
a=input('enter the temperature : ');
b=input('enter type of temperature , F for farenheit,K for kelvin,R for rankin, C for degree celcius ');
switch(b)
case 'F' || 'f'
c=5*(a-32)/9;
x=[num2str(a),'farenheit corresponds to ',num2str(c),' degree celcius.'];
disp(x)
d=0.8*c;
x=[num2str(a),'farenheit corresponds to ',num2str(d),' degree rankins.'];
disp(x)
e=c-273;
x=[num2str(a),'farenheit corresponds to ',num2str(e),' degree kelvin.'];
disp(x)
case 'c' || 'C'
c=1.8*a+32;
x=[num2str(a),'celcius corresponds to ',num2str(c),' degree farenheit.'];
disp(x)
d=0.8*a;
x=[num2str(a),'celcius corresponds to ',num2str(d),' degree rankins.'];
disp(x)
e=c-273;
x=[num2str(a),'celcius corresponds to ',num2str(e),' degree kelvin.'];
disp(x)
case 'r' || 'R'
c=2.25*a+32;
x=[num2str(a),'rankins corresponds to ',num2str(c),' degree farenheit.'];
disp(x)
d=1.25*a;
x=[num2str(a),'rankins corresponds to ',num2str(d),' degree celcius.'];
disp(x)
e=d-273;
x=[num2str(a),'rankins corresponds to ',num2str(e),' degree kelvin.'];
disp(x)
case 'k' || 'K'
c=a+273;
x=[num2str(a),'kelvin corresponds to ',num2str(c),' degree celcius.'];
disp(x)
d=0.8*c;
x=[num2str(a),'kelvin corresponds to ',num2str(d),' degree rankins.'];
disp(x)
e=1.8*c+32;
x=[num2str(a),'kelvin corresponds to ',num2str(d),' degree farenheit.'];
disp(x)
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.