****************** USE MATLAB ************* Write a program capable of convertin
ID: 2293560 • Letter: #
Question
****************** USE MATLAB *************
Write a program capable of converting a value of pressure from an initial unit to a new unit. Ask the user to enter both a value for pressure as well as the unit of the value. Also ask the user what their preferred unit of pressure is. (Ex: The user has a value of 50 psi, and they want you to convert this to kilo-Pascals) Your program should be able to convert between 3 different possible units of pressure: "kPa" (kiloPascals), "psi" (pounds per square inch), and "bar". Once the conversion is complete, display the sentence “ XXX.X UNITS was converted to XXX.X UNITS " , where the 1st UNITS is the word that refers to the initial input unit (kPa, psi, or bar), and the 2nd UNITS refers to the converted unit. *Your program should account for the fact that the user could potentially choose the same unit twice. (They could ask you to convert psi to psi.) *Feel free to use the menu command instead of input command for the user choice of units *You can find the conversions between kPa, psi, and bar on the internet. 4. The Bits-n-Bytes computer system is malfunctioning and they need your help to make it work. Write a code that can determine if a customer is allowed to use their meal plan to purchase food Assume that meal plans follow the given conditions: You are allowed 15 meals during the week. Each meal must be within the following price limits 5. Breakfast: $5.77 Lunch: $7.98 Dinner: $9.53 Use input or menu commands to determine the following information about the current customer: How many meals have they already used this week? Is it breakfast, lunch, or dinner? What is the total cost of their items? Based upon the input information, display an appropriate message telling the customer what happened after you swiped their card. (Tell them they don't have any meals left, or tell them their items are too expensive, or tell them the transaction was completed successfully.)Explanation / Answer
4.Ans)
================MATLAB CODE for script tiltled pressure_conv.m============
p=input('Enter the Pressure value:');
units=input('Enter the units of pressure value given above(kpa or bar or psi):','s');
K = menu('Choose units you want to convert','kpa','psi','bar');
if units=='kpa'
if K==1
p_new=p; %1kpa =1kpa
elseif K==2
p_new=p*0.145038; %1kpa=0.145038psi
else
p_new=p*0.01;% 1kpa=0.01 bar
end
elseif units=='psi'
if K==1
p_new=p*6.89476; %1psi=6.89476 kpa
elseif K==2
p_new=p; % 1psi=1psi
else
p_new=p*0.0689; %1psi=0.0689 bar
end
else
if K==1
p_new=p*100; %1bar=100 kpa
elseif K==2
p_new=p*14.5038; %1 bar=14.5038 psi
else
p_new=p; %1 bar=1bar
end
end
if K==1
X = sprintf('%5.5f %s was converted to %d kpa.',p,units,p_new);
disp(X)
elseif K==2
X = sprintf('%5.5f %s was converted to %d psi.',p,units,p_new);
disp(X)
else
X = sprintf('%5.5f %s was converted to %d bar.',p,units,p_new);
disp(X)
end
===============================
When you run the above script
===================result in command window=============
>> pressure_conv
Enter the Pressure value:1
Enter the units of pressure value given above(kpa or bar or psi):bar
1.00000 bar was converted to 100 kpa.
==================================
Only 1 question per post will be answered please ,if common data question upto 4 parts will be answered
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.