fork download
  1. // main.cpp:
  2.  
  3. #include <iostream>
  4. #include <functional>
  5.  
  6. int exercise1();
  7. int exercise2();
  8. int exercise3();
  9.  
  10. int prompt_user_for_exercise() {
  11. // TODO
  12. return 1;
  13. }
  14.  
  15. int main() {
  16. std::function<int()> exercises[] {
  17. exercise1,
  18. exercise2,
  19. exercise3 };
  20.  
  21. int choice = prompt_user_for_exercise();
  22. // probably wise to check that choice is in bounds
  23.  
  24. std::cout << "running exercise " << choice << "...\n";
  25. int result = exercises[choice](); // run exercise
  26. std::cout << "result = " << result;
  27.  
  28. return result;
  29. }
  30.  
  31. // exercise1.cpp:
  32.  
  33. int exercise1() {
  34. // do the stuff
  35.  
  36. return 0; // success, or 1 for failure
  37. }
  38.  
  39. // exercise2.cpp:
  40.  
  41. int exercise2() {
  42. // do the stuff
  43.  
  44. return 0; // success, or 1 for failure
  45. }
  46.  
  47. // exercise3.cpp:
  48.  
  49. int exercise3() {
  50. // do the stuff
  51.  
  52. return 0; // success, or 1 for failure
  53. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
running exercise 1...
result = 0