Question: c++ error code the main #include #include #include #include #include // Include header files for Airplane, CargoPlane and PassengerPlane classes #include Airplane.h #include Cargoplane.h #include

c++ error code

the main

#include #include #include #include #include

// Include header files for Airplane, CargoPlane and PassengerPlane classes #include "Airplane.h" #include "Cargoplane.h" #include "Passengerplane.h"

using namespace std; vector fleet;

// Function to print help text void print_help() { cout << "**Available Commands:**" << endl; cout << "* a [payload (optional)] - Add a new airplane" << endl; cout << "* f - Fly an airplane (not implemented yet)" << endl; cout << "* h - Print this help message" << endl; cout << "* P - Print information about all airplanes in the fleet" << endl; cout << "* q - Quit the application" << endl; cout << "* r - Remove an airplane from the fleet" << endl; }

// Function to find airplane by ID Airplane* find_airplane(const string& id) { for (Airplane* airplane : fleet){ if (airplane->get_id() == id) { return airplane; } } return nullptr; }

// Function to process user commands void process_command(const string& command) { istringstream stream(command); string cmd; if (!(stream >> cmd)) { cout << "Invalid command! Please try again." << endl; return; }

switch (cmd[0]) { case 'a': { // Add a new airplane string id, type; int range, capacity; int payload = 0; // Default for PassengerPlane if (!(stream >> id >> range >> capacity)) { cout << "Invalid arguments for command 'a'! Please refer to the help message." << endl; return; } if (stream >> payload) { type = "CargoPlane"; } else { type = "PassengerPlane"; }

if (find_airplane(id)) { cout << "Error: Airplane with ID '" << id << "' already exists!" << endl; return; }

if (type == "CargoPlane") { fleet.push_back(new CargoPlane(id, range, capacity, payload)); } else { fleet.push_back(new PassengerPlane(id, range, capacity,0)); } cout << "Airplane '" << id << "' added successfully!" << endl; break; } case 'f': { // Fly an airplane (not implemented yet) string id; if (!(stream >> id)) { cout << "Invalid arguments for command 'f'! Please refer to the help message." << endl; return; }

Airplane* airplane = find_airplane(id); if (!airplane) { cout << "Error: Airplane with ID '" << id << "' not found!" << endl; return; }

cout << "Flying airplane '" << id << "' (implementation TBD)" << endl; break; } case 'h': print_help(); break; case 'P': // Print information about all airplanes in the fleet if (fleet.empty()) { cout << "The fleet is currently empty." << endl; } else { cout << "**Fleet Information:**" << endl; for (Airplane* airplane : fleet) { airplane->print_info(); cout << endl; } } break; case 'q': // Quit the application cout << "Exiting the application..." << endl; exit(0); break;

case 'r': { // Remove an airplane from the fleet string id; if (!(stream >> id)) { cout << "Invalid arguments for command 'r'! Please refer to the help message." << endl; return; }

Airplane* airplane = find_airplane(id); if (!airplane) { cout << "Error: Airplane with ID '" << id << "' not found!" << endl; return; } else { fleet.erase(remove(fleet.begin(), fleet.end(), airplane), fleet.end()); delete airplane; cout << "Airplane '" << id << " ' removed from fleet." << endl; } break; } default: { cout << "Unknown command ' " << cmd << " ' ! Please try again." << endl; break; } } }

int main() { cout << "Welcome to the Airplane fleet Management System" << endl; print_help(); while (true) { cout << "> "; string command; getline(std::cin, command); process_command(command);

}

return 0;}

passngerplane file

#ifndef PASSENGERPLANE_H #define PASSENGERPLANE_H #include

#include "Airplane.h"

class PassengerPlane : public Airplane { public: PassengerPlane(std::string id, int range, int capacity, int classes); std::string get_type() const override { return "PassengerPlane"; } int get_classes() const { return classes_; } void print_info() const override { Airplane::print_info(); std::cout << "Classes: " << classes_ << " (e.g., First, Business, Economy)" << std::endl; }

private: int classes_; };

#endif

cargo file

#ifndef CARGOPLANE_H #define CARGOPLANE_H #include

#include "Airplane.h"

class CargoPlane : public Airplane { public: CargoPlane(std::string id, int range, int capacity, int max_payload); std::string get_type() const override { return "CargoPlane"; } int get_max_payload() const { return max_payload_; } void print_info() const override { Airplane::print_info(); std::cout << "Max Payload: " << max_payload_ << " tons" << std::endl; }

private: int max_payload_; };

#endif

airplane file

#ifndef AIRPLANE_H #define AIRPLANE_H #include

class Airplane { public: Airplane(std::string id, int range, int capacity); virtual std::string get_type() const { return "Airplane"; } std::string get_id() const { return id_; } int get_range() const { return range_; } int get_capacity() const { return capacity_; } virtual void print_info() const { std::cout << "ID: " << id_ << " (Type: " << get_type() << ")" << std::endl; std::cout << "Range: " << range_ << "km, Capacity: " << capacity_ << std::endl; }

private: std::string id_; int range_; int capacity_; };

#endif

how i name the file

the error code

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!