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

****** USE MATLAB ******* 7. Write a code to calculate the cost of a shopping tr

ID: 2293591 • Letter: #

Question

****** USE MATLAB *******

7. Write a code to calculate the cost of a shopping trip at Goodwill. The cost will depend upon both the type of item you buy, as well as the weight of your item. Your code should ask the user to input what type of item they are buying (housewares, clothes, or books), and also the weight of their purchase. Weight should be input as a vector comprised of lbs & oz. (1st value is the lbs and 2nd is oz. ex: instead of 6.25 lb it is [6,4]) Weight more than 10 Type of Items Weight 0-5 lbs Weight 5-10 lbs $0.80/lb S4 + $0.75 for each$7.75 + $0.60 for each additional lb or fraction additional lb or fraction Small housewares of a lb above 5 lbs of a lb above 10 lbs Clothing $1.60/lb $8 + $0.06 for each$12.8$0.04 for each additional oz or fraction of an oz above 5 lbs, additional oz or fraction of an oz above 10 lbs $0.59/lb Books and other heavy objects $2.95 + $0.50 for each $5.45$0.40 for each additional pound above| additional lb above 10 5 lbs (To make things easier, you may ask the user to enter 1 for housewares, 2 for clothes, etcor you can use the menu command.)

Explanation / Answer

Type the following matlab code in m file and than run it

clc
clear all


item=input('please enter 1 if you are buying houseware item and 2 for clothes and 3 for books and heavy item:');
weight=input('please enter weight of item you have selected in vector form :');
netweight=weight(1)+(weight(2)/100);
w2=ceil(weight(2)/100);


if item==1 & netweight<=5
cost=weight(1)*0.8;
fprintf('you bought house ware item of %d lbs at cost %d $ ',netweight,cost);


elseif item==1 & 5<netweight<=10
    cost=4+((weight(1)-5)*0.75)+(w2*0.75);

fprintf('you bought house ware item of %d lbs at cost %d $ ',netweight,cost);


elseif item==1 &netweight>10
cost=(7.75+((weight(1)-10)*0.6)+(w2*0.6)) ;
fprintf('you bought house ware item of %d lbs at cost %d $ ',netweight,cost);
end


if item==2 & netweight<=5
cost1=weight(1)*1.6;
fprintf('you bought clothes item of %d lbs at cost %d $ ',netweight,cost1);
elseif item==2 & 5<netweight<=10
  
cost1=8+((weight(1)-5)*0.06)+(w2*0.06);
fprintf('you bought clothes item of %d lbs at cost %d $ ',netweight,cost1);
elseif item==2 &netweight>10
cost1=(12.8+((weight(1)-10)*0.04)+(w2*0.04));
fprintf('you bought clothes item of %d lbs at cost %d $ ',netweight,cost1);
  
end


if item==3 & netweight<=5
cost2=weight(1)*0.59;
fprintf('you bought books and other heavy item of %d lbs at cost %d $ ',netweight,cost2);
elseif item==3 & 5<netweight<=10
  
cost2=2.95+((weight(1)-5)*0.5)+(w2*0.5);
fprintf('you bought books and other heavy item of %d lbs at cost %d $ ',netweight,cost2);
elseif item==3 & netweight>10
cost2=(5.45+((weight(1)-10)*0.4)+(w2*0.4));
fprintf('you bought books and other heavy item item of %d lbs at cost %d $ ',netweight,cost2);
  
end

Result

say someone chooses books of weight 10.3 lbs

please enter 1 if you are buying houseware item and 2 for clothes and 3 for books and other heavy item :3
please enter weight of item you have selected in vector form :[10 3]


you bought books and other heavy item of 1.003000e+01 lbs at cost 5.950000e+00 $

note :you can try for other combinations of weight and type of product .