Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class MyClass
  6. {
  7. private:
  8.     bool done;
  9.     double x;
  10.     double result;
  11.  
  12. public:
  13.     MyClass();
  14.     virtual ~MyClass() {}
  15.  
  16.     void set(double x);
  17.     void print();
  18.     void run();
  19. };
  20.  
  21. MyClass::MyClass()
  22. {
  23.     this->x = 0;
  24.     this->done = false;
  25. }
  26.  
  27. void MyClass::set(double x)
  28. {
  29.     this->x = x;
  30. }
  31.  
  32. void MyClass::print()
  33. {
  34.     if (this->done) {
  35.         std::cout << "Result: " << this->result << std::endl;
  36.     } else {
  37.         std::cout << "First execute method run();" << std::endl;
  38.     }
  39. }
  40.  
  41. void MyClass::run()
  42. {
  43.     this->result = (this->x + 100) / 10;
  44.     this->done = true;
  45. }
  46.  
  47. int main()
  48. {
  49.     MyClass myClass;
  50.     myClass.set(10);
  51.     myClass.run();
  52.     myClass.print();
  53.  
  54.     getchar();
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement