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

Write a class named Car that has the following member variables: *year. An int t

ID: 3544580 • Letter: W

Question

Write a class named Car that has the following member variables:
*year. An int that hold's 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--would accepts the car's year and make as arguments and assign these values to the object's year and make member variables.
*Accessor. appropriate accessor functions shoud 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 from the speed member variable each time it is called
*Brake- the brake function should minus 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 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 fuction, get the current speed. of the car and display it.

Explanation / Answer

please rate - thanks


I'm trusting you to rate



#include <string>
#include <iostream>
using namespace std;
class Car
{
public:
       Car(int,string);
       void setSpeed(int);
       void setYear(int);
       void setMake(string);                                                         
       int getSpeed();         
       string getMake();           
       int getYear();
       void accelerate();
       void brake();   
private:      
       int year;
       string make;
       int speed;
};
Car::Car(int y,string m)
{year=y;
make=m;
speed=0;
}
void Car::setSpeed(int s)
{speed=s;
}
void Car::setMake(string m)
{ make=m;
}

void Car::setYear(int y)
{year=y;
}

int Car::getSpeed()
{return speed;
}
string Car::getMake()
{return make;
}

int Car::getYear()
{return year;
}
void Car::accelerate()
{speed+=5;
}
void Car::brake()
{speed-=5;
}
int main()
{Car a(2012,"Kia");
int i;
cout<<"For your "<<a.getYear()<<" "<<a.getMake()<<endl;
for(i=1;i<=5;i++)
   {a.accelerate();
   cout<<"After accelerating "<<i<<" time speed: "<<a.getSpeed()<<endl;
}
for(i=1;i<=5;i++)
   {a.brake();
   cout<<"After brakeing "<<i<<" time speed: "<<a.getSpeed()<<endl;
}system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote