Need help on CLASS

Is my start_car() and stop_car() correct? Where do I set the bool start in CarSpeed? I am supposed to compute the velocity using the formula: acceleration * time. Prompts the user to enter the value for time. Before the computation of velocity, check that the car has started. If it is started, performs the computation, otherwise, set the velocity to 0. Return the velocity. How do I check that the car has started?

class CarSpeed
{
private:
float acceleration;
string engine_number;
bool start;
public:
CarSpeed(float = 0, string="", bool=false);
void start_car();
void stop_car();
void set_acceleration(float);
void set_engine_number(string);
float get_velocity(float);
};

void CarSpeed::start_car()
{
bool start = true;
cout << "Car started successfully" << endl;
}

void CarSpeed::stop_car()
{
bool start = false;
cout << "Car stopped successfully" << endl;
}
HIHI

please help
Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/


In start/stop_car() you create a new local variable start which shadows the member variable start:
1
2
3
4
5
6
7
8
9
10
11
void CarSpeed::start_car()
{
bool start = true;
cout << "Car started successfully" << endl;
}

void CarSpeed::stop_car()
{
bool start = false;
cout << "Car stopped successfully" << endl;
} 

You should initialize the member variables (acceleration/start) in the constructor.
Topic archived. No new replies allowed.