Want more features on Pastebin? Sign Up, it's FREE!
Guest

ARNMDH Example

By: a guest on Oct 2nd, 2012  |  syntax: C++  |  size: 1.70 KB  |  views: 76  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "numericmenu.h"
  2.  
  3. void tri() {
  4.     size_t size;
  5.     std::cerr << "How big do you want your triangle?\nEnter the number of rows: ";
  6.     std::cin >> size;
  7.     for(size_t i = 0; i < size; ++i) {
  8.         for (size_t j = 0; j < i+1; ++j) {
  9.             std::cerr << '*';
  10.         }
  11.          std::cerr << '\n';
  12.     }
  13. }
  14.  
  15. class Square {
  16. public:
  17.     void operator()() {
  18.         size_t size;
  19.         std::cerr << "How big do you want your square?\nEnter the number of rows: ";
  20.         std::cin >> size;
  21.         for(size_t i = 0; i < size; ++i) {
  22.             for (size_t j = 0; j < size; ++j) {
  23.                 std::cerr << '*';
  24.             }
  25.              std::cerr << '\n';
  26.         }
  27.     }
  28. };
  29.  
  30.  
  31. int main() {
  32.     nmenu::MenuList menu("Go to the main menu.");
  33.     nmenu::MenuList meno("Go to an empty menu.", &menu);
  34.     nmenu::MenuList menopause("Go to the Asterisk Geometry menu.");
  35.     nmenu::MenuExit paws("","You just exited the program. Have a nice day!\n");
  36.  
  37.     Square squ;
  38.     auto ev = [&menu](){menu.disconnect(1);};
  39.  
  40.     nmenu::MenuItem<decltype(&ev)> discon("Remove this option from the menu.",&ev,&menu);
  41.     nmenu::MenuExit ter("Please don't choose this. I don't want to be terminated.","You're so mean. *dies*\n");
  42.  
  43.     menu.connect(&menopause);
  44.     menu.connect(&discon);
  45.     menu.connect(&meno);
  46.     menu.connect(&paws);
  47.     menu.connect(&ter);
  48.  
  49.     nmenu::MenuItem<void(*)()> twi("Make the program print a triangle of asterisks.",tri,&menopause);
  50.     nmenu::MenuItem<Square> rec("Make the program print a square of asterisks.",squ,&menopause);
  51.  
  52.     menopause.connect(&menu);
  53.     menopause.connect(&twi);
  54.     menopause.connect(&rec);
  55.  
  56.     menu.exec();
  57.     return 0;
  58. }
clone this paste RAW Paste Data