josephdebono said:
Finally, to add finesse to your application, I suggest you declare constants LENGTH and WIDTH and always refer to those values when you need to. That way, changing the values for the program only requires you change it in two places.
Code:
const int LENGTH = 7;
const int WIDTH = 9;
main()
{
Plot rec(LENGTH, WIDTH);
cout << "The area of " << LENGTH << " and " << WIDTH << " is " rec.area() << endl;
}
I think you're going a bit overboard with this.
It's true that it's a good rule of thumb to never use "naked" constants, but it seem to me like the assignment here is the class, not the code that drives it.
AcciDante said:
My programming class is over now (got an A!), and now I'm trying to finish going through the text book before I have to return it. I'm going over classes now, and it's going well, but I'm a little fuzzy on one thing. I know how to make separate specification and implementation files, but I'm not sure why/when you would define functions in the implementation file. Can someone briefly explain?
Ignoring templates (and ignoring some other stuff, so don't be anal):
C++ doesn't really have the language concept of a specification files.
Header files are nothing more that code that get added to your cpp file by your precompiler.
In theory, you can achieve everything you want without using a single h file in your project.
In practice, header files are used mostly for forward deceleration, and therefore you can replace your #include directive with a copy paste of the header file and it will work (again, in theory, in reality there will probably be some issues).
But to bring this discussion back to reality, people mostly put function deceleration in header files.
For convenience and code brevity, it's not a bad idea to put the implementation short or inline functions (like accessors) in the header file as well.
Not ignoring templates:
I'm already boring myself so I'll be short - templates need to be in a header file.