Advertisement
Haval1

Final Question 2

Jan 20th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include"stdafx.h"
  2. #include "string"
  3. #include <iostream>
  4. /*
  5. write a cpp program to input two int number in main , and print sum in constructor function
  6. */
  7. using namespace std;
  8. class add {
  9. private:
  10.     int x, y;
  11. public:
  12.     add(int a, int b) {
  13.         x = a;
  14.         y = b;
  15.         cout << "sum : " << x + y << endl;
  16.     }
  17. };
  18. int main()
  19. {
  20.     int a, b;
  21.     cout << "a : ";
  22.     cin >> a;
  23.     cout << "b : ";
  24.     cin >> b;
  25.     add ad(a, b);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement