Question: MATLAB 14.8 Structure example: Seat reservation system A programmer commonly uses structures, arrays, and functions together. Consider a program that allows a reservations agent to





MATLAB
14.8 Structure example: Seat reservation system A programmer commonly uses structures, arrays, and functions together. Consider a program that allows a reservations agent to reserve seats for people, such as for a theater, an airplane, etc. The below program defines a seat structure whose fields are a person's first name, last name, and the amount paid for the seat. The program creates an array of structures allseats, and then allows a user to enter commands to print all seats, reserve a seat, or quit. Figure 14.8.T: Main script. % Assign default menu value userKey = 'go'; disp( 'Reservation System for 5 seats % Define an array of 5 empty seats al!Seats MakeAllSeatsEmpty (5); = % Continue to prompt user for menu selection while not quit while -strcmp (userKeyq) fprintf (' ') % Print empty line userKey input( Enter command (p/r/g): % Print all seats in array % Print each seat's information if strcmp (userKey, p') PrintAllseats (allSeats); elseif stromp(userKey, % Reserve a seat seatNumber = input (Enter seat number : ' ); % Get seat number if CheckSeatEmpty (allseats (seatNumber)) % Check if seat is empty a11seat s (seatNumber) Reserveseat(); % If empty, Reserve seat = else % If not empty, display error message fprintf (Seat %d is not empty. ', seatNumber) end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
