Haven't bothered to test this, but it should work with little (or no) fixes:
typedef double valuetype;
class sequencer {
public:
virtual valuetype getNext(valuetype v) = 0; valuetype getAt(std::size_t iterations, valuetype initial_value) {
v = initial_value;
for (std::size_t i = 0; i < iterations; ++i) {
v = getNext(v);
}
return v;
}
};
class AddSinusSequence : public sequencer {
public:
virtual valuetype getNext(valuetype v) {
return v + sin(v);
}
};
int main() {
AddSinusSequence ass;
std::cout << "first value: " << 1.5 << std::endl;
std::cout << "fifth value: " << ass.getAt(5, 1.5) << std::endl;
return 0;
}
Note that there is in fact no need for the two classes if there is really only one function you're interested in: I only used the classes as a means to separate the function you want to iterate from the actual calculation based on that.
[edit] added missing
: public sequencer
[/edit]
[edit2] the simple version:
double AddSinus(double value) {
return value + sin(value);
}
double getAt(unsigned i, double initial_value) {
double v = initial_value;
for (unsigned i=0; i < iterations; ++i)
v = AddSinus(v);
return v;
}
int main() {
double initial = 1.5;
double v_at_5 = getAt(5, initial);
return 0;
}
[/edit2]