please this is a matlab coding and only matlab is allowed to used. I will really
ID: 3718422 • Letter: P
Question
please this is a matlab coding and only matlab is allowed to used. I will really appreciate if you solve this 2 parts of the problem for me using matlab
Name: GTID (903XXXXXX, ete.): Problem 2. Write 1-15 lines of code to answer the following questions. DO NOT write functions. Pay attention to the names of variables. (20 points) a. You are deciding whether or not to buy an item. The name of the item is stored in item. The price of the item is stored in price. Your maximum budget is stored in budget. Set the variable decision based on the following conditions: If the first four letters of item are 'SALE' (case sensitive) then reduce the price by . 10% . If you buy the item and it was on sale then decision is 'Great Price" . If you buy the item and it was not on sale then decision is 'Not bought on ifyou do not buy the itorn then decision is 'Too expensive · You buy the item if your budget is greater than or equal to the price. Item will always be greater than 4 in length. (10 points) Examples item- SALECshirt price 10 budget8 decisionGreat price! 2: item -eggs price 5 budget3 decision 'Too expensive Name: GTID (903xxxxxx, ete.): b. You are given a 4xN array of doubles, temps, where each row has temperature samples from of the seasons (Spring, Summer, Fall, and Winter, respectively). You are given a string one season, that is one of the seasons listed above (case sensitive). Based on the season gi the average temperature for that season and make a sentence of the form it was about caverage ven, finc temperature . Store this sentence in veather. Itis guaranteed that the average temperature will be an integer. (10 points) Example season Summer temps 50, 60, 70; Spring 80, 90, 100 50, 40, 50 30, 20, 401 ? summe r Fall Winter weather This Summer, it was about 90. Note: Spring will always be row I, Summer row 2, Fall row 3, and Winter row 4,Explanation / Answer
a
Please note that example with item 'SALEshirt', price = 10 and budget with 8|
decision should be 'Too expensive' because after providing 10% discount, price becomes 9, which is higher than budget
Code:
item = 'SALEshirt'
price = 10
budget = 8
if strfind(item, 'SALE') == 1
price = price * 0.9;
end
if price <= budget && strfind(item, 'SALE') == 1
decision = 'Great Price'
elseif price <= budget
decision = 'Not bought on sale'
else
decision = 'Too expensive'
end
b
season = 'Summer';
temps = [50, 70, 90;
80, 90, 100;
50, 40, 50;
30, 20, 40];
if season == 'Spring'
avg_temp = mean(temps(1,:));
elseif season == 'Summer'
avg_temp = mean(temps(2,:))
elseif season == 'Fall'
avg_temp = mean(temps(3,:));
elseif season == 'Winter'
avg_temp = mean(temps(4,:));
end
weather = sprintf('This %s, it was %d', season, avg_temp)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.