Question

In: Computer Science

In C++, Designe a ticketing system for an airline in which there will be multiple flights,...

In C++,

Designe a ticketing system for an airline in which there will be multiple flights, all containing passengers. Our airline prides itself on the fact that pets may fly in seats if the customer purchases a full ticket for the pet (note, it is not necessary for the customer to accompany the pet on the flight). Thus, any seat may be occupied by a pet or by a person either of which is considered a passenger. Please design the following classes as well as any other classes which you deem necessary:

a. Flight. The flight will hold a vector (this must be a single vector, not two) of passengers, and should have a function for adding passengers as well as a function to calculate the total revenue for the entire flight. The revenue is the sum of all ticket prices on the flight.

b. Person. This class will have a function “getTicketCost” which will return how much the person paid for the ticket. The cost will be determined when the ticket is created and will be different for each person.

c. Pet. This class will have a function “getTicketCost” which will return how much the pet paid for the ticket. The cost will be determined when the ticket is created and will be different for each pet.

Solutions

Expert Solution

Code:

#include <iostream>

using namespace std;

class Passenger
{
protected:
   string m_name;
   string m_id;
   int m_age;
   int milesTravelling;
public:
   Passenger(string name, int age, string id, int miles)
   {
       m_name = name;
       m_age = age;
       m_id = id;
       milesTravelling = miles;
   }
   virtual int getTicketCost() = 0;
};

class Person : public Passenger
{
public:
   Person(string name,int age,string id,int miles):Passenger(name
   ,age,id,miles)
   {
      
   }
   int getTicketCost() override
   {
       if (m_age < 20)
           return milesTravelling * 120;
       return milesTravelling * 150;
   }
};

class Pet : public Passenger
{
public:
   Pet(string name, int age, string id, int miles) :Passenger(name
       , age, id, miles)
   {

   }
   int getTicketCost() override
   {
       if (m_age < 5)
           return milesTravelling * 80;
       return milesTravelling * 120;
   }
};
class Flight
{
   vector<Passenger*> passengers;
public:
   void addPassenger(Passenger* p)
   {
       passengers.push_back(p);
   }
   int calculateTotalRevenue()
   {
       int totalRevenue = 0;
       for(auto& p : passengers)
       {
           totalRevenue += p->getTicketCost();
       }

       return totalRevenue;
   }
};

int main()
{
   Flight f;
   Person person("A", 23, "12", 125);
   Pet apet("B", 15, "13", 140);
   Passenger& p1 = person;
   Passenger& p2 = apet;
   f.addPassenger(&p1);
   f.addPassenger(&p2);
   cout << "Total Revenue : " << f.calculateTotalRevenue();
   return 0;
}

OUTPUT:


Related Solutions

There was an SRS of 100 flights on a large airline (airline 1) that showed that...
There was an SRS of 100 flights on a large airline (airline 1) that showed that 64 of the flights were on time. An SRS of 100 flights of another large airline (airline 2) showed that 80 of the flights were on time. Let p1 and p2 be the proportion of all flights that are on time for these two airlines. What is a 95% confidence interval for the difference p1-p2? (-.222, -.098) (-.263, -.057) (-.218, -.102) (-.283, -.038) (.098,...
An SRS of 100 flights of a large airline (call this airline 1) showed that 64...
An SRS of 100 flights of a large airline (call this airline 1) showed that 64 were on time. An SRS of 100 flights of another large airline (call this airline 2) showed that 80 were on time. Let p1 and p2 be the proportion of all flights that are on time for these two airlines. Reference: Ref 8-10 You wish to determine whether there is evidence of a difference in the on-time rate for the two airlines? To determine...
A simple random sample of 100 flights of a large airline (call this airline 1) showed...
A simple random sample of 100 flights of a large airline (call this airline 1) showed that 64 were on time. A simple random sample of 100 flights of another large airline (call this airline 2) showed that 80 were on time. Let p1 and p2 be the proportion of all flights that are on time for these two airlines. 21.Suppose we wish to conduct the test at a 10% significance level. What would our decision be? Based on that...
A. According to an airline, flights on a certain route are NOT on time 15% of...
A. According to an airline, flights on a certain route are NOT on time 15% of the time. Suppose 10 flights are randomly selected and the number of NOT on time flights is recorded. Find the probability of the following question. At least 3 flights are not on time. B. According to an airline, flights on a certain route are NOT on time 15% of the time. Suppose 10 flights are randomly selected and the number of NOT on time...
The airline carriers schedule the flights between pairs of cities through the shortest routes. Two airline...
The airline carriers schedule the flights between pairs of cities through the shortest routes. Two airline carriers are called equivalent if they offer the flights between the same pairs of cities. Design an algorithm with less than cubic time complexity to compare whether two given airline carriers are equivalent or not. Direct and connecting flights are not differentiated here.
According to an airline, flights on a certain route are on time 80% of the time....
  According to an airline, flights on a certain route are on time 80% of the time. Suppose 20 fights are randomly selected and the number of on-time flights is recorded  (a) Explain why this is a binomial experiment  (b) Find and interpret the probability that exactly 12 flights are on time.  (c) Find and interpret the probability that fewer than 12 flights are on time  (d) Find and interpret the probability that at least 12 flights are on time ...
According to an airline, flights on a certain route are on time 75% of the time
According to an airline, flights on a certain route are on time 75% of the time. Suppose 24 flights are randomly selected and the number of on-time flights is recorded. (a) Explain why this is a binomial experiment. (b) Find and interpret the probability that exactly 15 lights are on time (c) Find and interpret the probability that fewer than 15 flights are on time (d) Find and interpret the probability that at least 15 fights are on time. (e)...
According to an​ airline, flights on a certain route are on time 8080​% of the time....
According to an​ airline, flights on a certain route are on time 8080​% of the time. Suppose 1515 flights are randomly selected and the number of​ on-time flights is recorded. ​(a) Explain why this is a binomial experiment. ​(b) Find and interpret the probability that exactly 99 flights are on time. ​(c) Find and interpret the probability that fewer than 99 flights are on time. ​(d) Find and interpret the probability that at least 99 flights are on time. ​(e)...
According to an? airline, flights on a certain route are on time 80?% of the time....
According to an? airline, flights on a certain route are on time 80?% of the time. Suppose 13 flights are randomly selected and the number of? on-time flights is recorded. ?(a) Explain why this is a binomial experiment. ?(b) Find and interpret the probability that exactly 8 flights are on time. ?(c) Find and interpret the probability that fewer than 8 flights are on time. ?(d) Find and interpret the probability that at least 8 flights are on time. ?(e)...
According to an​ airline, flights on a certain route are on time 80​% of the time....
According to an​ airline, flights on a certain route are on time 80​% of the time. Suppose 10 flights are randomly selected and the number of​ on-time flights is recorded. ​(a) Explain why this is a binomial experiment. (options provided below)​ A.There are two mutually exclusive​ outcomes, success or failure. B.The probability of success is different for each trial of the experiment. C.Each trial depends on the previous trial. D.There are three mutually exclusive possibly​ outcomes, arriving​ on-time, arriving​ early,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT