Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECS36B Winter 2023

2023-02-13

Homework 2 due Wed Feb 22  at 23:59

Part 1: Crew scheduling

The scheduling of aircrew members must follow strict regulations on how long each person may work in a given week. Each aircrew member can work on varying number of flights and hours   depending on their job responsibilities. In this assignment, you are asked to write a program that determines whether a crew member may be scheduled for a specific flight based on their current workload. The program must be able to process different types of crew members (having different limitation on number of flights and hours). In this assignment, we will only consider three types of crew members: Pilot (5 flights, 60 hours/week), Attendant (8 flights, 60

hours/week), and a Tagged” Attendant (8 flights, 60 hours/week). A tagged attendant is working as a backup for other fulltime attendants on the fight and registers only half the hours, meaning on a flight that physically takes 7 hours, a tagged attendant will only register 3.5 hours of work, whereas an Attendant or a Pilot will register the full 7 hours of work. A flight having   stops counts as multiple flights. For example, a flight having 2 stops counts as 3 flights.

Description

The input of the program is read from standard input. Each input line consists of a description of an aircrew member, including the job title (encoded as one character), the name, number of flights recorded so far this week, and the number of hours worked during this week. Followed by the flight information, namely number of stops, and then total length of flight in hours.

Assignment

Aircrew members are represented as instances of the classes Pilot, Attendant and                 TaggedAttendant derived from a base class Aircrew. The main program                              scheduling.cpp is provided, together with the header file Aircrew.h . Another program   testAircrew.cpp is provided that tests the functionality of the Aircrew derived classes.    You should not modify these files. You will implement the base class Aircrew, and the derived classes Pilot, Attendant and TaggedAttendant in the file Aircrew.cpp . The            scheduling program reads a list of aircrew descriptions from standard input and prints a          description of the aircrew and his/her availability. See the example input files and corresponding output files for details. Note that the last line of output should reflect whether the crew member   can be assigned to the specific flight or not. If an unknown crew code is used, the program prints an error message and exits (see example files).

Example: the input line:

P Alex 3 20 1 20

describes a Pilot named Alex who has worked on 3 flights this week for a total of 20 hours. And the system is attempting to schedule Alex to a 1-stop flight (therefore, counted as 2 flights) lasting a total of 20 hours. Given this input, the scheduling program will print the following output:

Pilot: Alex has operated 3 flights for a total of 20 hours this

week

Available flights : 2

Available hours: 40

Attempting to schedule for 1 stop(s) 20 hours flight . . .

This crew member can be scheduled

Done scheduling Alex

If the input contains multiple lines, the program should process them sequentially until the end of file is reached in input.

Specification of the Aircrew classes

The Aircrew base class is an abstract class from which the classes Pilot, Attendant and TaggedAttendant are derived. The base constructor takes one argument: the name of the    crew member.

In addition, the following member functions must be defined:

virtual const std::string type(void) const

A pure virtual function returning a string (Pilot”, Attendant”or

TaggedAttendant).

virtual const int maxFlights(void) const

A pure virtual function returning the maximum number of flights a crew member can work on per week.

const double maxHours(void) const

A member function returning the maximum number of hours a crew member can work on per week.

const std::string name(void) const

A member function returning the name of the aircrew.

void setFlights(int i)

A member function used to set the number of flights worked.

void setHours(double h)

A member function used to set the current number of hours worked.

void print(void) const

A member function that prints the description of the aircrew on standard output (see first part of the above example).

virtual void scheduleFlight(int i, double h) const

A member function that prints whether the aircrew can be scheduled for the flight specified or not on standard output (see above example, starting from the line Attempting to     schedule... ).

static Aircrew* makeAircrew(char ch, std::string name_str)

A static factory function that creates an Aircrew object of the appropriate type (determined by the character ch) and returns a pointer to it. If ch is P’, a Pilot must be created. If ch is A’, an Attendant must be created, and if ch is ‘T’, a TaggedAttendant must be created.

Use the test input files to verify that your program reproduces exactly the example output files. Use the Unix diff command to compare your output to the example output. All compilations should complete without warnings (use the –Wall option). Include only the file Aircrew.cpp in the file hw2p1.tar. Submit your project as file hw2p1.tar using Gradescope.

Part 2: Air Cargo Logistics

An airline is using airplanes of various sizes to ship containers between two airports. Each           shipment consists of a number of standardized containers that must be loaded on the airplanes so as to minimize the amount of unused space. As several shipments of different sizes arrive at the   airport, the airline must decide which shipment is loaded on which plane. The following rules are applied:

-    All airplanes are flying to the same destination, i.e. a shipment can be added to any airplane.

-     A shipment cannot be split among different airplanes.

-     Once a shipment is loaded on a plane, it cannot be unloaded before departure.

You are tasked with writing a program that will assign shipments to airplanes in the order of the shipments’ arrival at the airport. The airline you work for operates Airbus A321 planes with a     capacity of 10 containers each, Boeing B777 airplanes with a capacity of 32 containers each, and Boeing B787 airplanes with a capacity of 40 containers each.

Description

The input of the program consists of the size of the shipments (i.e. number of containers in the   shipments), in the order in which they appear in the queue. The assignment program must first   print a list of available slots in all empty airplanes. It should then read the size of each shipment to be loaded and report on attempts to assign the shipment to an airplane. Finally, it should print a summary of all assignments. See the example input and output files for details. If a shipment   size is not valid (i.e. not a positive number of containers) an exception should be thrown and an error message printed before the program proceeds with the next shipment.

Assignment

The program assign.cpp is provided, together with the header files Airline.h and Airplane.h . You should not modify these files. You will implement the classes Airline and Airplane in the files Airline.cpp and Airplane.cpp respectively. A Makefile is provided and must not be modified. Use the test input files to verify that your program reproduces exactly the example output files. Use the Unix diff command to compare your output to the example output. Your classes must function correctly independently of the number of each type of airplanes used by the airline. When computing the assignment grade, a modified version of the program assign.cpp will be used, with different numbers of airplanes.

Specification of the Airline class

The Airline class constructor creates the list of airplanes using dynamic allocation of the (private) pointer array airplaneList. The airplanes should appear in the list in order of increasing size. The Airline constructor takes three arguments (the number of A321, B777 and B787 airplanes). The nAirplanes data member is the total number of airplanes used by   the airline. The Airline class has a member function addShipment that tries to assign a shipment to an airplane by inspecting the list of airplanes and by assigning the shipment to the    first airplane that can accommodate the shipment, starting at the beginning of the airplaneList array. The Airline class also has a member function printSummary that prints a list of airplanes with their current and maximum load. Empty airplanes should not be printed in the summary. See the examples of output files for details on the output format.

Specification of the Airplane class

The Airplane class constructor takes one argument (the maximum capacity of the airplane). It has accessor member functions maxLoad and currentLoad returning the maximum and current number of containers respectively. The addContainers member function attempts to add containers to the airplane and modifies the load accordingly.  It returns true if the operation is successful and false otherwise.

All compilations should complete without warnings (use the –Wall option). Include only the files Airline.cpp and Airplane.cpp in your hw2p2.tar file. Submit your project as file hw2p2.tar using Gradescope.