Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2-2. Define and implement a class named aircraft. An aircraft object represents

ID: 3709223 • Letter: 2

Question

2-2. Define and implement a class named aircraft. An aircraft object represents an aircraft with a pilot and a co-pilot. The pilot and co-pilot must be represented by person objects. The aircraft class has the following constructors and behaviours: // a pilot and copilot must be provided when creating an aircraft sircraft(string callsign,person thePilot,person theCoPilot) void setPilot(person thePilot)change the pilot person getPilot() void setcoPilot(person theCoPilot); change the co-pilot person getCoPilot); void printDetails // print the callsign, ? new line, the pilot nare, //a new line, the co-pilot nare and a final newline Your main program should create an aircraft object and three person objects. Two of the person objects must be passed to the constructor when the aircraft object is created. Your main program must then replace the pilot with the third person object, then replace the co-pilot with the original pilot

Explanation / Answer

#include <iostream>
using namespace std;

class person
{
private:
string firstName,lastName;

public:
person()//default constructor
{
firstName = " ";
lastName = " ";
}
person(string firstName,string lastName)//argument constructor
{
this->firstName = firstName;
this->lastName = lastName;
}
person(person &p)//copy constructor
{
firstName = p.firstName;
lastName = p.lastName;
}
//set and get methods
void setFirstName(string firstName)
{
this->firstName = firstName;
}

string getFirstName()
{
return firstName;
}

void setLastName(string lastName)
{
this->lastName = lastName;
}

string getLastName()
{
return lastName;
}

//operator overloading function for =
void operator =(person p)
{
this->firstName = p.firstName;
this->lastName = p.lastName;
}

};

class aircraft
{
private:
string callsign;
person thePilot,theCoPilot;

public:
aircraft(string callsign,person thePilot,person theCoPilot)//argument constructor
{
this->callsign = callsign;
this->thePilot = thePilot;
this->theCoPilot = theCoPilot;
}

//set and get methods
void setPilot(person thePilot)
{
this->thePilot = thePilot;
}

person getPilot()
{
return thePilot;
}

void setCoPilot(person theCoPilot)
{
this->theCoPilot = theCoPilot;
}

person getCoPilot()
{
return theCoPilot;
}

void printDetails()
{
cout<<callsign<<" "<<"Pilot : "<<thePilot.getFirstName()<<" "<<thePilot.getLastName()<<" "<<"CoPilot : "<<theCoPilot.getFirstName()<<" "<<theCoPilot.getLastName()<<" ";
}
};
int main() {

person p1("John","Anderson");

person p2("Andrew","Jones");

person p3("Cathy","Williams");

aircraft a("sign 1",p1,p2);


a.printDetails();

a.setPilot(p3);
a.printDetails();

a.setCoPilot(p1);
a.printDetails();
return 0;
}

Output:

sign 1
Pilot : John Anderson
CoPilot : Andrew Jones
sign 1
Pilot : Cathy Williams
CoPilot : Andrew Jones
sign 1
Pilot : Cathy Williams
CoPilot : John Anderson

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote