fork(1) download
  1. #include <iostream>
  2. using namespace std; // consider removing this line in serious projects
  3.  
  4. class Game{
  5. private:
  6. int goals;
  7.  
  8. public:
  9. Game();
  10. int getGoals();
  11. void incrementGoals();
  12. };
  13.  
  14. void Game::incrementGoals(){
  15. goals++;
  16. }
  17.  
  18. Game::Game(){
  19. goals = 0;
  20. }
  21.  
  22. int Game::getGoals(){
  23. return goals;
  24. }
  25.  
  26. int main() {
  27. Game football;
  28.  
  29. cout << "Number of goals at start: " << football.getGoals() << endl;
  30.  
  31. football.incrementGoals();
  32. football.incrementGoals();
  33.  
  34. cout << "GAME... Final score " << football.getGoals() << endl;
  35.  
  36. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Number of goals at start: 0
GAME... Final score 2