Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named Car that has the following member variables: yearModel, make, speed. In addition the class should have the following constructor and the

Write a class named Car that has the following member variables: yearModel, make, speed. In addition the class should have the following constructor and the other member functions constructor-accept the cars year model make as arguments. an assign to the objects year, make also assign speed 0 to speed member. Accessors to get the values stored in an object's yearModel make, speed accelerate- should add 5 to the speed member variable each time it is called. brake- subtract 5 from speed each time it is called.

Demonstrate the class in a driver program that creates a Car object, then calls the accelerate function five 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.

This is what I have so far:

//Header file for the car

#include

using namespace std;

class Car {

private:

int yearModel;

string make;

int speed;

public:

car (int year, string carMake);//constructor

void getCarM(string carMake); //getter for make of car

int getCarS(); //getter for speed of car

int getCarMo(); //getter for year model of car

//member function for both accelerate and brake

void accelerate();

void brake();

};

______________________

//implementation file car.cpp

#include

#include "car.h"

using namespace std;

//constructor

Car::Car(int year, string makes){

yearModel = year;

makes = make;

speed = 0;

}

//accelerate function, will add 5 to carspeed total when called

void Car::accelerate() {

speed = speed + 5;

}

//brake function, will subtract 5 to carspeed total when called

void Car::brake () {

speed = speed - 5;

}

//gets the car make and return it

void Car::getCarM(){

return make;

}

//gets the car speed and returns it

int Car::getCarS(){

return speed;

}

//gets the car year model and returns it

int Car::getCarMo(){

return yearModel;

}

______________________

//Test Driver

//Lab 2

#include "car.h"

#include

using namespace std;

int main()

{

//declare a specific car

Car Honda(2017, "Accord");

//loops through the accelerate 5 times

for (int i = 0; i < 6; i++)

{

Honda.accelerate();

}

//prints out the current speed of the car

cout<<"The current speed for Honda Accord is: " << Honda.getCarS() << endl;

for (int i = 0; i <6; i++)

{

Honda.brake();

}

//prints out the current speed of the car

cout <<"The current speed for the Honda Accord is: " <

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago