Question: 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
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), requiring maintenance 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 (two engines, requiring maintenance every 500 hours).
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. You will create a Makefile that includes a target all, which builds the executables maintenance and testAircraft. 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 (see example files). The cpp program should work with the following files and these files should not be modified.
The example of input and output is given below;
input
A D-AIMB 550 400 370 600 B N470WN 410 350
output
Aircraft: D-AIMB type: Airbus A380 has 4 engines engine 1: 550 hours engine 2: 400 hours engine 3: 370 hours engine 4: 600 hours Maintenance schedule for D-AIMB engine 1: maintenance due in 200 hours engine 2: maintenance due in 350 hours engine 3: maintenance due in 380 hours engine 4: maintenance due in 150 hours Aircraft: N470WN type: Boeing 737 has 2 engines engine 1: 410 hours engine 2: 350 hours Maintenance schedule for N470WN engine 1: maintenance due in 90 hours engine 2: maintenance due in 150 hours
//
// 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
Get step-by-step solutions from verified subject matter experts
