Question
C++ Modify Functions, Function Overriding Rating helpful/best solution thumbs up! Code is provided below. Requirements: Program ( Need to override virtualcar functions in the old
C++ Modify Functions, Function Overriding
Rating helpful/best solution thumbs up! Code is provided below.
Requirements:
Program(Need to override virtualcar functions in the old car class):
#include
//NEW VIRTUAL CAR CLASS
class carVirtual { private: int *price; int *quantity; public: virtual int get_price() const { return *(this->price); } virtual int get_totalworth() { return *(this->quantity)* *(this->price); } virtual void set_price(int price) { *(this->price) = price; } virtual void set_quantity(int quantity) { *(this->quantity) = quantity; } };
//OLD CAR CLASS class car: public carVirtual { private: int *quantity; int *price; string *model; public: car(int quantity, int price, string model); //Constructor int get_price() const; //Getter function int get_totalworth() const; //Getter function void set_price(int); //Setter function void set_quantity(int); //Setter function int get_quantity() const; //Getter function };
//STORE CLASS (SALES) class store { private: int *revenue; //Revenue amount of company (PRIVATE) int *total_cars; //Total Cars in inventory (PRIVATE) public: friend class car; //Allows access to car members store(car& myCar, int revenue); //Constructor with parameters void sell(car& myCar, int quantity, int price); //Sell function int getNumberofCars(car& obj); //Getter function int getRevenue() const; //Getter function void acceptAmount(int amount); //Function to add to existing revenue };
//Car constructor: car::car(int quantity, int price, string model) { this->quantity = new int; *(this->quantity) = quantity;
this->price = new int; *(this->price) = price;
this->model = new string; *(this->model) = model; cout
//Store constructor: store::store(car& myCar, int revenue) { *(this->revenue) = revenue; cout
//Car function - get_price: int car::get_price() const { return *(this->price); }
//Car function - get_totalworth: int car::get_totalworth() const { return *(quantity)* *(this->price); }
//Car function - get_quantity: int car::get_quantity() const { return *(this->quantity); }
//Car function - set_price: void car::set_price(int price) { *(this->price) = price; }
//Car function - set_quantity: void car::set_quantity(int quantity) { *(this->quantity) = quantity; }
//Store function - sell void store::sell(car& myCar, int n, int price) { this->total_cars = new int; *total_cars = myCar.get_quantity();
myCar.set_quantity(*total_cars - n); *revenue = *revenue - price; }
//Store function - getNumberofCars int store::getNumberofCars(car& obj) { return obj.get_quantity(); }
//Store function - getRevenue int store::getRevenue() const { return (*revenue); }
//Store function - acceptAmount void store::acceptAmount(int amount) { *revenue += amount; }
int main() {
// car honda(10, 25000, "Accord"); //Initialize car, ADD some cars to inventory
// cout
return 0;
The goal is to override the following methods of the virtual class in the pre-existing car class and include more logic in the calculations Get the price of the car . override the virtual class and add 8.25% sales tax added to the price. Get the total worth of the cars override the virtual class and subtract 3% service fee from each car's price and calculate the new total worth based on the new value Finally, update your references anywhere inside the main function or other classes to call the newly created virtual class instead of the pre-existing car classStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started