Array of Structures Create a function CreateArrayOfStructure to create an array
ID: 2249759 • Letter: A
Question
Array of Structures Create a function CreateArrayOfStructure to create an array of structs pizzasln Store with 3 fields: one field is name that is a string with the name of the pizza, next is ingredients that is a string with the ingedients, and the third calories that is a numeric with the total calories The first item in pizzasln Store is associated with the "Barbecue" pizza, then "Carbonara" and finally "Ham and Cheese". In a "Barbecue" pizza, the ingredients are "Beef, chicken, bacon, barbecue sauce" and the calories equals an integer, which is an input parameter of the function CreateArrayOf Structure. In a "Carbonara" pizza, the ingredients are "Mushrooms, onion, creamy sauce" and the calories equals 5 calories less that the "Barbecue" pizza. In a "Ham and Cheese" pizza, the ingredients are "Ham, cheese, bacon" and the calories equals the "Barbecue" pizza. For example Matlab only >>numberCalofBBQ-30 pizzasInStore -CreateArrayOfStructure(numberCalofBBQ) pizzas!nStore = 1x3 struct array with fields: name ingredients calories Your Function Save C Reset MATLAB Documentation 1 function pizzasInStore -CreateArrayOfStructure (numberCalofBBQ) 2 Barbecue pizza, the ingredients are Beef, chicken, bacon, barbecue sauce 3 % and the calories equals an integer variable 4% Carbonara pizza, the ingredients are Mushrooms, onion, creamy sauce 5and the calories equals 5 calories less that the Barbecue pizza 6%Ham and Cheese pizza, the ingredients are Ham, cheese, bacon 7 % and the calories equals that of the Barbecue pizza 9% Your code goes here % 18 en 12 13Explanation / Answer
save the below code as CreateArrayofStructure.m and enter inputs as entered in the question snapshot.
function pizzasInStore = CreateArrayofStructure(numberCalofBBQ)
pizza_name={'Barbecue','Carbonara','Ham and Cheese'}; %String intialization of pizza name
pizza_ingredients = {'Beef, chicken, bacon, barbecue sauce','Mushrooms, onion, creamy sauce','Ham, cheese, bacon'}; %String intialization of pizza ingredients
pizza_calories=[numberCalofBBQ,numberCalofBBQ-5,numberCalofBBQ];%String intialization of calories
for i=1:numel(pizza_calories)
pizzasInStore(i).name=string(pizza_name{i});
pizzasInStore(i).ingredients=string(pizza_ingredients{i});
pizzasInStore(i).calories=pizza_calories(i);
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.