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
#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;
}
}
}
Comments
Leave a comment