Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "func1.cpp"
- #include "func2.cpp"
- using namespace std;
- class Function {
- public:
- void (*function_pointer)();
- string description;
- Function(void (*function_pointer)(), string description) {
- this->function_pointer = function_pointer;
- this->description = description;
- }
- };
- int main() {
- Function *functions[] = {
- new Function(&function1, "The goal of this task is to print hello"),
- new Function(&function2, "The goal of this task is to print hello 2")};
- int number_of_functions = sizeof(functions) / sizeof(*functions);
- while (true) {
- cout << "Functions: " << endl;
- cout << "0. Finish" << endl;
- for (int i = 0; i < number_of_functions; i++) {
- cout << i + 1 << ". " << functions[i]->description << endl;
- }
- cout << endl;
- int function_number;
- cout << "Function number: ";
- cin >> function_number;
- cout << endl;
- if (function_number == 0) {
- break;
- } else if (function_number < 1 || function_number > number_of_functions) {
- cout << "--" << endl;
- cout << "Invalid function number" << endl;
- cout << "--" << endl << endl;
- } else {
- cout << "--" << endl;
- // call function
- (*functions[function_number - 1]).function_pointer();
- cout << "--" << endl << endl;
- }
- }
- // Clean
- for (int i = 0; i < number_of_functions; i++) {
- delete functions[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment