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

I need help trying to display the make, and model of my program. If someone coul

ID: 3622002 • Letter: I

Question

I need help trying to display the make, and model of my program. If someone could please help me with this I would appreciate it!

This is my code:

//This program shows the year, make, and speed of a vehicle. It accelerates the car in increments of 5 for 5 times starting at
//zero. It then brakes the car in increments of 5 for 5 times starting at what the cars last accelerated speed was.
#include <iostream>
#include <cstring>

using namespace std;

class Car
{
private:
int yearModel;
int speed;
string make;
public:
Car(int, string, int);
string displayMake();
int displayModel();
int displaySpeed();
void Accelerate();
void Brake();
};
Car::Car(int year, string Make, int spd)
{
yearModel = year;
make = Make;
speed = spd;
}
string Car::displayMake() //Returns the make of the car
{
return make;
}

int Car::displayModel() //Returns the year of the car
{
return yearModel;
}

int Car::displaySpeed() //To hold the current speed of the car
{
return speed;
}

void Car::Accelerate() //Increases the accelerated speed by 5
{
speed = speed +5;
}

void Car::Brake() //Decreases the brake speed by 5
{
speed = speed -5;
}



int main()
{
int speed = 0; //Beginning speed of car
int index; //Loop counter
int total=0; //To hold the total speed

cout<<"Your G-6 speed is: "<<speed<<endl; //Display the speed of the car
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.displaySpeed()<<" mph."<<endl;

}
cout<<"The car's speed current speed is "<<first.displaySpeed()<<" mph."<<endl;
for(index=0;index<6;index++)
{
first.Brake();
cout<<"The car is breaking. The speed is now "<<first.displaySpeed()<<" mph."<<endl;

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

Explanation / Answer

please rate - thanks

you wer accelerating and decelerating 6 times, not 5-I fixed that

//This program shows the year, make, and speed of a vehicle. It accelerates the car in increments of 5 for 5 times starting at
//zero. It then brakes the car in increments of 5 for 5 times starting at what the cars last accelerated speed was.
#include <iostream>
#include <cstring>

using namespace std;

class Car
{
private:
int yearModel;
int speed;
string make;
public:
Car(int, string, int);
string displayMake();
int displayModel();
int displaySpeed();
void Accelerate();
void Brake();
};
Car::Car(int year, string Make, int spd)
{
yearModel = year;
make = Make;
speed = spd;
}
string Car::displayMake() //Returns the make of the car
{
return make;
}

int Car::displayModel() //Returns the year of the car
{
return yearModel;
}

int Car::displaySpeed() //To hold the current speed of the car
{
return speed;
}

void Car::Accelerate() //Increases the accelerated speed by 5
{
speed = speed +5;
}

void Car::Brake() //Decreases the brake speed by 5
{
speed = speed -5;
}



int main()
{
int speed = 0; //Beginning speed of car
int index; //Loop counter
int total=0; //To hold the total speed

cout<<"Your G-6 speed is: "<<speed<<endl; //Display the speed of the car
Car first( 2008, "Pontiac", speed);

total+=speed;
//Display the menu and get a valid selection
cout<<"Your car is a "<<first.displayMake()<<" "<<first.displayModel()<<endl;
for(index=0;index<5;index++)
{
first.Accelerate();
cout<<"The car is accelerating at "<<first.displaySpeed()<<" mph."<<endl;

}
cout<<"The car's speed current speed is "<<first.displaySpeed()<<" mph."<<endl;
for(index=0;index<5;index++)
{
first.Brake();
cout<<"The car is breaking. The speed is now "<<first.displaySpeed()<<" mph."<<endl;

}
cout<<"The car's speed is now "<<first.displaySpeed()<<" mph."<<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