• (2 Pages)
• 1
• 2

## GRAPHING ALGEBRAIC FUNCTIONS USING C++ AND FLTK TUTORIAL GRAPHING ALGEBRAIC FUNCTIONS USING C++ AND FLTK TUTORIAL Rate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=123338&amp;s=82baa9c176a74fe58589b446539f4122&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Elcric

• D.I.C Regular

Reputation: 102
• Posts: 453
• Joined: 02-May 09

Posted 01 September 2009 - 10:54 AM

GRAPHING ALGEBRAIC FUNCTIONS USING C++ AND FLTK TUTORIAL

YOU WILL LEARN HOW TO GRAPH THE FOLLOWING ALGEBRAIC FUNCTIONS USING C++ AND FLTK:

1. HORIZONTAL LINE

2. SLOPING LINE

3. PARABOLA

• I. INTRODUCTION

Hello; nice to meet you! Welcome to the “GRAPHING ALGEBRAIC FUNCTIONS USING C++ AND FLTK TUTORIAL.”

This tutorial is a very brief overview of information presented by Dr. Bjarne Stroustrup in his book “Programming Principles and Practices Using C++,” Addison-Wesley 2009, ISBN 978-0321543721.

The web site for his book and the appropriate FLTX .h header files and .cpp files is:

http://www.stroustrup.com/Programming/

Please copy and paste the following example program into your IDE; then build and debug the example program.

```//***********************************************
//GRAPHING ALGEBRAIC FUNCTIONS
//USING C++ AND FLTK TUTORIAL
//***********************************************
#include "Simple_window.h"
#include "Graph.h"

double one(double)
{
return 1;
}

double slope(double x)
{
return x/2;
}

double square(double x)
{
return x*x;
}

int main( int argc, char* argv[] )
{
using namespace Graph_lib;
Point tl(100, 100);

const int xmax = 600;
const int ymax = 400;

const int x_orig = xmax/2;
const int y_orig = ymax/2;
const Point orig(x_orig,y_orig);

const int r_min = -10;
const int r_max = 11;

const int n_points = 400;

const int x_scale = 30;
const int y_scale = 30;
Simple_window win(Point(100,100),xmax,ymax,"FUNCTION GRAPHING");

Function s(one,r_min,r_max,orig,n_points,x_scale,y_scale);
Function s2(slope,r_min,r_max,orig,n_points,x_scale,y_scale);
Function s3(square,r_min,r_max,orig,n_points,x_scale,y_scale);

win.attach(s);
win.attach(s2);
win.attach(s3);

Text ts(Point(100,y_orig-40),"one");
Text ts2(Point(100,y_orig+y_orig/2-20),"x/2");
Text ts3(Point(x_orig-100,20),"x*x");
win.set_label("Function Graphing: Label Functions");
win.wait_for_button();

win.attach(ts);
win.attach(ts2);
win.attach(ts3);
win.wait_for_button();

const int xlength = xmax-40;
const int ylength = ymax-40;

Axis x(Axis::x,Point(20,y_orig),xlength,xlength/x_scale,"one notch == 1");
Axis y(Axis::y,Point(x_orig,ylength+20),
ylength,ylength/y_scale,"one notch == 1");

x.set_color(Color::dark_red);
y.set_color(Color::dark_red);

win.attach(x);
win.attach(y);

win.wait_for_button();
}

```

• II. HORIZONTAL LINE

A line parallel to the x-axis is called a horizontal line. A horizontal line is parallel to the x-axis because the y value never changes.

We get a horizontal line by graphing the following function:

```double one(double)
{
return 1;
}

```

The line is defined by (x,y) == (x,1) for all x. In other words, we get the y value 1 for every x passed as an argument to the function one().

The following code specifies how it is to be drawn in the window:

```Function s(one,r_min,r_max,orig,n_points,x_scale,y_scale);

```

The function specifies how its first argument, a function of one double argument returning a double, is to be drawn in the window.

The second argument and the third argument give the range of x, the argument to the function to be graphed.

The fourth argument, orig, tells the function where origin (0,0) is to be located within the window.

The remaining three arguments are default arguments. The function constructor arguments n_points, xscale and yscale were given the following initializers in the declaration. The default argument values are used if the caller does not specify values.

```const int n_points = 400;

const int x_scale = 30;
const int y_scale = 30;

```

The graph label is as follows:

```Text ts(Point(100,y_orig-40),"one");

```

The following code attaches the function and the graph label to win.

```win.attach(s);
win.attach(ts);

```

• III. SLOPING LINE

The slope of a line is referred to as the rise over the run, or given two points on the line, the change in the y coordinates over the change in x coordinates.

We get a sloping line by graphing the following function:

```double slope(double x)
{
return x/2;
}

```

The line is defined by (x,y) == (x,x/2). For every x we get the y value x/2.

The point where the two lines cross is (2,1).

The following code specifies how it is to be drawn in the window:

```Function s2(slope,r_min,r_max,orig,n_points,x_scale,y_scale);

```

