Refining my OOP program

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.
That's not exactly how I would go about it. What I would do is make an abstract base class called "Shape" that has area() and perimeter() as virtual functions. Then each other shape could derive and modify them as necessary. You wouldn't need an enum or anything, I think that would just complicate it more.
Thanks for the reply. I'll get right onto reading about virtual functions, since this is the first time I ever heard about them. As far as each other shape derives and modifies them as necessary I believe that would happen based on the constructors somehow? Any dummy-code that can be adapted to my shapes just to give me a rough idea on how this would work? Maybe with some comments to explain what that would be. =]
No, that is all done through your definition of the classes. You might also want to read up on polymorphism too, as it is needed when using virtual functions.

http://cplusplus.com/doc/tutorial/polymorphism/

That page pretty has an example of what you are trying to do right there.
Thank you very much for your input, draco. I'm getting started on that once I finish reading what it recommends to read beforehand (I was confused at the a->b at first. Turned out it was something very simple and very useful to know! Been 10 minutes and I already learned something new :O
As an update to this post, since my little mission ain't over yet - I have read over the polymorphism and tried several tiny programs of my own. I have a basic understanding of how this works and how I could implement it in my own scenario as far as virtual functions and derived functions would go. The problem I'm facing right now is:

How would I go on about implementing an efficient type of code without unecessary repetition when I have to ask the user to:

- Enter different details per shape (Would that be in a separate function, say "takeInput" per each class, which is derived from the main Shape class, or should I just plain hard-code it into the main function in an endless series of switch-case? Keep in mind various shapes require various inputs. Square takes only one, rect takes two, triangle may take 2 or 3 (based on whether area of perimiter is being calculated) while circle once again takes one.

- Provide shape-relevant output such as "Area of Square = XX". Should this be once again coded into the main or is there a more object-specific way to do this for each object without being too agressive on how many functions would exist in each class (or does that not really matter?)

I'd like some guidance with how the flow of my program can go, since I'm very hazy about it from this point of view, although I do like where this appears to be going =]
Topic archived. No new replies allowed.