Write program in C++ using inhertiance and polymorphism. A car dealership wants you to keep track of their sold and leased vehicles. You have realized that all vehicles have a make, model and vehicle identification number so you are going to factor those attributes out and put them in the base class as private attributes. Additionally you realize that you need to create two derived classes: one that keeps track of vehicles that are sold and the other that keeps track of ones that are leased. Vehicles that are sold have a sale date and sale amount. Vehicles that are leased have a monthly lease payment and terms of the lease (number of years). For all classes, create a proper overloaded constructor and display method that properly displays the class’s attributes. For your display method make sure you are using proper run-time polymorphism techniques so that your code calls the correct display methods. Complete main.cpp and follow comments for instruction Given code of .cpp and .h classes attached below

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

Write program in C++ using inhertiance and polymorphism.

A car dealership wants you to keep track of their sold and leased vehicles. You have realized that all vehicles have a make, model and vehicle identification number so you are going to factor those attributes out and put them in the base class as private attributes. Additionally you realize that you need to create two derived classes: one that keeps track of vehicles that are sold and the other that keeps track of ones that are leased.

Vehicles that are sold have a sale date and sale amount. Vehicles that are leased have a monthly lease payment and terms of the lease (number of years).

For all classes, create a proper overloaded constructor and display method that properly displays the class’s attributes. For your display method make sure you are using proper run-time polymorphism techniques so that your code calls the correct display methods. Complete main.cpp and follow comments for instruction

Given code of .cpp and .h classes attached below

