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

Using functions and global variables as well as other features of matlab create

ID: 3349712 • Letter: U

Question

Using functions and global variables as well as other features of matlab create a function called Cookingtimer that adjusts the timer based on the entered food items from a list of items.

(a) Using one fprintf create a menu of 3 food items (pizza, cake, and stake) were they are listed in a column in that specific order.

(b) Create a global variable called ’food’ and using a input ask the user enter one of the items from you menu. Suppress the output of the variable.

(c) Create a function called Cookingtimer that has no inputs and outputs.

(d) In the function, set up the global variable ’food’ again.

(e) In the function, Using the global variable food that you created check it against your 3 menu items. (Hint: When comparing strings be sure to use double quotes (”) around the words and not single quotes (’)). • If the first item on the menu is entered tell the user it will take 5 seconds and pause the code for 5 seconds. For the second item, tell the user that it will take 10 seconds and pause the code for 10 seconds. Do the same for item 3, but the time is 15 seconds. Use fprintf() to tell the use the time required for each item. (Hint: you may have to use if statements and look up the pause() function). • If none of the menu items are entered, tell the user to choose from your menu.

(f) Call your function in the main code and create a fprintf telling the user their food is ready. Be sure to include what the food item is in the output.

(g) Using tic and toc time time how long it takes your function and the output to run.

Explanation / Answer

Code for Cooking_Example.m

==========================

clear; clc;
global food;

while(1)
fprintf('1) Pizza 2) Cake 3) Stake ')
food = input('Enter one of the food from the menu ','s');
if (strcmp(food,'Pizza') | strcmp(food,'Cake') | strcmp(food,'Stake'))
tic
Cookingtimer;
fprintf('Your %s is Ready.. Have a Fun.. ',food);
toc
else
fprintf('Please Enter the food from Menu ');
end
end

===================================

Code for Function.Save it as Cookingtimer.m

====================================

function [] = Cookingtimer()
global food;

if (strcmp(food,'Pizza'))
fprintf('It will take 5 Seconds to process your order ');
pause(5)
elseif (strcmp(food,'Cake'))
fprintf('It will take 10 Seconds to process your order ');
pause(10)

elseif(strcmp(food,'Stake'))
fprintf('It will take 15 Seconds to process your order ');
pause(15)
end
end

============================================

Dont Forget to hit Like,...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote