## ajprincess 3 years ago plzz check.

1. ajprincess

#include<iostream> using namespace std; class Operation { private: int answer; int numberA; int numberB; public: int addition(int numberA,int numberB); int subtraction(int numberA,int numberB); int multiplication(int numberA,int numberB); int division(int numberA,int numberB); int getNumberA(); void setNumberA(int numberA); int getNumberB(); void setNumberB(int result); void printOnScreen(int answer); }; int Operation::getNumberA() { return numberA; } void Operation::setNumberA(int A) { numberA=A; } int Operation::getNumberB() { return numberB; } void Operation::setNumberB(int B) { numberB=B; } int Operation::addition(int numberA,int numberB) { return (numberA+numberB); } int Operation::subtraction(int numberA,int numberB) { return (numberA-numberB); } int Operation::multiplication(int numberA,int numberB) { return (numberA*numberB); } int Operation::division(int numberA,int numberB) { return (numberA/numberB); } void Operation::printOnScreen(int answer) { cout<<answer<<endl; } int main() { Operation o; int numberA, numberB, answer, choice; o.setNumberA(8); o.setNumberB(7); cout<<"Enter the choice:"; cin>>choice; switch(choice) { case 1: o.addition(numberA,numberB); break; case 2: o.subtraction(numberA,numberB); break; case 3: o.multiplication(numberA,numberB); break; case 4: o.division(numberA,numberB); break; default: cout<<"Wrong choice"<<endl; } o.printOnScreen(int answer); system("PAUSE"); return 0; }

2. agdgdgdgwngo

about your printOnScreen method: Shouldn't it take no arguments, and just print out the private memver `answer'? otherwise the last statement in main before system(pause) (o.printOnScreen(int answer);) is a syntax error :)

3. agdgdgdgwngo

private member* `answer' something like void Operation::printOnScreen() { cout << answer << endl; }

4. ajprincess

This is the question Write a C++ program with multiple methods to intake the two integers and do the, Addition, Subtraction, Multiplication, and Division. Hints: 1.Use the following class diagram for your implementation. 2.On your main method u hav to implement selection and repetition of the arithmetic operation 3.You can include any more methods if required.

5. agdgdgdgwngo

ah I get it now. you need to either declare an answer variable to store the results of adding/multiplying/etc and supply it as an arugment to void Operation::printOnScreen(int answer), or you need to change the adding/subtracting/etc methods to change the `answer' member variable

6. ajprincess

Class diagram Arithmetic int numberA int numberB int answer int addition int subtraction int multiplication int division void getAnswer void setAnswer void printOnScreen

7. agdgdgdgwngo

with that diagram, it looks like you are just missing the getAnswer and setAnswer methods.

8. ajprincess

yep. bt am trying to include it. am totally confused.

9. agdgdgdgwngo

10. ajprincess

ya I knw that. bt it is given in the class diagram as void getAnswer.

11. agdgdgdgwngo

that's confusing then; getter methods are supposed to return something, no? :(

12. ajprincess

ya u r right. and also i dnt knw vt to include in printOnScreen() .:(

13. agdgdgdgwngo

from your first post, your printOnScreen looks fine. when you use it in main you can do something like: o.printOnScreen(o.getAnswer());

14. ajprincess

15. ajprincess

Bt I dnt get the expected output. Dnt knw y.:(

16. shivam_bhalla

What is the output you expect?

17. ajprincess

as u can see I hav passed the values 8 and 7 for A and B. If my choice is 1 I should get 15 as the output. Bt I dnt get t.

18. shivam_bhalla

@ajprincess , int Arithmetic::addition(int numberA,int numberB) This is wrong. a.addition(numberA,numberB); It should be int temp; temp =a.addition(numberA,numberB);

19. shivam_bhalla

Do you understand that you were not storing the value returnnd by " int Arithmetic::addition(int numberA,int numberB) " in a variable

20. ajprincess

21. shivam_bhalla

22. shivam_bhalla

BUt why did you declare another answer varible in main () ??

23. ajprincess

If I change it like this I get an error saying that answer is private.

24. shivam_bhalla

25. ajprincess

bt it reports an error as answer undeclared

26. shivam_bhalla

27. ajprincess

28. shivam_bhalla

29. ajprincess

if I make this many mistakes dnt knw hw I am gonna finish this within 45mints. Thanxxxxxxx a lot. @Shivam_bhalla. U r so helpful.

30. shivam_bhalla

LOL. No problem. I also learnt by making these mistakes :P

31. ajprincess

U too @agdgdgdgwngo are really helpful. Thanxxxxx a lot.

32. ajprincess

in my question repetition of arithmetic operation is askd to b implemented. Hw wud i do that?@Shivam_bhalla

33. ajprincess

@shivam_bhalla

34. shivam_bhalla

I was busy at another question. If your question is asking for repeting of arithmetic operation then you can add the (Number 1 +Number 2)+number 1

35. ajprincess

can u please show with my function declarations?

36. shivam_bhalla

@ajprincess , why don't you try by yourself?. Learn by trying on your own. You will get the logic. Then try to implement that logic :D

37. ajprincess

k thanxxxx a lot. @shivam_bhalla

38. shivam_bhalla

np ;). Remember. Computer is a easy subject. Just practice it on your own by making your own programs :)

39. ajprincess

Sure.:)

Find more explanations on OpenStudy