A community for students.
Here's the question you clicked on:
 0 viewing
ajprincess
 3 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
ajprincess
 3 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

ajprincess
 3 years ago
Best ResponseYou've already chosen the best response.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 (numberAnumberB); } 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; }

eSpeX
 3 years ago
Best ResponseYou've already chosen the best response.1With the exception of this: answer=a.addition(A,B)+A; it all looks pretty good. Were you having difficulty with this code?

ajprincess
 3 years ago
Best ResponseYou've already chosen the best response.2No. 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.

eSpeX
 3 years ago
Best ResponseYou've already chosen the best response.1You 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?

eSpeX
 3 years ago
Best ResponseYou've already chosen the best response.1while(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;

ajprincess
 3 years ago
Best ResponseYou've already chosen the best response.2No. i didn't mean this. I want the addition operation to repeat again by the insertion of single code.
Ask your own question
Sign UpFind 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
 Engagement 19 Mad Hatter
 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.