errors with a class program

I need help trying to fix the errors in my class program. The comments to the sides are the requirements for the program. My compiler says that there are a bunch of things undeclared. I am new to C++ so please don't be too harsh on me. I am suppose to print out the initial value of age & price and the modified value of age & price. Any help on trying to run this program would be very helpful.

#include <iostream>
using namespace std;
Class Vehicle {
private:
int Age; //The age of the vehicle

protected:
float Price; //The price of the vehicle

public:
Vehicle(int Age=0,int Price=0.0;) //default constructor sets age=0, and price=0.0
~Vehicle() (Age=0,Price=0.0;) //destructor sets age=0, and price=0.0
setAge(int Age); //Takes an integer parameter, returns nothing
setPrice(float Price); //Takes a float parameter, returns nothing
int getAge(){return Age;};// Takes no parameters, returns the vehicle’s age
float getPrice(){return Price;}; // Takes no parameters, returns the vehicle’s price
};
int main()
{
Vehicle x;
cout << "Initial value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
x.setAge(40);
x.setPrice(20000);
cout << "Modified value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
return 0;
}
For starters, it's "class" and not "Class". C++ is case sensitive.


Vehicle(int Age=0,int Price=0.0;)

That is incorrect. The correct way to do it is: Vehicle(){ Age = 0; Price = 0.0; }


~Vehicle() (Age=0,Price=0.0;)

That is incorrect. The correct way to do it is: ~Vehicle(){ Age = 0; Price = 0.0; }


setAge(int Age);

You need to give this the void return type for it to return nothing. Also, this needs to be defined; this is only a declaration.


setPrice(float Price);

You need to give this the void return type for it to return nothing. Also, this needs to be defined; this is only a declaration.


int getAge(){return Age;};

Remove the semicolon after the }


float getPrice(){return Price;};

Remove the semicolon after the }


PLEASE read this: http://www.cplusplus.com/doc/tutorial/functions/
PLEASE read this: http://www.cplusplus.com/doc/tutorial/classes/
Last edited on
Topic archived. No new replies allowed.