


Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!



Duration: 1 hour 25 minutes
You are going to write a program to manage the stock of spare parts of an airline. The airline operates in 10 different airport and stores spare parts in all of them.
Section 1. 1 point. Define and pre-allocate a vector of structures to store the following information regarding the spare parts^1 for 250 different parts. Please use the same field names described here:
Define the maximum number of parts (maxParts) as a variable
Section 2. 2 points. Write a function with the header shown below to read the information on the parts - including the stock in each airport - and store it in the vector of structures defined in the previous section.
The number of parts to store will depend on the user. The program will first ask the user for the data of one part and next if he/she wants to enter data for a new part. This will continue until the user decides to stop entering data or the maximum number of spares (250) is reached. The number of spare parts actually registered in the system by the user (nParts) is returned as an output parameter of the function, together with the vector of structures (parts).
function [parts,nParts] = getData(parts,maxParts)
Section 3. 1 point. Write a function to display the data of all the spare parts, including the number of units of each spare part available in each airport
Section 4. 2 points. Write a function (see header below) to find a part by its code. The input parameters of the function are the vector of structures (parts), the number of parts registered (nParts ) and the code of the part to search (partCode). The output parameters are a flag (true or false) to tell if the piece is found (found) and the position of the part in the vector (pos). The search must stop once that the part is found
function [found,pos]=findPart(parts,nParts,partCode)
(continues)
(^1) A spare part , spare, service part, repair part, or replacement part, is an interchangeable part that is kept in
an inventory and used for the repair or replacement of failed units (spanish: pieza de repuesto )
Section 5. 2 points. Write a function to remove a spare part from the vector of structures, with the header shown below. The input parameters of the function are the vector of structures (parts), the number of parts registered (nParts ) and the position in the vector of the part to remove (pos). The output parameters are the modified vector and the modified number of spare parts actually registered. To remove a part, overwrite it in the vector of parts with the next one, and update the number of parts registered
function [parts,nParts] = removePart(parts, nParts, pos)
Section 6. 2 points. Using all the functions previously designed, write a main script with the following steps
%% Section 3 function displayParts(parts,nParts) for i=1:nParts fprintf('\n'); fprintf('description: %s\n',parts(i).name); fprintf('code: %i \n',parts(i).code); fprintf('manufacturer: %i \n',parts(i).manufacturer); fprintf('Number of parts in each airport:\n'); for a=1: fprintf('airport %i',a) fprintf(':%i;\t',parts(i).stock(a)); end end end
%% Section 4 function [found,pos]=findPart(parts,nParts,partCode) i=1; found = false; pos=-1; while i<=nParts && found==false if parts(i).code== partCode found= true; pos =i; end i=i+1; end end
%% Section 5 function [parts,nParts] = removePart(parts,nParts,pos) for i=pos:nParts- parts(i)=parts(i+1); % overwrite part with the next end nParts=nParts-1; end