Advertisement
Maaaruf

Addition and Subtraction using class

Oct 18th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class calculation{
  6.     public:
  7.     int num1,num2,result;
  8.  
  9.     void takeInput(){
  10.         cout<< "Enter num1 :";
  11.         cin>> num1;
  12.         cout<< "Enter num2 :";
  13.         cin>> num2;
  14.     }
  15.  
  16.  
  17.     int sum(){
  18.         takeInput();
  19.         result = num1+num2;
  20.         return result;
  21.     }
  22.  
  23.     int sub(){
  24.         result = num1-num2;
  25.         return result;
  26.     }
  27. };
  28.  
  29. int main()
  30. {
  31.     calculation object;
  32.     int sub,sum;
  33.     sum = object.sum();
  34.     sub = object.sub();
  35.  
  36.     cout<< "Sum of "<< object.num1<< " and "<< object.num2<< " is "<< sum<< endl;
  37.     cout<< "Subtraction of "<< object.num1<< " and "<< object.num2<< " is "<< sub;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement