/*————————————————————————-**— —**— airport.cpp —**— —**— This program simulates the approach, landing, servicing, —**— and taking off of several flights. Each flight is in its own —**— thread, and is to be handled in a thread-safe fashion. —**— —**— —- —- —- —- —- —- —- —- —**— —**— Version 1.0 2018 August 1 Joseph Phillips —**— —**————————————————————————-*/
//// Compile with: g++ airport.cpp -o airport -lpthread//
#include #include #include #include #include #include
using namespace std;
// PURPOSE: To hold the names of the various airlinesconst char* AIRLINE_NAME_ARRAY[] = {“Air No Cares”, “Fly-By-Nite”, “Pterodactyl”, “SwineAir”, “Flying Toaster”, “Do You Dare Air”, “Air Montgolfier”, “Luft Zeppelin” };
// PURPOSE: To tell how many elements are in array ‘AIRLINE_NAME_ARRAY[]’.const int NUM_AIRLINES = sizeof(AIRLINE_NAME_ARRAY) / sizeof(const char*);
// PURPOSE: To tell how many Flight instances need to be serviced.const int NUM_FLIGHTS = 32;
// PURPOSE: To represent instances of a flight.class Flight{ // I. Member vars: // PURPOSE: To tell the name of flight. string name_;
// II. Disallowed auto-generated methods:
protected : // III. Protected methods:
public : // IV. Constructor(s), assignment op(s), factory(s) and destructor: // PURPOSE: To randomly generate a flight. No parameters. No return value. Flight () { char text[64];
snprintf(text,64,”%s %d”, AIRLINE_NAME_ARRAY[rand() % NUM_AIRLINES], (rand() % 9999)+1 ); name_ = text; }
// PURPOSE: To make ‘*this’ a copy of ‘source’. No return value. Flight (const Flight& source ) : name_(source.getName()) { } // PURPOSE: To release the resources of ‘*this’, make ‘*this’ a copy of // ‘source’, and return a reference to ‘*this’. No return value. Flight& operator= (const Flight& source ) { // I. Application validity check: if (this == &source) return(*this);
// II. Release resources:
// III. Copy ‘source’: name_ = source.getName();
// IV. Finished: return(*this); }
// PURPOSE: To release the resources of ‘*this’. No parameters. No return // value. ~Flight () { }
// V. Accessors: // PURPOSE: To return the name of the Flight. const string& getName () const { return(name_); }
};
// PURPOSE: To output Flight instance ‘flight’ to ‘os’. Returns reference to// ‘os’.ostream& operator