Hi,
I have this code that displays graphical data:
Code:
Func::Func(Fct f, double r1, double r2, Point xy,
int cnt, double xscale, double yscale)
:count(cnt), range1(r1), origin(xy)
{
if(r2-range1<=0) error("bad graphing range");
if(count <=0) error("non-positive graphing count");
double dist = (r2-range1)/count;
double r = range1;
for(int i = 0; i<count; ++i) {
add(Point(origin.x+int(r*xscale), origin.y-int(f(r)*yscale)));
r+=dist;
}
}
The Fct f, is a function that I pass in, such as square, factorial etc. It all works and the graphs are displayed using a simple graphics library used in the book.
A typical object is created as such:
Code:
Func s1(square,-10,11, Point(300,300), 400, 25, 25);
An exercise in the book asks me to create member functions to allow for parameter changes. For example, the Point(300, 300) above is the origin of the graph.
So I thought I would simple create a function as such:
Code:
void Func::set_origin(Point& p)
{
origin = p;
}
And, then when I re-attach the graph to the window, the changes would be made. But this is not the case. Any body got any ideas?
Thanks.