Hello CPP community,
At our course we've been given an assignment to jump-start us on OOP with C++. The assignment details, roughly are as follow:
- Create an OOP program which allows the user to choose one of four shapes (Square, Rectangle, Triangle, Circle).
- For any one of these shapes the user chooses, the program will then prompt the user whether he'd like to calculate the perimeter/circumference OR area.
- Based on the above two choices the appropriate measurements of the object will be requested from the user (nothing extra should be asked).
- We must create a class (or more than one) that covers the shapes, created as an object through which functions such as perimeter() and area() will calculate the details, after a constructor sets the values.
That's essentially what's required. I have already completed this assignment in "my own way". Which works well, is clean and I'm sure I'll get a good grade on. Now what I'd personally like is to further refine it and learn more as far as OOP goes. How do I go on about:
- Creating a single class (e.g. Shapes), which contains several constructors (overloaded) and through the user choices, probably with a switch-case function I'll be able to build one object and initialize the proper variables.
Current code (still working on it, obviously) =
http://pastebin.com/PahBnqE4
I would also like to:
- Make use of the apparently useful but kinda confusing enum (which holds all 4 shapes in it and is used as whatever it should be used - I'm not too sure on that :P) and avoid creating as many unnecessary variables as possible (would like to keep this already small program as efficient as possible on memory and processing, even though it really doesn't matter for now).
I don't know, I guess I'm just asking for pro-tips on making the program something I can learn a lot from, considering what I need to submit is essentially already finished and I can just mess around all I want to, now =]
Thanks for any insight.