Question: Written in C++ not java. Write a driver program which contains a vector of pointers to BasicTicket objects. Create some BasicTicket and PremiumTicket objects and

Written in C++ not java. Write a driver program which contains a vector of pointers to BasicTicket objects. Create some BasicTicket and PremiumTicket objects and add them into the vector. Write a simple function to add the cost of all the tickets in the vector. Manually compute and ensure that the sum returned by your function is correct. If it is incorrect, check that you are using the virtual keyword correctly in your BasicTicket class im not sure if it's referring to the previous question but here is my code for the previous question using the same. BasicTicket.h

#ifndef CHAPTER15_PROP2_BASICTICKET_H

#define CHAPTER15_PROP2_BASICTICKET_H

#include

#include

class BasicTicket {

std::string name;

std::string departureCity;

std::string arrivalCity;

std::string flightNum;

double price;

public:

BasicTicket( std::string str, std::string dc, std::string ac, std::string fNum, double amt);

virtual double getPrice();

};

#endif //CHAPTER15_PROP2_BASICTICKET_H

BasicTicket.cppfile

#include "BasicTicket.h"

BasicTicket::BasicTicket(std::string str, std::string dc, std::string ac, std::string fNum, double amt) {

name = str;

departureCity = dc;

arrivalCity = ac;

flightNum = fNum;

price = amt;

}

double BasicTicket::getPrice() {

return price;

}

PremiumTicket.H

#ifndef CHAPTER15_PROP2_PREMIUMTICKET_H

#define CHAPTER15_PROP2_PREMIUMTICKET_H

#include "BasicTicket.h"

class PremiumTicket : public BasicTicket {

public:

PremiumTicket(std:: string str,std:: string dc,std:: string ac,std:: string fNum,double amt,int seat);

double getPrice();

private:

int seat_no;

};

#endif //CHAPTER15_PROP2_PREMIUMTICKET_H

PremiumTicket.cpp

#include "PremiumTicket.h"

PremiumTicket::PremiumTicket(std::string str, std::string dc, std::string ac, std::string fNum, double amt, int seat)

: BasicTicket(str, dc, ac, fNum, amt){

seat_no = seat;

}

double PremiumTicket::getPrice() {

double amt = BasicTicket::getPrice();

return (amt + (amt * 10) / 100);;

}

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 Programming Questions!