Question
Hello I need help with my C++ program. I need to change the part highlighted in bold to the part described below: This part needs
Hello I need help with my C++ program. I need to change the part highlighted in bold to the part described below:
This part needs to be added:
int main() { Car tesla(2019, "S3"); cout << "My Tesla is at " << tesla.getSpeed() << " m/h. "; for( int count =0; count < 10; count++ ) { tesla.accelerate(); cout << "My Tesla is at " << tesla.getSpeed() << " m/h. ";
Car.h
#pragma once #include
using namespace std;
class Car { private: int yearModel; int speed = 0; string make;
public: Car(int year, string m) { speed = 0; yearModel = year; make = m; }
void setYearModel(int); void setSpeed(int); void setMake(string);
int getYearModel() const; int getSpeed() const; string getMake() const;
void accelerate(); //add 5 to speed void brake(); //subtract 5 to speed };
testCar.cpp
#include "Car.h" #include
using namespace std;
void Car::setYearModel(int ym) { yearModel = ym; }
void Car::setSpeed(int sp) { speed = sp; }
void Car::setMake(string m) { make = m; }
int Car::getYearModel() const { return yearModel; }
int Car::getSpeed() const { return speed; }
string Car::getMake() const { return make; }
void Car::accelerate() { speed += 5; }
void Car::brake() { speed -= 5; }
int main() { //This part needs to be changed for the part described above in bold unique_ptr
cout << "Current speed: " << testCar->getSpeed() << endl;
//calls accelerate and dispalys its 5 times for (int i = 0; i < 5; i++) { cout << "Accelerating..." << endl; testCar->accelerate(); cout << "Current speed: " << testCar->getSpeed() << endl; }
//calls brake and dispalys its 5 times for (int i = 0; i < 5; i++) { cout << "Braking..." << endl; testCar->brake(); cout << "Current speed: " << testCar->getSpeed() << endl; }
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started