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

Plzzz help Write a C++ program with multiple methods to intake the two integers and do the, Addition, Subtraction, Multiplication, and Division.On your main method u hav to implement selection and repetition of the arithmetic operation

  • one year ago
  • one year ago

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

    #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 A, B, answer, choice; a.setNumberA(8); a.setNumberB(7); A=a.getNumberA(); B=a.getNumberB(); cout<<"Enter the choice:"; cin>>choice; switch(choice) { case 1: answer=a.addition(A,B); a.setAnswer(answer); a.printOnScreen(); answer=a.addition(A,B)+A; a.setAnswer(answer); break; case 2: answer=a.subtraction(A,B); a.setAnswer(answer); break; case 3: answer=a.multiplication(A,B); a.setAnswer(answer); break; case 4: answer=a.division(A,B); a.setAnswer(answer); break; default: cout<<"Wrong choice"<<endl; } a.printOnScreen(); system("PAUSE"); return 0; }

    • one year ago
  2. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 1

    With the exception of this: answer=a.addition(A,B)+A; it all looks pretty good. Were you having difficulty with this code?

    • one year ago
  3. ajprincess
    Best Response
    You've already chosen the best response.
    Medals 2

    No. vat my problem is i dnt knw how to include a code that instructs the arithmetic operations to be repeated. because that's vat the question asks me to do.

    • one year ago
  4. ajprincess
    Best Response
    You've already chosen the best response.
    Medals 2

    @eSpeX

    • one year ago
  5. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 1

    You could enclose the main switch section in a while loop, this would cause it to repeat until some condition, maybe while(choice != 0). Is that what you're looking to do?

    • one year ago
  6. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 1

    while(choice != 0) { cout<<"Enter the choice:\n"; cout<<"Press 1 for addition:\n"; cout<<"Press 2 for subtraction:\n"; cout<<"Press 3 for multiplication:\n"; cout<<"Press 4 for division:\n"; cout<<"Press 0 to exit:"; cin>>choice; switch(choice) { case 0: break; case 1: answer=a.addition(A,B); a.setAnswer(answer); a.printOnScreen(); answer=a.addition(A,B)+A; a.setAnswer(answer); break; case 2: answer=a.subtraction(A,B); a.setAnswer(answer); break; case 3: answer=a.multiplication(A,B); a.setAnswer(answer); break; case 4: answer=a.division(A,B); a.setAnswer(answer); break; default: cout<<"Wrong choice"<<endl; } a.printOnScreen(); system("PAUSE"); } return 0;

    • one year ago
  7. ajprincess
    Best Response
    You've already chosen the best response.
    Medals 2

    No. i didn't mean this. I want the addition operation to repeat again by the insertion of single code.

    • one year 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.