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

This is the question: Write a class named Car that has the following member vari

ID: 3656154 • Letter: T

Question

This is the question: 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 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. The project instructions stated that i should store class declarations and member function definitions in their own seperate files; place the main part of the program in another file How do i do this? am confused on that part. #include #include #include using namespace std; class Car { private: int YearModel; int Speed; string Make; public: Car(int, string, int); string getMake(); int getModel(); int getSpeed(); void Accelerate(); void Brake(); }; Car::Car(int YearofModel, string Makeby, int Spd) { YearModel = YearofModel; Make = Makeby; Speed = Spd; } //To get who makes the car. string Car::getMake() { return Make; } //To get the year of the car. int Car::getModel() { return YearModel; } //To holds the car actual speed. int Car::getSpeed() { return Speed; } //To increase speed by 5. void Car::Accelerate() { Speed = Speed +5; } //To drop the speed of the car by 5. void Car::Brake() { Speed = Speed -5; } int main() { int Speed = 0; //Start Cars speed at zero. int index; int total=0; cout<<"Your G-6 is speed is: "<<Speed<<endl; Car first( 2008, "Pontiac", Speed); total+=Speed; //Display the menu and get a valid selection for(index=0;index<6;index++) { first.Accelerate(); cout<<"The car is accelerating at "<<first.getSpeed()<<" mph."<<endl; // here u have to change Speed to //first.getSpeed() } cout<<"The car's speed current speed is "<<first.getSpeed()<<" mph."<<endl; for(index=0;index<6;index++) { first.Brake(); cout<<"The car is breaking. The speed is now "<<first.getSpeed()<<" mph."<<endl; // here u have to change Speed to //first.getSpeed() } cout<<"The car's speed is now "<<first.getSpeed()<<" mph."<<endl; return 0; } although the code compiles, they are some mistakes in it no doubt its done wrong i think, its also supposed to be broken into seperate files.. The project instructions stated that i should store class declarations and member function definitions in their own seperate files; place the main part of the program in another file How do i do this? am confused on that part.

Explanation / Answer

// buddy u r 100% right but u r not supposed to call spped all the time

// the edited code given below according to your requirements.

// only two changes u have to make

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

class Car
{
private:
int YearModel;
int Speed;
string Make;
public:
Car(int, string, int);
string getMake();
int getModel();
int getSpeed();
void Accelerate();
void Brake();
};

Car::Car(int YearofModel, string Makeby, int Spd)
{
YearModel = YearofModel;
Make = Makeby;
Speed = Spd;
}
//To get who makes the car.
string Car::getMake()
{
return Make;
}
//To get the year of the car.
int Car::getModel()
{
return YearModel;
}
//To holds the car actual speed.
int Car::getSpeed()
{
return Speed;
}
//To increase speed by 5.
void Car::Accelerate()
{
Speed = Speed +5;
}
//To drop the speed of the car by 5.
void Car::Brake()
{
Speed = Speed -5;
}



int main()
{
int Speed = 0; //Start Cars speed at zero.
int index;
int total=0;
cout<<"Your G-6 is speed is: "<<Speed<<endl;
Car first( 2008, "Pontiac", Speed);
total+=Speed;
//Display the menu and get a valid selection

for(index=0;index<6;index++)
{
first.Accelerate();
cout<<"The car is accelerating at "<<first.getSpeed()<<" mph."<<endl;

// here u have to change Speed to //first.getSpeed()                                                                                                         
}
cout<<"The car's speed current speed is "<<first.getSpeed()<<" mph."<<endl;
for(index=0;index<6;index++)
{
first.Brake();
cout<<"The car is breaking. The speed is now "<<first.getSpeed()<<" mph."<<endl;

// here u have to change Speed to //first.getSpeed()                                                                                                         

}
cout<<"The car's speed is now "<<first.getSpeed()<<" mph."<<endl;
return 0;
}

// now compile and run CHeers.

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