#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();
	void displayMenu();
};

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;
}

void displayMenu()
{
	cout <<"\n				Menu\n";
	cout << "----------------------------\n";
	cout << "A)Accelerate the Car\n";
	cout << "B)Push the Brake on the Car\n";
	cout << "C)Exit the program\n\n";
	cout << "Enter your choice: ";
}

int main()
{
	int Speed = 0; //Start Cars speed at zero.
	char choice; //Menu selection

	cout << "The speed of the SUV is set to: " << Speed <<endl;
	Car first( 2007, "GMC", Speed);

	//Display the menu and get a valid selection
	do
	{
		displayMenu();
		cin >> choice;
		while(toupper(choice) < 'A' || toupper(choice) > 'C')
		{
			cout << "Please make a choice of A or B or C:";
			cin >> choice;
		}

		//Process the user's menu selection
		{
{
			switch (choice)
			{
			case 'a':
			case 'A': cout << "You are accelerating the car. ";
				cout << Accelerate(first) << endl;
				break;
			case 'b':
			case 'B': cout << "You have choosen to push the brake.";
				cout << Brake(first) << endl;
				break;
			}
}
		}while (toupper(choice) != 'C');

	return 0;
}

what do you mean by "it won't work"? You need to be more specific. Do you take your car to auto repairman and simply tell him "my car is broke, fix it please."? Of course not, you have to tell him what you thnk is wrong and what the symptems are.

what do you mean by "it won't work"? You need to be more specific. Do you take your car to auto repairman and simply tell him "my car is broke, fix it please."? Of course not, you have to tell him what you thnk is wrong and what the symptems are.

The assignment is:

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.

it says the error is in line 90

line 90 us wrong because function Accelerate() returns void, which means it can not be used in a cout statement.

Would you mind showing what the error is? I think it's because you call the Accelerator method but nothing is returned out of it because it's set to void, but maybe I'm wrong...


Edit: Ancient beat me to it...

it also does not stay up to date with the speed.

the last part of the assignment is

demonstrate the class in a program that creates a car object, and then calls the acceleration function five times. After each call to the acceleration function, get the current speed of the car and display it. Then, call the break function five times. After each break function get the current speed of the car and display it.

sorry, im new to programming and am having a hard time with this.

cout << Accelerate(first) << endl;

The cout implies that you want to output something using the function, Accelerate.

The function Accelerate, when you called it Accelerate(first), does not take any parameters in the declared or defined function. Nor does it imply outputting any data either.

void Car::Accelerate(){
Speed = Speed + 5;
}

So, do you want to increase the speed? or cout the speed?

i fixed the acceleration part but how do i do this part of the assignment?

demonstrate the class in a program that creates a car object, and then calls the acceleration function five times. After each call to the acceleration function, get the current speed of the car and display it. Then, call the break function five times. After each break function get the current speed of the car and display it.

sorry, im new to programming and am having a hard time with this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.