Advertisement
Haval1

Final Question

Jan 20th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include"stdafx.h"
  2. #include "string"
  3. #include <iostream>
  4. /*
  5. write a cpp class to claculate distnace as the following
  6. -create object to distnace between kirkuk and baghdad
  7. -create object to distnace between baghdad and basra
  8. -calculate distance between kirkuk and basra
  9. */
  10. using namespace std;
  11. class distnace {
  12. private:
  13.     int dis;
  14. public:
  15.     distnace(int d) {
  16.         dis = d;
  17.     }
  18.     distnace() {
  19.     }
  20.     void print_dis() {
  21.         cout << dis << endl;
  22.     }
  23.     int get_dis() {
  24.         return dis;
  25.     }
  26. };
  27. int main()
  28. {
  29.     distnace kb(100), bb(70), kba;
  30.     cout << "distnace : ";
  31.     kb.print_dis();
  32.     cout << "distnace 2 : ";
  33.     bb.print_dis();
  34.     kba = kb.get_dis() + bb.get_dis();
  35.     cout << "dis : ";
  36.     kba.print_dis();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement