I know I posted the same problem earlier but I tried a different method and I'm still getting errors. Thanks for your help!
ERRORS:
warning C4091: 'auto ' : ignored on left of 'Car' when no variable is declared
warning C4091: 'auto ' : ignored on left of 'int' when no variable is declared
error C2143: syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before '.'
warning C4091: 'auto ' : ignored on left of 'int' when no variable is declared
error C2143: syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before '.'
warning C4091: 'auto ' : ignored on left of 'int' when no variable is declared
error C2143: syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before '.'
warning C4091: 'auto ' : ignored on left of 'int' when no variable is declared
syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before '.'
Instructions:
Car Class:
Write a class named Car that has the following:
year. An int that holds the cars model year.
make. A string object that holds the make of car.
speed. An int that holds the cars current speed.
In addition, the class should have the following member functions.
Constructor. The constructor should accept the car's year and make as arguments and assign these values to a object's year and make member variables. The constructor should initialize the speed member variable to 0.
Accessors. Appropriate accessor functions should 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 to the speed member variable each time it is called.
brake. The brake function should subtract 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 accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. The, call the brake function five times. After each call to the brake function, get the current speed of the car and display it.
Your 'Car' class has a constructor which takes 3 parameters. Which means it does not have a default constructor (a "default constructor" is one that can be called with no parameters).
You are attempting to call the default ctor here:
Car mobile; // <- calls default ctor since you are not supplying any params
But since there isn't a default ctor... you get this error.
Your options are:
1) Provide a default constructor
or
2) Dont' call the default ctor, and instead supply parameters when you create the object. Example:
Car mobile( 2003, "Dodge", 65 ); // <- provide year/make/speed params