ajprincess
  • ajprincess
plzz check.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
ajprincess
  • ajprincess
#include 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<>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"<
anonymous
  • anonymous
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 :)
anonymous
  • anonymous
private member* `answer' something like void Operation::printOnScreen() { cout << answer << endl; }

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

ajprincess
  • 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.
anonymous
  • anonymous
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
ajprincess
  • ajprincess
Class diagram Arithmetic int numberA int numberB int answer int addition int subtraction int multiplication int division void getAnswer void setAnswer void printOnScreen
anonymous
  • anonymous
with that diagram, it looks like you are just missing the getAnswer and setAnswer methods.
ajprincess
  • ajprincess
yep. bt am trying to include it. am totally confused.
anonymous
  • anonymous
something like: int Operation::getAnswer() { return answer } void Operation::setAnswer(int answer) { this->answer = answer; }
ajprincess
  • ajprincess
ya I knw that. bt it is given in the class diagram as void getAnswer.
anonymous
  • anonymous
that's confusing then; getter methods are supposed to return something, no? :(
ajprincess
  • ajprincess
ya u r right. and also i dnt knw vt to include in printOnScreen() .:(
anonymous
  • anonymous
from your first post, your printOnScreen looks fine. when you use it in main you can do something like: o.printOnScreen(o.getAnswer());
ajprincess
  • ajprincess
#include using namespace std; class Arithmetic { 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); int getAnswer(); void setAnswer(int result); void printOnScreen(); }; int Arithmetic::getNumberA() { return numberA; } void Arithmetic::setNumberA(int A) { numberA=A; } int Arithmetic::getNumberB() { return numberB; } void Arithmetic::setNumberB(int B) { numberB=B; } int Arithmetic::addition(int numberA,int numberB) { return (numberA+numberB); } int Arithmetic::subtraction(int numberA,int numberB) { return (numberA-numberB); } int Arithmetic::multiplication(int numberA,int numberB) { return (numberA*numberB); } int Arithmetic::division(int numberA,int numberB) { return (numberA/numberB); } int Arithmetic::getAnswer() { return answer; } void Arithmetic::setAnswer(int result) { answer=result; } void Arithmetic::printOnScreen() { cout<>choice; switch(choice) { case 1: a.addition(numberA,numberB); break; case 2: a.subtraction(numberA,numberB); break; case 3: a.multiplication(numberA,numberB); break; case 4: a.division(numberA,numberB); break; default: cout<<"Wrong choice"<
ajprincess
  • ajprincess
Bt I dnt get the expected output. Dnt knw y.:(
anonymous
  • anonymous
What is the output you expect?
ajprincess
  • 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.
anonymous
  • anonymous
@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);
anonymous
  • anonymous
Do you understand that you were not storing the value returnnd by " int Arithmetic::addition(int numberA,int numberB) " in a variable
ajprincess
  • ajprincess
I hav already declared answer in my main method. Nw I wrote this answer=a.addition(numberA,numberB) It's correct nw. Isnt t?
anonymous
  • anonymous
Nope @ajprincess , it should be a.answer=a.addition(numberA,numberB); answer is private member function of Arithmetic
anonymous
  • anonymous
BUt why did you declare another answer varible in main () ??
ajprincess
  • ajprincess
If I change it like this I get an error saying that answer is private.
anonymous
  • anonymous
Got it. It should be answer=a.addition(numberA,numberB); setAnswer(answer); Now it should be fine
ajprincess
  • ajprincess
bt it reports an error as answer undeclared
anonymous
  • anonymous
Sorry @ Ajprincess. It should be answer=a.addition(numberA,numberB); a.setAnswer(answer);
ajprincess
  • ajprincess
bt I wrote it as a.setAnswer(answer)
anonymous
  • anonymous
LOl @ajprincess . I just noticed another mistake. int temp, temp1; temp=getNumberA(); temp1=getNumberB(); answer=a.addition(temp,temp1); a.setAnswer(answer);
ajprincess
  • 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.
anonymous
  • anonymous
LOL. No problem. I also learnt by making these mistakes :P
ajprincess
  • ajprincess
U too @agdgdgdgwngo are really helpful. Thanxxxxx a lot.
ajprincess
  • ajprincess
in my question repetition of arithmetic operation is askd to b implemented. Hw wud i do that?@Shivam_bhalla
ajprincess
  • ajprincess
@shivam_bhalla
anonymous
  • anonymous
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
ajprincess
  • ajprincess
can u please show with my function declarations?
anonymous
  • anonymous
@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
ajprincess
  • ajprincess
k thanxxxx a lot. @shivam_bhalla
anonymous
  • anonymous
np ;). Remember. Computer is a easy subject. Just practice it on your own by making your own programs :)
ajprincess
  • ajprincess
Sure.:)

Looking for something else?

Not the answer you are looking for? Search for more explanations.