Remove the reading of the file part from your tasks and read up on the 'strategy'
pattern. Basically you want to do something with a sequence of numbers. Define
an abstract class Task that represents the number processing:
-
public:
-
void preprocess() = 0;
-
void process(double x) = 0;
-
double postprocess() = 0;
-
All your 'concrete' tasks inherit from this abstract class and implement the
methods mentioned above.
Define a 'driver' class that does the file reading; the driver class is passed one
or more task class. While reading those numbers it activates the methods
defined in the task class.
Basically your driver class doesn't know what task it calls and the task(s) doesn't
know where these numbers come from but both do what they have to do. You
can call your driver class with different tasks without changing any code at all.
This is the strategy pattern in a nutshell.
kind regards,
Jos