Current file: main.cpp
Load default template
1 #include "Vehicle.h"
2 #include "SoldVehicle.h"
3 #include "LeasedVehicle.h"
4 #include siostream>
5 #include <vector>
7 using namespace std;
8
9 int main() {
// Creating Sold Vehicles...
cout <« "--Vehicle Inventory--\n" << endl;
10
11
12
vector<Vehicle *> vehicles;
// Example Sold Vehicle provided for you with an overloaded constructor (Overloaded Constructor not defined for you).
SoldVehicle * sv1 = new SoldVehicle("Chevy", "Equinox", "1111", "10/10/2019", 30000);
vehicles.push_back(sv1);
13
14
15
16
17
/* Add the rest of the vehicles to vehicles vector
18
19
Each vehicle must be created on the HEAP.
20
*/
21
22
/* Iterate through vehicles vector and display each vehicle. */
23
24
return 0;
25 }
26
Current file: Vehicle.h
1 #ifndef VEHICLES_H
2 #define VEHICLES_H
3
4 #include <string>
5
6 using std::string;
7
8 class Vehicle {
9 public:
Vehicle();
10
11
/* Add overloaded Vehicle Constructor and a virtual display method here */
12
13 private:
string make;
string model;
string vin;
14
15
16
17 };
18
19 #endif
Current file: Vehicle.cpp
1 #include "Vehicle.h"
2 #include <string>
3 #include <iostream>
4
5 using std::string;
6 using std::cout;
7 using std::endl;
9 Vehicle::Vehicle() {
10
|11
12
13 }
make
model =
vin =
14
15 /* Implementation for additional methods here */
Transcribed Image Text:Current file: main.cpp Load default template 1 #include "Vehicle.h" 2 #include "SoldVehicle.h" 3 #include "LeasedVehicle.h" 4 #include siostream> 5 #include <vector> 7 using namespace std; 8 9 int main() { // Creating Sold Vehicles... cout <« "--Vehicle Inventory--\n" << endl; 10 11 12 vector<Vehicle *> vehicles; // Example Sold Vehicle provided for you with an overloaded constructor (Overloaded Constructor not defined for you). SoldVehicle * sv1 = new SoldVehicle("Chevy", "Equinox", "1111", "10/10/2019", 30000); vehicles.push_back(sv1); 13 14 15 16 17 /* Add the rest of the vehicles to vehicles vector 18 19 Each vehicle must be created on the HEAP. 20 */ 21 22 /* Iterate through vehicles vector and display each vehicle. */ 23 24 return 0; 25 } 26 Current file: Vehicle.h 1 #ifndef VEHICLES_H 2 #define VEHICLES_H 3 4 #include <string> 5 6 using std::string; 7 8 class Vehicle { 9 public: Vehicle(); 10 11 /* Add overloaded Vehicle Constructor and a virtual display method here */ 12 13 private: string make; string model; string vin; 14 15 16 17 }; 18 19 #endif Current file: Vehicle.cpp 1 #include "Vehicle.h" 2 #include <string> 3 #include <iostream> 4 5 using std::string; 6 using std::cout; 7 using std::endl; 9 Vehicle::Vehicle() { 10 |11 12 13 } make model = vin = 14 15 /* Implementation for additional methods here */
Current file: SoldVehicle.h -
1 #ifndef SOLDVEHICLES_H
2 #define SOLDVEHICLES_H
4 #include "Vehicle.h"
5 #include <string>
6
7 using std::string;
8
9 class SoldVehicle: public Vehicle {
10 public:
11
12
13
14 private:
15
16
17 };
18
19 #endif
SoldVehicle();
/* Add additional methods here */
string saleDate;
double saleAmount;
Current file: SoldVehicle.cpp
1 #include "SoldVehicle.h"
2 #include <string>
3 #include siostream>
4
5 using std: :string;
6 using std::cout;
7 using std::endl;
8
9 SoldVehicle::SoldVehicle(): Vehicle() {
10
11
12 }
13
14 /* Implementation for additional methods here */
15
16
saleDate = "";
saleAmount = 0;
17
Current file: LeasedVehicle.h
1 #ifndef LEASEDVEHICLES_H
2 #define LEASEDVEHICLES_H
3
4 #include "Vehicle.h"
5 #include <string>
7 using std::string;
8
9 class LeasedVehicle: public Vehicle {
10 public:
11
12
13
14 private:
15
16
17 };
18
19 #endif
LeasedVehicle();
/* Add other methods / constructors here */
double payment; // monthly lease payment
int terms; // number of years
Current file: LeasedVehicle.cpp
1 #include "LeasedVehicle.h"
2 #include <string>
3 #include <iostream>
4
5 using std::string;
6 using std::cout;
7 using std::endl;
8
9 LeasedVehicle::LeasedVehicle(): Vehicle() {
payment = 0.0;
terms = 0;
10
11
12 }
13
14 /* Implementation for additional methods here */
Transcribed Image Text:Current file: SoldVehicle.h - 1 #ifndef SOLDVEHICLES_H 2 #define SOLDVEHICLES_H 4 #include "Vehicle.h" 5 #include <string> 6 7 using std::string; 8 9 class SoldVehicle: public Vehicle { 10 public: 11 12 13 14 private: 15 16 17 }; 18 19 #endif SoldVehicle(); /* Add additional methods here */ string saleDate; double saleAmount; Current file: SoldVehicle.cpp 1 #include "SoldVehicle.h" 2 #include <string> 3 #include siostream> 4 5 using std: :string; 6 using std::cout; 7 using std::endl; 8 9 SoldVehicle::SoldVehicle(): Vehicle() { 10 11 12 } 13 14 /* Implementation for additional methods here */ 15 16 saleDate = ""; saleAmount = 0; 17 Current file: LeasedVehicle.h 1 #ifndef LEASEDVEHICLES_H 2 #define LEASEDVEHICLES_H 3 4 #include "Vehicle.h" 5 #include <string> 7 using std::string; 8 9 class LeasedVehicle: public Vehicle { 10 public: 11 12 13 14 private: 15 16 17 }; 18 19 #endif LeasedVehicle(); /* Add other methods / constructors here */ double payment; // monthly lease payment int terms; // number of years Current file: LeasedVehicle.cpp 1 #include "LeasedVehicle.h" 2 #include <string> 3 #include <iostream> 4 5 using std::string; 6 using std::cout; 7 using std::endl; 8 9 LeasedVehicle::LeasedVehicle(): Vehicle() { payment = 0.0; terms = 0; 10 11 12 } 13 14 /* Implementation for additional methods here */
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning