Object oriented c++, make a class that does the basic operations (+,*,/,-)

So i know a little bit of basic c++, but i am new to object oriented programming.
My task is to make a class that does calculations with +,-,*,/
i need to modify this code:


1
2
3
4
5
6
7
8
class Calc { 
private:
         int op1;
         int op2;
public: 
         ... 
         double eval (char op); 
}; 


i have to make it using set and get methods.

any suggestion would be appreciated, also i need to know what to write in the main() function,

thank you in advance.
Last edited on

i need to know what to write in the main() function,

So think about what you need to do:
- Ask the user the value of op1
- Ask the user the value of op2
- Ask the user for the operator (+,-,*,/)
- Call your setters for op1 and op2.
- Call eval with the operator.
- Display the result.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
ok, thank you very much for your advice i will try to do what you said, also i will edit my post.
i am sorry, could you or someone else please demonstrate (with code) what do i need to do, i know its too much but i would apreciate it very much.
We're not going to do your homework for you. You wouldn't learn that way.

Try writing a function for each of the activities I listed. Post back with your code and any problems or questions.

Thanks for adding the code tags.
Topic archived. No new replies allowed.