-
I have a few comments! :)
- The Rectangle class needs a destructor, since you wrote a constructor.
- You should use your getter functions to compose the equation in your area function.
- The Cube class inherits the height variable, you dont need to make another private member for the Cube class. The Cube class can also simply use Rectangle's implementation, since nothing is different about it. Save yourself the typing.
Most importantly, default parameters belong in the implementation of the constructor:
Code:
Rectangle::Rectangle(double l=0., double w=0.) : length(l), width(w)
{ }
And of course the loop will be endless until the user types something that isn't 1 or 2. Type 0, for instance, and the loop breaks.
-
forget the loop any idea why the functions wont take the numbers and they are producing garbage?
-
No matter what the user passes into your Rectangle constructor, you ignore it and use zeros, for one thing.
Use the constructor I built for you in my last post. They don't have the same variable names as yours does, but that can be easily changed. I tested my constructor before posting it and it works fine.
-
your constructor gives me 2 errors:
.\Rectangle.cpp(4) : error C2572: 'Rectangle::Rectangle' : redefinition of default parameter : parameter 2
c:\documents and settings\johnnyg\my documents\visual studio 2005\projects\project 8\project 8\Rectangle.h(8) : see declaration of 'Rectangle::Rectangle'
.\Rectangle.cpp(4) : error C2572: 'Rectangle::Rectangle' : redefinition of default parameter : parameter 1
c:\documents and settings\johnnyg\my documents\visual studio 2005\projects\project 8\project 8\Rectangle.h(8) : see declaration of 'Rectangle::Rectangle'
thats the way i had it at the start but had to remove those due to the errors it was causing... seemed to be unavoidable
-
I will do this for you again. I told you my parameter names didn't match yours; you would need to change them--and that's what those errors mean.
This will definitely work.
Code:
Rectangle::Rectangle (double l=0., double w=0.) : length(l), width(w) { }
-
they give me the same two errors
sorry -_-
-
Sorry, I went to sleep. What exactly is the problem again as it seems we've gone off on a tangent.
-
well i have to leave to turn it in now but the problem was the var's arnt being set by the user input and are just returning garbage.