Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I just want to check if my C++ follow the requirements stated below. I do not know if I need the test dummy. Requirements:

Hello I just want to check if my C++ follow the requirements stated below. I do not know if I need the test dummy.

Requirements:

image text in transcribed

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() { //creates a test dummy unique_ptr testDummy(new Car(2019, "Tesla"));

cout getSpeed()

//calls accelerate and dispalys its 5 times for (int i = 0; i accelerate(); cout getSpeed()

//calls brake and dispalys its 5 times for (int i = 0; i brake(); cout getSpeed()

return 0; }

Sample Output:

image text in transcribed

Write a class named Car that has the following member variables: yearModel. An int that holds the car s year model. make. A string that holds the make of the car. speed. An int that holds the cars current speed. In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the cars year model and make as arguments. These values should be assigned to the object s year Model and make member variables. The constructor should also assign 0 to the speed member variables. (programing preference: member initialization list: reference) Accessor. Appropriate accessor functions to get the values stored in an object s year Model, make, and speed member variables. accelerate. The accelerate function should add 5 to the speed member variable each time it is called. brake. The brake function should subtract 5 from the speed member variable each time it is called. Demonstrate the class in a program that creates a Car object, and then calls the accelerate function ve times. After each call to the accelerate function, get the current speed of the car and display it. Then, call the brake function five times. After each call to the brake function, get the current speed of the car and display it. Current speed: 0 Accelerating... Current speed: 5 Accelerating: - Current speed: 10 Accelerating ... Current speed: 15 Accelerating Current speed: 20 Accelerating... Current speed: 25 Braking... Current speed: 20 Braking -- . 45 Current speed: 15 Current speed: 10 Braking. . Current speed: 5 Braking. . Current speed: 0 Process returned 0 (0x0) Press any key to continue. Braking-peed: 10 execution time : 0.199 s

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

What traits predict leadership?

Answered: 1 week ago

Question

Describe the steps involved in coaching to improve poor performance

Answered: 1 week ago

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago