Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

ajprincess

  • 2 years ago

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

  • This Question is Closed
  1. ajprincess
    • 2 years ago
    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; }

  2. eSpeX
    • 2 years ago
    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?

  3. ajprincess
    • 2 years ago
    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.

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

    @eSpeX

  5. eSpeX
    • 2 years ago
    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?

  6. eSpeX
    • 2 years ago
    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;

  7. ajprincess
    • 2 years ago
    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.

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

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.