fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Adder{
  5. public:
  6. // constructor
  7. Adder()
  8. {
  9. }
  10. // interface to outside world
  11. void addNum(int number)
  12. {
  13. total += number;
  14. }
  15. // interface to outside world
  16. int getTotal()
  17. {
  18. return total;
  19. };
  20. private:
  21. // hidden data from outside world
  22. int total = 0;
  23. };
  24. int main( )
  25. {
  26. Adder a;
  27.  
  28. a.addNum(10);
  29. a.addNum(20);
  30. a.addNum(30);
  31.  
  32. cout << "Total " << a.getTotal() <<endl;
  33. return 0;
  34. }
Success #stdin #stdout 0s 5460KB
stdin
Standard input is empty
stdout
Total 60