Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

ajprincess Group Title

plzz check.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    #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 years ago
  2. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    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 :)

    • 2 years ago
  3. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

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

    • 2 years ago
  4. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  5. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    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

    • 2 years ago
  6. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  7. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

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

    • 2 years ago
  8. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  9. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    something like: int Operation::getAnswer() { return answer } void Operation::setAnswer(int answer) { this->answer = answer; }

    • 2 years ago
  10. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  11. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

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

    • 2 years ago
  12. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  13. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

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

    • 2 years ago
  14. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    #include<iostream> 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<<answer<<endl; } int main() { Arithmetic a; int numberA, numberB, answer, choice; a.setNumberA(8); a.setNumberB(7); cout<<"Enter the choice:"; cin>>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"<<endl; } a.printOnScreen(); system("PAUSE"); return 0; }

    • 2 years ago
  15. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  16. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    What is the output you expect?

    • 2 years ago
  17. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  18. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @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);

    • 2 years ago
  19. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  20. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I hav already declared answer in my main method. Nw I wrote this answer=a.addition(numberA,numberB) It's correct nw. Isnt t?

    • 2 years ago
  21. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Nope @ajprincess , it should be a.answer=a.addition(numberA,numberB); answer is private member function of Arithmetic

    • 2 years ago
  22. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  23. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  24. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Got it. It should be answer=a.addition(numberA,numberB); setAnswer(answer); Now it should be fine

    • 2 years ago
  25. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    bt it reports an error as answer undeclared

    • 2 years ago
  26. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry @ Ajprincess. It should be answer=a.addition(numberA,numberB); a.setAnswer(answer);

    • 2 years ago
  27. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    bt I wrote it as a.setAnswer(answer)

    • 2 years ago
  28. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    LOl @ajprincess . I just noticed another mistake. int temp, temp1; temp=getNumberA(); temp1=getNumberB(); answer=a.addition(temp,temp1); a.setAnswer(answer);

    • 2 years ago
  29. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  30. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  31. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  32. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  33. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    @shivam_bhalla

    • 2 years ago
  34. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 2 years ago
  35. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    can u please show with my function declarations?

    • 2 years ago
  36. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @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

    • 2 years ago
  37. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    k thanxxxx a lot. @shivam_bhalla

    • 2 years ago
  38. shivam_bhalla Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  39. ajprincess Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Sure.:)

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.