Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First, write a C class named Car that has the following private nember variables

ID: 3870569 • Letter: F

Question

First, write a C class named Car that has the following private nember variables year (int) make (string) speed (int) Add the following public members functions to class Car Default Constructor with no parameters: This constructor should set the year to -1, make to "none" and speed to e. Constructor with parameters: The constructor should accept the nake and year as arguments and use these arguments values to set the year and make member variables of the class. Speed should be initialized to e by this constructor. Accessors (getters): add these member functions for year, make and speed member variables Mutators (setters): add these member functions for year, make and speed member variables. accelerate: this member function should add 5 to speed member variable each time it is called. brake: this member function should subtract 5 from speed menber variable each time it is called. print: this member function should print the values of make, model, and speed of the car in to the screen b) Then, in your main function create an two objects of class Car: one with using the default constructor and the other one using the constructor with parameters. call print function for each Car objects call accelerate function for each Car object and followed by a call to print function for each Car object. .call brake function for each Car object and followed by a call to print function for each Car object.

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

class Car
{
private:
int year;
string make;
int speed;

public:
Car()
{
year=-1;
make="none";
speed=0;
}

Car(int y,string m)
{
year=y;
make=m;
speed=0;
}

int get_year()
{
return year;
}

string get_make()
{
return make;
}

int get_speed()
{
return speed;
}

void set_year(int y)
{
year=y;
}

void set_make(string m)
{
make=m;
}

void set_speed(int s)
{
speed=s;
}

void accelerate()
{
speed+=5;
}

void brake()
{
speed-=5;
}

void print()
{
cout<<"The details are "<<year<<endl<<make<<endl<<speed<<endl;
}

};

int main()
{
Car a,b(2012,"Hyndai");
a.print();
b.print();

a.accelerate();
a.print();

b.accelerate();
b.print();

a.brake();
a.print();

b.brake();
b.print();
}