The function specifies how its first argument, a function of one double argument returning a double, is to be drawn in the window.

The second argument and the third argument give the range of x, the argument to the function to be graphed.

The fourth argument, orig, tells the function where origin (0,0) is to be located within the window.

The remaining three arguments are default arguments. The function constructor arguments n_points, and xscale were given the following initializers in the declaration. The default argument values are used if the caller does not specify values.

```const int n_points = 400;

const int x_scale = 30;

```

The graph label is as follows:

```Text ts2(Point(100,y_orig+y_orig/2-20),"x/2");

```

The following code attaches the function and the graph label to win.

```win.attach(s2);
win.attach(ts2);

```

• IV. PARABOLA

We get a parabola by graphing the following function:

```double square(double x)
{
return x*x;
}

```

The line is defined by (x,y) == (x,x*x). The lowest point where the parabola touches the sloping line is (0,0). The parabola is symmetric on the y axis.

The following code specifies how it is to be drawn in the window:

```Function s3(square,r_min,r_max,orig,n_points,x_scale,y_scale);

```

The function specifies how its first argument, a function of one double argument returning a double, is to be drawn in the window.

The second argument and the third argument give the range of x, the argument to the function to be graphed.

The fourth argument, orig, tells the function where origin (0,0) is to be located within the window.

The remaining three arguments are default arguments. The function constructor arguments n_points were given the following initializer in the declaration. The default argument value is used if the caller does not specify a value.

```const int n_points = 400;

```

The graph label is as follows:

```Text ts3(Point(x_orig-100,20),"x*x");

```

The following code attaches the function and the graph label to win.

```win.attach(s3);
win.attach(ts3);

```

Is This A Good Question/Topic? 2

## Replies To: GRAPHING ALGEBRAIC FUNCTIONS USING C++ AND FLTK TUTORIAL

### #2 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 17 September 2010 - 07:05 AM

zomg i'm so gonna take this tutorial NOW

### #3 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 26 September 2010 - 04:47 PM

call me lazy, but i'm kinda salty over getting this FLTK stuff working. I dunno I'll figure it out eventually

### #4 snoopy11

• Engineering ● Software

Reputation: 1458
• Posts: 4,726
• Joined: 20-March 10

Posted 04 October 2010 - 03:48 AM

To get this Tutorial to run is not that easy

First you need to go to Bjarne Strousstrup's page as the tutorial says
and you need to copy
GUI.cpp
window.cpp
Graph.cpp
Simple_window.cpp

then

GUI.h
Graph.h
window.h
Simple_window.h
Point.h
std_lib_facilities.h

you will also need to link to the libraries
fltk
fltkimages
and
jpeg

why we are not told this in the tutorial I dont know ?

It would have been nice but it works so hey ho

### #5 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 04 October 2010 - 02:18 PM

snoopy11, on 04 October 2010 - 02:48 AM, said:

To get this Tutorial to run is not that easy

First you need to go to Bjarne Strousstrup's page as the tutorial says
and you need to copy
GUI.cpp
window.cpp
Graph.cpp
Simple_window.cpp

then

GUI.h
Graph.h
window.h
Simple_window.h
Point.h
std_lib_facilities.h

you will also need to link to the libraries
fltk
fltkimages
and
jpeg

why we are not told this in the tutorial I dont know ?

It would have been nice but it works so hey ho

I can't seem to build the fltk libraries. I get all kinds of errors on win7 vs2010. I've tried building 1.1 and 1.3

### #6 snoopy11

• Engineering ● Software

Reputation: 1458
• Posts: 4,726
• Joined: 20-March 10

Posted 04 October 2010 - 08:27 PM

and then do this
go to fltk1.1.10\vc2005
then you will see a host of .vcproj files
double click on fltk.lib.vcproj
this should fire up msvc 2010
It will ask you if you want to convert the project click on yes
This will take a while have a coffee
Then it will convert about 70 projects into one soloution file
Build it as a release this will take a while have another coffee
go to fltk1.1.10\lib and you will now see a host of library .lib
files.

This post has been edited by snoopy11: 04 October 2010 - 08:33 PM

### #7 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 04 October 2010 - 09:37 PM

snoopy11, on 04 October 2010 - 07:27 PM, said:

and then do this
go to fltk1.1.10\vc2005
then you will see a host of .vcproj files
double click on fltk.lib.vcproj
this should fire up msvc 2010
It will ask you if you want to convert the project click on yes
This will take a while have a coffee
Then it will convert about 70 projects into one soloution file
Build it as a release this will take a while have another coffee
go to fltk1.1.10\lib and you will now see a host of library .lib
files.

