Answer to Question #206232 in C++ for Ahmed Ali

Question #206232

Write a C++ Program on Airline Reservation System using classes and inheritance concept. And other C++ statements also like if, if-else, switch, loops, functions, etc.

The Output Should include:


1) Book Flight (domestic and international)

2) Cancel Flight

3) Check Flight Status

4) Exit


1
Expert's answer
2021-06-12T10:40:42-0400
#include <iostream>

class Ticket {
private:
  std::string owner;
  int price;
public:
  Ticket(std::string owner, int price) 
  {
    this->owner = owner;
    this->price = price;
  }
  std::string status;
};

class DomesticTicket : public Ticket {
private:
  std::string type;
public:
  DomesticTicket(std::string owner, int price) : Ticket(owner, price)
  {
    this->type = "'domestic'";
  }
};

class InternationalTicket : public Ticket {
private:
  std::string type;
public:
  InternationalTicket(std::string owner, int price) : Ticket(owner, price)
  {
    this->type = "'international'";
  }
};

int main()
{
  std::map<std:::string, Ticket> airport;
  while(true)
  {
    std::cout << "1) Book Flight (domestic and international)" << std::endl;
    std::cout << "2) Cancel Flight" << std::endl;
    std::cout << "3) Check Flight Status" << std::endl;
    std::cout << "4) Exit" << std::endl;
    int choise;
    std::cin >> choise;
    switch(choise) {
      case 1:
        std::string name;
        std::cout << "Enter your name: "
        std::cin >> name;
        std::cout << "1) Domestic" << std::endl;
        std::cout << "2) International" << std::endl;
        int type;
        std::cin >> type;
        if (type == 1)
          airport.insert(name, DomesticTicket(name, 49));
        if (type == 2)
          airport.insert(name, InternationalTicket(name, 99));
        std::cout << "Successfully!" << std::endl;
        break;
      case 2:
        std::string name;
        std::cout << "Enter your name: ";
        std::cin >> name;
        airport.remove(name);
        std::cout << "Successfully!" << std::endl;
        break;
      case 3:
        std::string name;
        std::cout << "Enter your name: ";
        std::cin >> name;
        auto it = airport.find(name);
        if (it != airport.end())
          std::cout << "Status: " << (*it).status << std::endl;
        else
          std::cout << "Unsuccessfully!" << std::endl;
        break;
      case 4:
        std::cout << "Exis System..." << std::endl;
        return 0;
      default:
        std::cout << "oops.." << std::endl;
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog