Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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 testCar(new Car(2019, "Tesla"));

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions