Questions
Questions

COSC 1437 - 15099 - Introduction to Programming

Unknown Question Type

Question textFor this programming question, you will be working with Polymorphism. Given the base abstract class "airplane", the derived classes "passenger" and "cargo", and the container class "airport" (defined in airport.h): #ifndef AIRPORT_H#define AIRPORT_H #include "airplane.h"#include "passenger.h"#include "cargo.h" #include <vector>#include <string> using namespace std; class airport{private: string city; string code; vector<airplane *> airplanes; public: airport(const string &_city, const string &_code); airport(const airport &RHS); airport &operator=(const airport &RHS); ~airport(); void add_airplane(const airplane &plane); void summary() const; void list_airplanes() const;}; #endif Modify the base class airplane and the derived classes passenger and cargo (following the comments in the provided template files), and write the implementation of the member functions summary and list_airplanes. Here is the implementation of the other member functions of the "airport" class: airport::airport(const string &_city, const string &_code){ city = _city; code = _code;} airport::airport(const airport &RHS){ city = RHS.city; code = RHS.code; for (airplane *plane : RHS.airplanes) {  if (plane != nullptr) {  airplane *temp_plane; if (plane->get_type() == 'P') {  temp_plane = new passenger(*((passenger *)plane)); }  else {  temp_plane = new cargo(*((cargo *)plane)); }  airplanes.push_back(temp_plane); }  }} airport &airport::operator=(const airport &RHS){ if (this != &RHS) {  city = RHS.city; code = RHS.code; if (airplanes.size() > 0) // Delete allocated memory {  for (int i = airplanes.size() - 1; i >= 0; i--) {  if (airplanes.at(i) != nullptr) {  delete airplanes.at(i); airplanes.pop_back(); }  }  }  for (airplane *plane : RHS.airplanes) {  if (plane != nullptr) {  airplane *temp_plane; if (plane->get_type() == 'P') {  temp_plane = new passenger(*((passenger *)plane)); }  else {  temp_plane = new cargo(*((cargo *)plane)); }  airplanes.push_back(temp_plane); }  }  }  return *this;} airport::~airport(){ if (airplanes.size() > 0) // Delete allocated memory {  for (int i = airplanes.size() - 1; i >= 0; i--) {  if (airplanes.at(i) != nullptr) {  delete airplanes.at(i); airplanes.pop_back(); }  }  }} void airport::add_airplane(const airplane &plane){ airplane *temp_plane; if (plane.get_type() == 'P') {  temp_plane = new passenger((const passenger &)plane); }  else {  temp_plane = new cargo((const cargo &)plane); }  airplanes.push_back(temp_plane);} HINT: You can use the code from these functions when writing the solution for the requested member functions. NOTES: You can safely assume that the input is always correct. You must use function identifiers based on the specifications of the question when writing your solution. You do not need to write a main function. Solutions that do not compile will receive a 100 % penalty. Hardcoding the output will translate into a 100 % penalty. Answer:(penalty regime: 0 %){"airplane_h":["// airplane.h\n#ifndef AIRPLANE_H\n#define AIRPLANE_H\n\n#include <string>\n#include <iostream>\nusing namespace std;\n\nclass airplane {\nprivate:\n string manufacturer;\n string model;\n string tail_number;\npublic:\n airplane(const string& _manufacturer, const string& _model, const string& _tail_number)\n : manufacturer(_manufacturer), model(_model), tail_number(_tail_number) {}\n virtual char get_type() const = 0;\n virtual void print() const {\n cout << \"Manufacturer: \" << manufacturer\n << \", Model: \" << model\n << \", Tail number: \" << tail_number;\n }\n virtual ~airplane() {}\n};\n\n#endif\n\n\n"],"passenger_h":["#ifndef PASSENGER_H\n#define PASSENGER_H\n\n#include \"airplane.h\"\n#include <iostream>\n#include <string>\nusing namespace std;\n\n// Implement public inheritance from the airplane class\n// Call the overloaded constructor of the base class in the class overloaded constructor\n// Use the virtual qualifier when needed\n\nclass passenger // Implement public inheritance from the airplane class \n{\n private:\n string airline;\n int n_passengers;\n public:\n passenger(const string & _manufacturer, const string & _model, \n const string & _tail_number, const string & _airline, int _n_passengers):\n // Call the overloaded constructor of the base class here\n {\n airline = _airline;\n n_passengers = _n_passengers;\n }\n ~passenger(){}\n char get_type() const {return 'P';}\n void print() const\n {\n airplane::print();\n cout << \", Airline: \" << airline <<\n \", # of passengers: \" << n_passengers << endl;\n }\n};\n\n#endif"],"cargo_h":["#ifndef CARGO_H\n#define CARGO_H\n\n#include \"airplane.h\"\n#include <iostream>\nusing namespace std;\n\n// Implement public inheritance from the airplane class\n// Call the overloaded constructor of the base class in the class overloaded constructor\n// Use the virtual qualifier when needed\n\nclass cargo // Implement public inheritance from the airplane class \n{\n private:\n string company;\n int max_capacity;\n public:\n cargo(const string & _manufacturer, const string & _model, \n const string & _tail_number, const string & _company, int _max_capacity):\n // Call the overloaded constructor of the base class here\n {\n company = _company;\n max_capacity = _max_capacity;\n }\n ~cargo(){}\n char get_type() const {return 'C';}\n void print() const\n {\n airplane::print();\n cout << \", Company: \" << company <<\n \", Max Capacity (tons): \" << max_capacity << endl;\n }\n};\n\n#endif"],"airport_cpp":["// Include the libraries to run compile your solution\n#include \"airport.h\"\n#include <iostream>\nusing namespace std;\n\n\n// Write the implementation of the requested member functions \nvoid airport::summary const\n{\n int num_passenger = 0, num_cargo = 0;\n for (size_t i=0, i < airplanes.size(); ++i)\n {\n if (airplane[i])\n {\n if (airplane[i]) get_type() - > == 'P'\n num_passenger ++;\n else (airplane[i]) get_type() - > == \"C\"\n num_cargo ++;\n }\n cout <<\"Airport city: \" << city << endl;\n cout <<\"Airport code: \" << code << endl;\n cout <<\"# Passeneger airplanes:\" << num_passenger << endl;\n cout <<\"# Cargo airplanes:\" << num_cargo << endl;\n}\n\nvoid airport::list_airplane() const\n{\n cout <<\"Passenger airplanes:\" endl;\n for (size_t i=0 i < airplane.size(); ++1\n {\n if (airplane[i] && airplane[i] - > get_type() == 'P')\n airplane[i]- > print();\n }\n cout <<\"Cargo airplanes:\" << endl;\n for (size_t i=0, i < airplanes.size(); ++1)\n {\n if (airplane[i] && airplane[i] - > get_type() == 'C')\n airplane[i] - > print();\n }\n}\n\n// Output messages for the summary function\n// cout << \"Airport city: \" << /* variable identifier */ << endl;\n// cout << \"Airport code: \" << /* variable identifier */ << endl;\n// cout << \"# Passenger airplanes: \" << /* variable identifier */ << endl;\n// cout << \"# Cargo airplanes: \" << /* variable identifier */ << endl;\n\n// Output messages for the list_airplanes function\n// cout << \"Passenger airplanes: \" << endl;\n// cout << \"Cargo airplanes: \" << endl;\n\n// I need you to modify the give code for airport.cpp\n"]} Code for airplane.h 1234567891011121314151617181920212223242526272829// airplane.h#ifndef AIRPLANE_H#define AIRPLANE_H#include <string>#include <iostream>using namespace std;class airplane {private: string manufacturer; string model; string tail_number;public: airplane(const string& _manufacturer, const string& _model, const string& _tail_number) : manufacturer(_manufacturer), model(_model), tail_number(_tail_number) {} virtual char get_type() const = 0; virtual void print() const { cout << "Manufacturer: " << manufacturer << ", Model: " << model << ", Tail number: " << tail_number; } virtual ~airplane() {}};#endif ההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Code for passenger.h 123456789101112131415161718192021222324252627282930313233343536#ifndef PASSENGER_H#define PASSENGER_H#include "airplane.h"#include <iostream>#include <string>using namespace std;// Implement public inheritance from the airplane class// Call the overloaded constructor of the base class in the class overloaded constructor// Use the virtual qualifier when neededclass passenger // Implement public inheritance from the airplane class { private: string airline; int n_passengers; public: passenger(const string & _manufacturer, const string & _model, const string & _tail_number, const string & _airline, int _n_passengers): // Call the overloaded constructor of the base class here { airline = _airline; n_passengers = _n_passengers; } ~passenger(){} char get_type() const {return 'P';} void print() const { airplane::print(); cout << ", Airline: " << airline << ", # of passengers: " << n_passengers << endl; }};#endif ההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Code for cargo.h 1234567891011121314151617181920212223242526272829303132333435#ifndef CARGO_H#define CARGO_H#include "airplane.h"#include <iostream>using namespace std;// Implement public inheritance from the airplane class// Call the overloaded constructor of the base class in the class overloaded constructor// Use the virtual qualifier when neededclass cargo // Implement public inheritance from the airplane class { private: string company; int max_capacity; public: cargo(const string & _manufacturer, const string & _model, const string & _tail_number, const string & _company, int _max_capacity): // Call the overloaded constructor of the base class here { company = _company; max_capacity = _max_capacity; } ~cargo(){} char get_type() const {return 'C';} void print() const { airplane::print(); cout << ", Company: " << company << ", Max Capacity (tons): " << max_capacity << endl; }};#endif ההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Code for airport.cpp 234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include "airport.h"#include <iostream>using namespace std;// Write the implementation of the requested member functions void airport::summary const{ int num_passenger = 0, num_cargo = 0; for (size_t i=0, i < airplanes.size(); ++i) { if (airplane[i]) { if (airplane[i]) get_type() - > == 'P' num_passenger ++; else (airplane[i]) get_type() - > == "C" num_cargo ++; } cout <<"Airport city: " << city << endl; cout <<"Airport code: " << code << endl; cout <<"# Passeneger airplanes:" << num_passenger << endl; cout <<"# Cargo airplanes:" << num_cargo << endl;}void airport::list_airplane() const{ cout <<"Passenger airplanes:" endl; for (size_t i=0 i < airplane.size(); ++1 { if (airplane[i] && airplane[i] - > get_type() == 'P') airplane[i]- > print(); } cout <<"Cargo airplanes:" << endl; for (size_t i=0, i < airplanes.size(); ++1) { if (airplane[i] && airplane[i] - > get_type() == 'C') airplane[i] - > print(); }}// Output messages for the summary function// cout << "Airport city: " << /* variable identifier */ << endl;// cout << "Airport code: " << /* variable identifier */ << endl;// cout << "# Passenger airplanes: " << /* variable identifier */ << endl;// cout << "# Cargo airplanes: " << /* variable identifier */ << endl;// Output messages for the list_airplanes function// cout << "Passenger airplanes: " << endl;// cout << "Cargo airplanes: " << endl;// I need you to modify the give code for airport.cpp ההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX M.util.js_pending('qtype_coderunner/userinterfacewrapper'); require(['qtype_coderunner/userinterfacewrapper'], function(amd) { amd.newUiWrapper("ace", "id_q55064:2_answer-ace_field1"); M.util.js_complete('qtype_coderunner/userinterfacewrapper'); }); M.util.js_pending('qtype_coderunner/userinterfacewrapper'); require(['qtype_coderunner/userinterfacewrapper'], function(amd) { amd.newUiWrapper("ace", "id_q55064:2_answer-ace_field2"); M.util.js_complete('qtype_coderunner/userinterfacewrapper'); }); M.util.js_pending('qtype_coderunner/userinterfacewrapper'); require(['qtype_coderunner/userinterfacewrapper'], function(amd) { amd.newUiWrapper("ace", "id_q55064:2_answer-ace_field3"); M.util.js_complete('qtype_coderunner/userinterfacewrapper'); }); M.util.js_pending('qtype_coderunner/userinterfacewrapper'); require(['qtype_coderunner/userinterfacewrapper'], function(amd) { amd.newUiWrapper("ace", "id_q55064:2_answer-ace_field4"); M.util.js_complete('qtype_coderunner/userinterfacewrapper'); }); Check Question 1

Question Image
View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
The prompt presents a programming question about polymorphism with base class airplane and derived classes passenger and cargo, plus an airport container class. It asks to modify the base class and derived classes and implement the summary and list_airplanes member functions in airport, and it provides snippets of code for airplane.h, passenger.h, cargo.h, and airport.h along with some sample implementations. However, when extracting the specific answer choices for a multiple-choice analysis, there are no options provided in the given data. The field answer_options is present but contains an empty value, which means there is no set of potential answers to evaluate one by one. This prevents performing a traditional option-by-......Login to view full explanation

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

Similar Questions

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!