Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB, Using conditional statement(e.g.switch or if statement) to extend your u

ID: 3197339 • Letter: M

Question

MATLAB, Using conditional statement(e.g.switch or if statement) to extend your unit conversion program so it now converts numbers to metric or to imperial depending on the user’s requirements.
Also use conditional statements to allow your user to select which unit they want to convert (e.g. temperature, length, speed, mass, volume, etc) Huhene value) from Fahrenheit to Celsius. Test that your program outputs the correct values by using the following small set of test data to compare with your results: Sample test data | 32. F=0"C 100°F=37.78°C | 0° F=-17.78"C 1-40. F=-40"C | 55 F=1278"C Try to write another few scripts to create unit converters for the following types of units: Type To imperial To metric Temperature crn ? ? inch L X2.54 mfeet L. 0.3048 0.3048 kmmiles D,-= D= x1609344 1.609344 m" = 283495 "-x 28.3495 gramsounces kgpounds km/hmph m,04536 mu = m, x 0.4536 1.609344 Volume litregallon 3.78544 hectrareacre A A, x2.4711 A, 24711

Explanation / Answer

CODE:

clear;
type = input('Enter your type:');
if(strcmp(type,'Temperature'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
c = input('Enter temperature in C:');
f = (c*(9/5)) + 32;
fprintf('%dC = %dF',c,f);
elseif(strcmp(cas,'To metric'))
f = input('Enter temperature in F:');
c = (f - 32)*(5/9);
fprintf('%dF = %dC',f,c);
end
elseif(strcmp(type,'Length & Distance'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
km = input('Enter Dkm');
mil = km/1.609344;
fprintf('%dDkm = %dDmile',km,mil);
else
mil = input('Enter Dmile');
km = mil*1.609344;
fprintf('%dDmile = %dDkm',mil,km);
end
elseif(strcmp(type,'Mass'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
mkg = input('Enter Mkg');
mlb = mkg/0.4536;
fprintf('%dMkg = %dMlb',mkg,mlb);
else
mlb = input('Enter Mlb');
mkg = mlb*0.4536;
fprintf('%dMlb = %dMkg',mlb,mkg);
end
  
elseif(strcmp(type,'Speed'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
vk = input('Enter km/h');
vm = vk/1.609344;
fprintf('%dVkm/h = %dVm/h',vk,vm);
else
vm = input('Enter m/h');
vk = vm*1.609344;
fprintf('%dVm/h = %dVkm/h',vm,vk);
end
elseif(strcmp(type,'Volume'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
vl = input('Enter Vlit');
vgal = vl/3.78544;
fprintf('%dVlit = %dVgal',vl,vgal);
else
vgal = input('Enter Vgal');
vl = vgal*3.78544;
fprintf('%dVgal = %dVlit',vgal,vl);
end
elseif(strcmp(type,'Area'))
cas = input('Enter To imperial or To metric:');
if(strcmp(cas,'To imperial'))
Ah = input('Enter Ah');
Aac = Ah*2.4711;
fprintf('%dAh = %dAac',Ah,Aac);
else
Aac = input('Enter Aac');
Ah = Aac/2.4711;
fprintf('%dAac = %dAh',Aac,Ah);
end
end

OUTPUT:

Enter your type:'Temperature'
Enter To imperial or To metric:'To metric'
Enter temperature in F:100
100F = 3.777778e+01C>>
>> Untitled
Enter your type:'Temperature'
Enter To imperial or To metric:'To metric'
Enter temperature in F:0
0F = -1.777778e+01C>>
>> Untitled
Enter your type:'Temperature'
Enter To imperial or To metric:'To metric'
Enter temperature in F:32
32F = 0C>>
>> Untitled
Enter your type:'Temperature'
Enter To imperial or To metric:'To metric'
Enter temperature in F:-40
-40F = -40C>>
>> Untitled
Enter your type:'Temperature'
Enter To imperial or To metric:'To metric'
Enter temperature in F:55
55F = 1.277778e+01C>>
>>