Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Virtual Class / Pointers Modify the program below to fit the requirements. Rating best/helpful solution a thumbs up! The code is posted below. Requirements:

C++ Virtual Class / Pointers

Modify the program below to fit the requirements.

Rating best/helpful solution a thumbs up! The code is posted below.

Requirements:

image text in transcribed

image text in transcribed

The Program :

Description: A program that can handle car sales and manage revenue. It can add/sell cars. It can set and get values that are private members through functions. #include  #include  using namespace std; class car { 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 }; class store { private: int revenue; //Revenue amoun 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 for Number of Cars int getRevenue() const; //Getter function for Revenue void acceptAmount(int amount); //Function to add to existing revenue }; //Car constructor: //Allows to set quantity, price, and model of car //when initialized. //Input: 3 Parameter Variables //Output: Object with set variables through parameter car::car(int quantity, int price, string model) { this->quantity = quantity; this->price = price; this->model = model; cout revenue = revenue; cout price = price; } //Car function - set_quantity: //Sets the quantity. //Input: An int //Output: Sets qunatity to the int variable void car::set_quantity(int quantity) { this->quantity = quantity; } //Store function - sell //Subtracts n from total_cars in inventory, //Subtracts total worth of car(s) from revenue (in assignment requirements). //Input: Car Object, N, Price //Output: Subtracts from total_cars and revenue, based on the parameters void store::sell(car& myCar, int n, int price) { total_cars = myCar.get_quantity(); myCar.set_quantity(total_cars - n); revenue = revenue - price; } //Store function - getNumberofCars //Returns number of cars. //Input: Car object //Output: Returns quantity of cars int store::getNumberofCars(car& obj) { return obj.get_quantity(); } //Store function - getRevenue //Returns the revenue. //Input: None //Output: Returns revenue int store::getRevenue() const { return revenue; } //Store function - acceptAmount //Adds a custom amount to the revenue //Input: An int //Output: Adds int to the amount void store::acceptAmount(int amount) { revenue += amount; } int main() { car honda(10, 25000, "Accord"); //Initialize car, ADD some cars to inventory store inventory(honda, 99999); //Initialize revenue to 0 or another amount cout   1) a. Create a new virtual class tha t acts like a parent class for your pre-existing car class and provides a base work for the entity of cars. Call you newly created virtual class your pre-existing car class name>Virtual The new virtual class that you create still has the same operations mentioned below. The goal is to modify the pre-existing car class (developed in assignment 3 and described in the next paragraph) to override the virtual class and add more criteria and pricing rules. Here are the least number of operations you need to develop in your newly created virtual class Get the price of the car o calculates the price same way as in Assignment 3, however, by leveraging pointers instead. Get the total worth of the cars o calculates the same way as in Assignment 3, however, by leveraging pointers instead. Set the Price of the car Set the quantity of the cars. b. Modify your pre-existing car class that accommodates the entity of car to create dynamic variables and dynamic arrays instead of regular variables and arrays. Use pointers wherever is possib retrieve address and content of pointer respectively. All you private members should be pointers that refer to the address of where your values are located. Use dynamic variables and dynamic arrays when necessary le, use & andto Once you have leveraged pointers, update your operations on this class to include some modifications. 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 o 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 o 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. a. Modify your pre-existing class that accommodates the entity of sales to create dynamic variables and dynamic arrays. Use pointers wherever possible to make your class as less dependent on direct variables as possible. Update dynamic variables/arrays whenever you are trying to add/remove some values. b. Create an abstract class for this class that shows all necessary pure virtual functions. Eventually, your pre- existing sales class should inherit this class and try to implement all the pure virtual functions that have been included in the abstract class. Call the abstract classAbstract and make sure you have the previous operations defined as pure virtual functions . Selling a car Get total number of cars in the inventory Get the revenue. Accept an amount into the revenue  1) a. Create a new virtual class tha t acts like a parent class for your pre-existing car class and provides a base work for the entity of cars. Call you newly created virtual class your pre-existing car class name>Virtual The new virtual class that you create still has the same operations mentioned below. The goal is to modify the pre-existing car class (developed in assignment 3 and described in the next paragraph) to override the virtual class and add more criteria and pricing rules. Here are the least number of operations you need to develop in your newly created virtual class Get the price of the car o calculates the price same way as in Assignment 3, however, by leveraging pointers instead. Get the total worth of the cars o calculates the same way as in Assignment 3, however, by leveraging pointers instead. Set the Price of the car Set the quantity of the cars. b. Modify your pre-existing car class that accommodates the entity of car to create dynamic variables and dynamic arrays instead of regular variables and arrays. Use pointers wherever is possib retrieve address and content of pointer respectively. All you private members should be pointers that refer to the address of where your values are located. Use dynamic variables and dynamic arrays when necessary le, use & andto Once you have leveraged pointers, update your operations on this class to include some modifications. 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 o 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 o 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. a. Modify your pre-existing class that accommodates the entity of sales to create dynamic variables and dynamic arrays. Use pointers wherever possible to make your class as less dependent on direct variables as possible. Update dynamic variables/arrays whenever you are trying to add/remove some values. b. Create an abstract class for this class that shows all necessary pure virtual functions. Eventually, your pre- existing sales class should inherit this class and try to implement all the pure virtual functions that have been included in the abstract class. Call the abstract classAbstract and make sure you have the previous operations defined as pure virtual functions . Selling a car Get total number of cars in the inventory Get the revenue. Accept an amount into the revenue

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

Step: 3

blur-text-image

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

Students also viewed these Databases questions