Question
Solve in C++ for Car.h and Car.cpp

8.21 LAB: Car value (classes) Given main, complete the Car class (in files Car hand Car.cpp) with member functions to set and
LAB ACTIVITY 8.21.1 LAB Car value (classes) Ourrent file Carh Load 1 mifndef CARH #define CARH 4 class Car ( private: int mod
ACTIVITY Current file: Car.cpp 1 include <iostream> 2 include <math.h> 3 #include Car.h 4 using namespace std; I void Car::S
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Car.h

#ifndef CARH
#define CARH

class Car{
private:
int modelYear;
  
int purchasePrice;
int currentValue;

public:
void SetModelYear(int userYear);
int GetModelYear() const;
void SetPurchasePrice(int purchasePrice);
int GetPurchasePrice() const;

void CalcCurrentValue(int currentYear);
void PrintInfo();
};
#endif // CARH

Car.cpp

#include<iostream>
#include<math.h>
#include "Car.h"
using namespace std;

void Car::SetModelYear(int userYear){
modelYear=userYear;
}

int Car::GetModelYear() const{
return modelYear;
}


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;


currentValue = (int)round(purchasePrice*pow((1-depreciationRate),carAge));

}

void Car::PrintInfo(){
cout<<"Car's information:\n";
cout<<"\t\tModel Year : "<<GetModelYear();
cout<<"\n\t\tPurchase price: "<<GetPurchasePrice();
cout<<"\n\t\tCurrentValue: "<<currentValue;
}

Add a comment
Know the answer?
Add Answer to:
Solve in C++ for Car.h and Car.cpp 8.21 LAB: Car value (classes) Given main, complete the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ please. 7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the Food Item class (in...

    In C++ please. 7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the Food Item class (in files Foodltem.h and Fooditem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "None" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of fat, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value. Ex: If the input is: M&M's 10.0 34.0...

  • 10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete...

    10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

  • Solve in C++ for Team.h and Team.cpp Given main(). define the Team class (in files Team.h...

    Solve in C++ for Team.h and Team.cpp Given main(). define the Team class (in files Team.h and Team.cpp). For class member function GetWinPercentage, the formula is: teamwins / (teamins + teamLosses) Note: Use casting to prevent integer division Ex: If the input is Ravens 13 3 where Ravens is the team's name, 13 is number of team wins, and 3 is the number of team losses, the output is: Congratulations, Team Ravens has a winning average! If the input is...

  • Code in C++ Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and...

    Code in C++ Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant member functions. Ex: If the input is: 3.0 4.0 4.0 5.0 where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is: Triangle with larger area: Base: 4.00...

  • Take your Car and List class from Week 8. Add functions to the List class that...

    Take your Car and List class from Week 8. Add functions to the List class that asks the user for a make and then deletes the first match in the list (or just assume all makes are unique in the list). HINT: Add a deleteCar function to get the make and then call a deleteFromList with the cstring to actually delete the car object from the list. Car class: #ifndef CAR_H #define CAR_H #define MAX_STR 10 //Car class class Car...

  • KINDLY HELP SOLVE THE C++ SECURE SHELL DRILLS, RUN AND COMPILE THEM TO PERFORM THE TASK PERFECTLY...

    KINDLY HELP SOLVE THE C++ SECURE SHELL DRILLS, RUN AND COMPILE THEM TO PERFORM THE TASK PERFECTLY. THANK YOU. /1 Function: Complete the body of the Read _Kth Num function. #include <iostream> using namespace std; // Read the k'th input value. DO NOT ISSUE A PROMPT // Example: when 3 and inputs are 4 6 8 10 12 the desired value is 8 void Read Kth Num (int k, int & value) tinclude "mainpt60300a.cpp" //Function: Complete the MaxVal function #include...

  • use c++ and complete this lab #include <iostream> using namespace std; class FibObj { public: void...

    use c++ and complete this lab #include <iostream> using namespace std; class FibObj { public: void setSize() { cout << "Enter an integer larger than 2: "; cin >> size; } int getSize() { return size; } void fibTerms(int x) // Write a recursive function { } explicit FibObj() // Default constructor was made explicit to avoid possible implicit type conversion { setSize(); int *arr; arr = new int[getSize()]; arr[0] = 1; arr[1] = 1; // Call recursive function here...

  • c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe...

    c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe De Silva Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below: class bookType { public:    void setBookTitle(string s);            //sets the bookTitle to s    void setBookISBN(string ISBN);            //sets the private member bookISBN to the parameter    void setBookPrice(double cost);            //sets the private member bookPrice to cost    void setCopiesInStock(int noOfCopies);            //sets the private member copiesInStock to...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT