In my program, someone enters a value for x, and this value goes into a function and the answer is returned. Now, I have a main.cpp, functions.h, and functions.cpp

There are 2 functions f(x) and g(x).

In main.cpp:

The user enters a value for x
The user is prompted to enter 1 to use f(x) or 2 for g(x).
functions(x) is called and finds f(x) or g(x)

Now, in my assignment it says:

"All functions and the main program must be defined in separate c++ source files and all functions must have separate header files). There is a way in C++ to pass a pointer to a function as an argument in a function call. Use this method to avoid writing two versions of the source code and run the code once to obtain the results."

I have read a lot of tutorials on function pointers and I still do not know how to implement this. From what I read, I would need two functions, one for f(x) and one for g(x). But, according to the assignment I would have to put them in seperate .cpp and .h files. But, this would be writing two versions of the source code.

I'm not sure how I am supposed to implement a function pointer without having seperate functions (one for f(x) and one for g(x)). I could easily just use if statements, but its not allowed.


Any ideas?

Thanks