Question: main.cpp #include #include Car.h using namespace std; int main() { int userYear; int userPrice; int userCurrentYear; /*TODO: Declare a pointer variable myCar to a Car

main.cpp
#include
int main() { int userYear; int userPrice; int userCurrentYear; /*TODO: Declare a pointer variable myCar to a Car object*/ /* Call the mutator functions and then the PrintInfo function*/ return 0; }
Car.cpp
#include
//default constructor Car::Car() { modelYear = 0; purchasePrice = 0; currentValue = 0; }
//setter for modelYear void Car::SetModelYear(int userYear){ modelYear = userYear; }
//getter for modelYear int Car::GetModelYear() const { return modelYear; }
//setter for purchasePrice void Car::SetPurchasePrice(int userPrice){ purchasePrice = userPrice; }
int Car::GetPurchasePrice() const { return purchasePrice; }
void Car::CalcCurrentValue(int currentYear) { double depreciationRate = 0.15; int carAge = currentYear - modelYear; // Car depreciation formula currentValue = (int) round(purchasePrice * pow((1 - depreciationRate), carAge)); }
void Car::PrintInfo() const { cout
Car.h
#ifndef CARH #define CARH
class Car { private: int modelYear; int purchasePrice; int currentValue; public: Car(); void SetModelYear(int userYear); int GetModelYear() const; void SetPurchasePrice(int userPrice); int GetPurchasePrice() const; void CalcCurrentValue(int currentYear); void PrintInfo() const; };
#endif
Given the Car class (in files Car.h and Car.cpp) with a default constructor, and member functions to set and get the purchase price of a car (SetPurchasePrice(), GetPurchasePrice()), and a PrintInfo() function to output the car's information complete main() to do the following: - Declare a pointer to a Car object called myCar, allocate memory and call the default constructor. - Then call the mutator functions to set the values for modelYear, purchasePrice, currentvalue - Then call the PrintInfo function to print the values for the Car object. Ex: If the input is: 2011180002018 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
