| 163 | { |
| 164 | public: |
| 165 | explicit Arithmetic(Menu* menu) |
| 166 | { |
| 167 | auto subMenu = make_unique<Menu>(Name(), "Enter the " + Name() + " plugin menu"); |
| 168 | subMenu->Insert( |
| 169 | "add", {"first_term", "second_term"}, |
| 170 | [](std::ostream& out, int x, int y) |
| 171 | { |
| 172 | out << x << " + " << y << " = " << (x+y) << "\n"; |
| 173 | }, |
| 174 | "Print the sum of the two numbers" ); |
| 175 | subMenu->Insert( |
| 176 | "add", |
| 177 | [](std::ostream& out, int x, int y, int z) |
| 178 | { |
| 179 | out << x << " + " << y << " + " << z << " = " << (x+y+z) << "\n"; |
| 180 | }, |
| 181 | "Print the sum of the three numbers" ); |
| 182 | subMenu->Insert( |
| 183 | "sub", {"subtrahend", "minuend"}, |
| 184 | [](std::ostream& out, int x, int y) |
| 185 | { |
| 186 | out << x << " - " << y << " = " << (x-y) << "\n"; |
| 187 | }, |
| 188 | "Print the result of a subtraction" ); |
| 189 | |
| 190 | menuHandler = menu->Insert(std::move(subMenu)); |
| 191 | } |
| 192 | ~Arithmetic() override |
| 193 | { |
| 194 | menuHandler.Remove(); |