thanks for the reply, have done everything you've said, up until the build. Then I get errors. I'll rebuild so that i can give you the list.
(an hour later)
well, debug just freezes and refuses to build,
trying to build the release version now.
10 errors and one skipped. the rest succeeded.
The first one says access denied but i run VS2010 in admin mode. I don't get it.
```Error	28	error c101008d: Failed to write the updated manifest to the resource of file "../test/navigation.exe". Access is denied.	C:\flt\fltk-1.1.10\vc2005\mt.exe	navigation
Error	56	error FTK1011: could not create the new file tracking log file: C:\flt\fltk-1.1.10\vc2005\Release\CL.read.1.tlog. The file exists.	C:\flt\fltk-1.1.10\vc2005\FileTracker	adjuster
Error	31	error FTK1011: could not create the new file tracking log file: C:\flt\fltk-1.1.10\vc2005\Release\CL.write.1.tlog. The file exists.	C:\flt\fltk-1.1.10\vc2005\FileTracker	mandelbrot
Error	11	error LNK1181: cannot open input file 'fltk.lib'	C:\flt\fltk-1.1.10\vc2005\LINK	line_style
Error	57	error MSB6003: The specified task executable "CL.exe" could not be run. The process cannot access the file 'C:\flt\fltk-1.1.10\vc2005\Release\cl.read.1.tlog' because it is being used by another process.	C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets	147	6	cube
Error	69	error MSB6003: The specified task executable "CL.exe" could not be run. The process cannot access the file 'C:\flt\fltk-1.1.10\vc2005\Release\cl.read.1.tlog' because it is being used by another process.	C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets	147	6	input_choice
Error	36	error MSB6003: The specified task executable "CL.exe" could not be run. The process cannot access the file 'C:\flt\fltk-1.1.10\vc2005\Release\cl.write.1.tlog' because it is being used by another process.	C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets	147	6	image
Error	49	error MSB6006: "mt.exe" exited with code 31.	C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets	562	6	tiled_image

```

This post has been edited by laserbeak43: 04 October 2010 - 09:38 PM

### #8 snoopy11

• Engineering ● Software

Reputation: 1458
• Posts: 4,726
• Joined: 20-March 10

Posted 05 October 2010 - 03:21 AM

What is your Platform Toolset set to ?

### #9 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 05 October 2010 - 05:19 AM

as in 32 or 64 bit? 32.
-edit-
Project > Properties > Config Properties > General > Platform Toolset: v100
My only other option is V90

This post has been edited by laserbeak43: 05 October 2010 - 05:23 AM

### #10 snoopy11

• Engineering ● Software

Reputation: 1458
• Posts: 4,726
• Joined: 20-March 10

Posted 05 October 2010 - 09:04 AM

laserbeak43, on 05 October 2010 - 04:19 AM, said:

as in 32 or 64 bit? 32.
-edit-
Project > Properties > Config Properties > General > Platform Toolset: v100
My only other option is V90

See if that changes anything other than that I can only think your compiler isnt functioning as it should.

### #11 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 05 October 2010 - 09:12 AM

snoopy11, on 05 October 2010 - 08:04 AM, said:

See if that changes anything other than that I can only think your compiler isnt functioning as it should.

Hmm I thought I Had the win7 SDK. OK i'll see what i have setup when i get a chance, I'll let you know what happens. Thanks for your advice.

### #12 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 05 October 2010 - 05:05 PM

Ive installed the SDK but i've gotten no change in the platform options

### #13 snoopy11

• Engineering ● Software

Reputation: 1458
• Posts: 4,726
• Joined: 20-March 10

Posted 05 October 2010 - 08:01 PM

Ok thats really weird........

when I installed the windows sdk it allowed me to change the platform toolset to it
only other thing i can recommend is reinstalling VS 2010.

something weird is going on with your compiler, dont what it is but its weird....

### #14 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 05 October 2010 - 08:27 PM

snoopy11, on 05 October 2010 - 07:01 PM, said:

Ok thats really weird........

when I installed the windows sdk it allowed me to change the platform toolset to it
only other thing i can recommend is reinstalling VS 2010.

something weird is going on with your compiler, dont what it is but its weird....

and what's the version? all i have is v90 and v100
I'll reinstall vs2010 and see what happens.

-edit-
after installing, I decided to run the sdk installer again. I got some new features to add. mainly under redistribution tools.
so i installed again, which made it sdk 7.1 and now i have that in vs2010.
So i'll try that and see what happens, thanks

This post has been edited by laserbeak43: 05 October 2010 - 08:52 PM

### #15 laserbeak43

Reputation: 4
• Posts: 134
• Joined: 07-November 09

Posted 05 October 2010 - 09:18 PM

ok built it and got 2 errors, 67 successes and 1 sipped, my two errors are
```Error	58	error c101008d: Failed to write the updated manifest to the resource of file "../test/labeld.exe". The operation failed.	C:\flt\fltk-1.1.10\vc2005\mt.exe	label
Error	15	error LNK1181: cannot open input file 'fltkd.lib'	C:\flt\fltk-1.1.10\vc2005\LINK	line_style

```

I don't know the importance of a manifest, or if it even matters but for the fltkd.lib error, am i supposed to link the lib found in "../lib"?
I don't really see what's been skipped either. I'm stumped.

Thanks