Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Calculator
- {
- public:
- void addition(double a,double b)
- {
- cout<<"The result of addition "<<a+b<<endl;
- }
- void subtraction(double a,double b)
- {
- cout<<"The result of subtraction "<<a-b<<endl;
- }
- void multiplication(double a,double b)
- {
- cout<<"The result of multiplication "<<a*b<<endl;
- }
- void division(double a,double b)
- {
- if(b==0)
- {
- cout<<"Undefined"<<endl;
- }
- else
- {
- cout<<"The result of division "<<a/b<<endl;
- }
- }
- };
- int main()
- {
- while(true)
- {
- Calculator calc;
- char c;
- cout<<"Enter your choice"<<endl;
- cout<<"+ for addition"<<endl;
- cout<<"- for subtraction"<<endl;
- cout<<"* for multiplication"<<endl;
- cout<<"/ for division"<<endl;
- cout<<"e/E for Exit"<<endl;
- cin>>c;
- if(c=='+')
- {
- cout<<"Enter two numbers"<<endl;
- double a,b;
- cin>>a>>b;
- calc.addition(a,b);
- }
- else if(c=='-')
- {
- cout<<"Enter two numbers"<<endl;
- double a,b;
- cin>>a>>b;
- calc.subtraction(a,b);
- }
- else if(c=='*')
- {
- cout<<"Enter two numbers"<<endl;
- double a,b;
- cin>>a>>b;
- calc.multiplication(a,b);
- }
- else if(c=='/')
- {
- cout<<"Enter two numbers"<<endl;
- double a,b;
- cin>>a>>b;
- calc.division(a,b);
- }
- else if(c=='e' || c=='E')
- {
- break;
- }
- else
- {
- cout<<"Invalid choice"<<endl;
- cout<<"Enter again"<<endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment