Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

Program(Need to override virtualcar functions in the old car class):

#include #include using namespace std;

//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 class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

Describe the accounting for a debt restructuring

Answered: 1 week ago

Question

1. Identify what positions are included in the plan.

Answered: 1 week ago

Question

How flying airoplane?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago