we went over how to do class circles and it was completely different for a rectangle. So..
|
Your statement implies that you have already seen a rectangle class. And you are now asking for detailed info on how to do it?
Any way your statement is not really correct. Obviously a circle has a centre point & radius while a rectangle has width & height, and a circle has lots of different ways of being created, but the organisation of the code is the same.
You have constructors to set member variables when the object is created, and functions to change the value of the member variables (set functions), functions to retrieve values of member variables (get functions), and output functions to, say, print out values.
Professor wrote:
accessor and mutator functions for all data fields |
Try to avoid writing a get / set function for each member variable - only write them if you need them. Remember class functions have direct access to all the member variables, so you can take advantage of this in your Output function. As well as that you can have functions that set several variables at once. IMO, one only needs get functions if the data is required by another class. Having get / set functions for every member variable is effectively the same as making them all public.
If you explain why you didn't have get functions & only 1 set function in this case, you professor would be a bit unfair to mark you down IMO.
Also, having get in a function name is a bit misleading - it implies the retrieval of a member variable. I would just name the functions Area & Perimeter.
There is a bit of a convention to name member variables with a leading m_ as in m_Width. This can make it easier to name function parameters.
There you go, some stuff to think about.