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

A program is required to construct a data structure for different types of metal

ID: 3783321 • Letter: A

Question

A program is required to construct a data structure for different types of metal tubes manufactured by certain company. Each type has a reference number, a string representing the metal, a quantity, and a price. The following depicts the information for five sample types. Matlab script with a for loop that performs the following tasks: Prompt the user to enter the data for the five sample types of metal tubes. The data must be arrange a vector of structures. Calculate the total price for every type of tubes and accumulate it in a single variable. Print out the total price for all the tubes in stock in the form: (Total price = $.......).

Explanation / Answer

%creating array empty structure
s = struct('referenceNumber',{},'metal',{},'quantity',{},'unitprice',{})

%reading data from user
for n = 1:5
s(n).referenceNumber = input('enter reference Number: ');
   s(n).metal = input('enter type of metal: ');
   s(n).quantity = input('enter rquantity: ');
   s(n).unitprice = input('enter unit price: ');
end
%variables declaring
totalPrice = 0;
%calculating total price of single tube
for n = 1:5
   price = s(n).quantity * s(n).unitprice;
   totalPrice = totalPrice + price;
   disp(s(n).referenceNumber);
   disp(price);
end

%printing final prices
disp('Total all tubes price is: ');
disp(totalPrice);

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