Classes and Structures

I need help with writing this program for class. My teacher did not teach classes or structures very well and I do not know where to even begin. Here is what the program needs to be:

Design, implement and test a class that represents a basic calculator. The calculator may perform addition, subtraction, division and multiplication operations on two double numbers. The operation member is of type string and can be ADD, SUB, DIV or MUL.

Define and implement the following public member functions:

A default constructor that sets all variables to zero and operation to ADD.
A Set function that sets the values of the two numbers and the operator. The program should ask the user to enter the two numbers and then ask him/her to choose from a list the type of operation that should be performed.
An operation to add the two numbers then display the answer
An operation to subtract the two numbers then display the answer
An operation to divide the two numbers make sure that you are not dividing by 0; then display the answer
An operation to multiply the two numbers then displays the answer.


In the main program declare and set an object. Then test your program on all different options.

Any help will be greatly appreciated. Thanks!

Hi,

Teachers are like guides, they wouldn't give you all you wanted. Yes, I agree, some teachers are better than others, but you have to make some effort on your own to do some work.

Break the problem into several smaller unit and then combine all to get what you wanted.

To get some help, you have to show some effort. What your teacher didn't teach or taught very well is not the problem. You have 10,000 teachers sitting in front of you on your laptop! So use them.

Even on this forum there is tutorial section http://www.cplusplus.com/doc/tutorial/
and you could even get that for classes http://www.cplusplus.com/doc/tutorial/classes/

So, challenge yourself and get ahead of your class.
Others are willing to help too, but you show some effort!
closed account (48T7M4Gy)
You have 10,000 teachers sitting in front of you on your laptop! So use them.


All sound advice to OP who shouldn't forget there's also one staring back at you as a reflection in your monitor. All told, 10001 out of which OP has one allegedly lousy one.
@jaufdenberg69

Try writing some pseudo code - I know it sounds boring, but it is actually quite helpful.

Start out with quite general things that are is the assignment, write them as comments in the code editor. Then go back and refine things by adding more comments that explain the detail of each thing. Keep doing this until happy to convert the comments to code.

Doing this helps organise one's thoughts, identify what should be in a function, what should be in a loop etcetera.

Don't forget to check for division by zero !! :+)
Topic archived. No new replies allowed.