Question: Hello, I have to write the following program, but I do not understand virtual functions or pure virtual function. I would appreciate any help as

Hello, I have to write the following program, but I do not understand virtual functions or pure virtual function. I would appreciate any help as to ho to get started on this program :)

Aircraft Maintenance System Program Problem

The regular maintenance of aircraft engines is critical to ensure the high level of safety of air travel. Maintenance activities are scheduled for each engine of an aircraft after specific periods of use, which depend on the aircraft and engine model. In this assignment, you are asked to write a program that determines the maintenance schedule of aircraft engines. The program must be able to process different types of aircrafts (having different numbers of engines), requiringmaintenance at different intervals. In this assignment, we will only consider two types of aircraft:

Airbus A380 (four engines, requiring maintenance every 750 hours) and Boeing 737 (twoengines, requiring maintenance every 500 hours).

Description

The input of the program is read from standard input. Each input line consists of a description of an aircraft, including the model (encoded as one character), the aircraft name (or tail code), and the number of hours recorded since the last maintenance check for each of its engines. The

number of hours of use may differ among the engines of a given aircraft due to the fact that not all engines are subjected to maintenance at the same time.

Assignment

Aircrafts are represented as instances of the classes A380 and B737 that are derived from a base class Aircraft. The main program

maintenance.cpp is provided, together with the header file Aircraft.h. Another program testAircraft.cpp is provided that tests the functionality of the

Aircraft derived classes. You should not modify these files. You will implement the base class Aircraft, and the derived classes A380 and B737 in the file Aircraft.cpp. The maintenance program reads a list of aircraft descriptions from standard input and prints a description of the aircraft and its

maintenance schedule. See the example input files and corresponding output files for details. Note that if an engines maintenance is past due, a special output message is printed instead of a time. If an unknown aircraft code is used, the program prints an error message and exits.

Example: the input line:

A VH-OQF 630 550 470 690

describes an Airbus A380 named VH-OQF whose four engines have 630, 550, 470 and 690 hours of use since their last maintenance. Given this input, the maintenance program will print the following output:

Aircraft: VH-OQF type: Airbus A380 has 4 engines

engine 1: 630 hours

engine 2: 550 hours

engine 3: 470 hours

engine 4: 690 hours

Maintenance schedule for VH-OQF

engine 1: maintenance due in 120 hours

engine 2: maintenance due in 200 hours

engine 3: maintenance due in 280 hours

engine 4: maintenance due in 60 hours

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

Specification of the Aircraft classes

The Aircraft base class is an abstract class from which the classes A380 and B737 are derived. The base constructor takes two arguments: the number of engines and the aircraft name. In addition, the following member functions must be defined:

virtual const std::string type(void) const

A pure virtual function returning a string (A380 or B737).

virtual const int maxHours(void) const

A pure virtual function returning the maximum duration of use of an engine before maintenance is due.

const std::string name(void) const

A member function returning the name of the aircraft.

int numEngines(void) const

A member function returning the number of engines of the aircraft.

void setHours(int i, int h)

A member function used to set the current number of hours of use for engine i.

void print(void) const

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

void printSchedule(void) const

A member function that prints the maintenance schedule of the aircraft on standard output (see above example).

static Aircraft* makeAircraft(char ch, std::string name_str)

A static factory function that creates an Aircraft object of the appropriate type (determined by the character ch) and returns a pointer to it. If ch is A, an A380

must be created. If ch is B, a B737 must be created.

// // Aircraft.h // #ifndef AIRCRAFT_H #define AIRCRAFT_H #include

class Aircraft { public: Aircraft(int n, std::string name_str); virtual const std::string type(void) const = 0; virtual const int maxHours(void) const = 0; const std::string name(void) const; int numEngines(void) const; void setHours(int i, int h); void print(void) const; void printSchedule(void) const; static Aircraft* makeAircraft(char ch, std::string name_str); virtual ~Aircraft(void); protected: const int numEng; const std::string nm; int* hrs; };

class A380: public Aircraft { public: A380(std::string name_str); virtual const std::string type(void) const; virtual const int maxHours(void) const; };

class B737: public Aircraft { public: B737(std::string name_str); virtual const std::string type(void) const; virtual const int maxHours(void) const; }; #endif

// // maintenance.cpp //

#include "Aircraft.h" #include using namespace std;

int main() { char ch; string s; cin >> ch >> s; while ( cin ) { Aircraft *p = Aircraft::makeAircraft(ch,s); if ( p != 0 ) { for ( int i = 1; i <= p->numEngines(); i++ ) { int h; cin >> h; p->setHours(i,h); }

p->print(); p->printSchedule(); cin >> ch >> s; } else { cout << "unknown aircraft code" << endl; return 1; } } }

// // testAircraft.cpp //

#include "Aircraft.h" #include using namespace std;

int main() { Aircraft *p1 = Aircraft::makeAircraft('A', "D-AIMB"); p1->setHours(1,100); p1->setHours(2,300); p1->setHours(3,600); p1->setHours(4,200); p1->print(); p1->printSchedule(); delete p1;

Aircraft *p2 = Aircraft::makeAircraft('B', "N772SW"); p2->setHours(1,7700); p2->setHours(2,300); p2->print(); p2->printSchedule(); delete p2; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!