Home /
Expert Answers /
Other /
given-main-complete-the-car-class-in-files-carh-and-car-cpp-with-member-functions-to-set-and-get-the
(Answered): Given main(), complete the car class (in files Carh and Car.cpp) with member functions to set and g ...
Given main(), complete the car class (in files Carh and Car.cpp) with member functions to set and get the purchase price of a car (SetPurchasePrice. GetPurchasePrice), and to output the car's information (PrintInfo(). Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is: Car's information: Model year: 2011 Purchase price: 18000 Current value: 5770 Note: printinfo() should use three spaces for indentation 264692.1301946 LAB ACTIVITY 7.23.1: LAB1: Car value (classes) 0/10 File is marked as read only Current file: main.cpp 1 #include <iostream> 2 #include "Car.h" 3 using namespace std; 4 5 int main(int argc, const chart argv[]) { 6 int userYear: 7 int userPrice; 8 int userCurrent Year; 9 Car myCar; 10 11 cin >> userYear; 12 cin >> userPrice; 13 cin >> userCurrentYear; 14 15 myCar. SetModel Year(userYear); 16 myCar.SetPurchase Price(userPrice); 17 myCar CalcCurrentValue(userCurrent Year); 18 19 myCar PrintInfo(); 20 21 return; 22 } Current file: Car.cpp Load default template... 9 1 #include <iostream> 2 #include <math.h> 3 #include "Car.h" 4 using namespace std; 5 6 void Car::SetModel Year(int userYear){ 7 model Year - userYear; 8} 10 int Car::GetModel Year() const { 11 return model Year; 12 } 13 14 // TODO: Implement Set PurchasePrice() function 15 16 // TODO: Implement Get PurchasePrice() function 18 void Car::CalcCurrentValue(int currentYear) { double depreciationRate - 0.15; int carAge - current Year - model Year; 21 // Car depreciation formula currentValue - (int) 24 round(purchasePrice * pow((1 - depreciationRate), carAge)); 25} 17 19 20 22 23 26 27 // TODO: Implement PrintInfo() function to output model Year, purchasePrice, and 28 // currentValue Current file: Carh Load default template 1 #include <iostream> 2 3 using namespace std; 4 5 class Car 6 { 7 public: 8 int get PurchasePrice() const; 9 void setPurchasePrice(int price); 10 void calculateCurrentValue(int userCurrent Year); 11 void printInfo(); 12 void setModel Year(int year); 13 private: 14 int m_Model; 15 int m_PurchasePrice; 16 int m.CurrentValue; 17 };