Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <math.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. class CHelloWorld {
  9.     int nNum;
  10. public:
  11.     void setnum(int nNumToSet) { nNum = nNumToSet; }
  12.     int getnum() { return nNum; }
  13.  
  14.     void increase()     { nNum++; }
  15.     void decrease()     { nNum--; }
  16.     void doublenum()    { nNum = nNum * 2; }
  17.     void halfnum()      { nNum = nNum / 2; }
  18. };
  19.  
  20. int main () {
  21.  
  22.     CHelloWorld hello1, hello2; //declaring 2 objects of CHelloWorld, each holding their own values.
  23.  
  24.     //hello1
  25.  
  26.     cout << "Hello1 Object:\n";
  27.  
  28.     hello1.setnum( 10 );
  29.  
  30.     cout << hello1.getnum() << endl;
  31.  
  32.     hello1.doublenum();
  33.  
  34.     cout << hello1.getnum() << endl;
  35.  
  36.     hello1.halfnum();
  37.  
  38.     cout << hello1.getnum() << endl;
  39.  
  40.     hello1.increase();
  41.  
  42.     cout << hello1.getnum() << endl;
  43.  
  44.     cout << "Hello2 Object:\n";
  45.  
  46.     //hello2
  47.     hello2.setnum( 25 );
  48.  
  49.     cout << hello2.getnum() << endl;
  50.  
  51.     hello2.doublenum();
  52.  
  53.     cout << hello2.getnum() << endl;
  54.  
  55.     hello2.halfnum();
  56.  
  57.     cout << hello2.getnum() << endl;
  58.  
  59.     hello2.increase();
  60.  
  61.     cout << hello2.getnum() << endl;
  62.  
  63.     system( "pause" );
  64.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement