Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I just want to check if the C++ code follows all the requirements. Thanks. Requirements: Car.h #pragma once #include using namespace std; class Car

Hello, I just want to check if the C++ code follows all the requirements. Thanks.

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

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() { Car tesla(2019, "S3"); cout

for (int count = 0; count

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

return 0; }

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

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions