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

YES WRITE A C++ CODE -lass Write a class named Car that has the following member

ID: 3902080 • Letter: Y

Question

YES WRITE A C++ CODE -lass Write a class named Car that has the following member variables * year. An int that holds the car's model year. make. A string that holds the make of the car speed. An int that holds the car's current speed. In addition, the class should have the following member functions Constructor. The constructor should accept the car's year and make as arguments and assign these values to the object's year and make member variables. The constructor should initialize the speed member variable to 0 Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's year, 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 eaclh time it is called. Demonstrate the class in a program that creates a Car object, and 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.

Explanation / Answer

As per your requirement r have written code which fulfill all your requirements please follow it step by step.

#include<conio.h>
#include<string.h>
#include<iostream.h>


class Car
{
public:
int year,speed;
char make[25];

Car(int year,char makeObject[25])
{
year=year;
strcpy(make,makeObject);
speed=0;
}

void displayInfoFunction()
{
cout<<"Year : "<<year<<endl;

cout<<"Make : "<<make<<endl;
}

void demoSpeedFunction()
{

cout<<"Speed : "<<speed<<endl;
}

void accelerate()
{
speed=speed+5;
}

void brake()
{
speed=speed-5;
}
};

int main()
{
int r,year;
char makeArray[25];
cout<<"Enter the Car's year Model : ";

cin>>year;

cout<<"Enter a string that hold the make of the car : ";

cin>>makeArray;

Car carObject(year,makeArray);
cout<<endl<<endl;

carObject.displayInfoFunction();

carObject.demoSpeedFunction();
cout<<endl<<endl;
cout<<"Adding 5 to speed & calling accelerate function five times ,get the current speed of the car ."<<endl<<endl;

for(r=1;r<=5;r++)
{
carObject.accelerate();

carObject.demoSpeedFunction();
}
cout<<endl;

cout<<"After adding 5 to speed for five Times : ";

carObject.demoSpeedFunction();

cout<<endl<<endl;

cout<<"Subtracting 5 from speed & calling brake function five times ,get the current speed of the car ."<<endl<<endl;

for(r=1;r<=5;r++)
{

carObject.brake();

carObject.demoSpeedFunction();

}
cout<<endl;

cout<<"After subtracting 5 from speed for five Times : ";

carObject.demoSpeedFunction();

getch();

return 0;

}