We're going to give you two projects to start the lab. Download a ZIP'ed copy of the Lab 7 projects and store it in the C:\files directory.
Use PowerZip to open this archive and then to extract the files to the C:\ directory. This should create a new directory c:\files\lab08 with two subdirectories, PLOT2d and PLOT3d. Check to make sure these directories exist before proceeding.
The driver program Main2D.cpp
uses the EzWindows library to sequentially plot five functions that
you will write.
You should not modify Main2D.cpp in this lab.
However, you are encouraged to look at it to learn a bit more about
C++ and EzWindows.
The program you will modify is called
Funky.cpp.
Presently, this program contains five simple functions similar to:
The values returned by these functions produced the boring output that
you saw when you ran the program.
You are to replace these five functions with five functions that
return the following values:
You will need to use functions from the math library to write the
functions described above. Page 250 of your text lists a few of the
functions in the math library. Notice that the file cmath
is included in funky.cpp, this is the "include" file for the math
library.
OK. You really can't plot in three dimensions, put you can do
something close. Open the workspace
c:\files\Lab07\PLOT3D\PLOT3D.DSW. Again, this workspace
will contain three files
The driver program Main3D.cpp
will call the functions that you will write. It will pass
two float values (also called arguments) to your function.
Your function will return a float which will be used in the
plot. Since we don't have 3-D holographic displays, we have to plot
your function on a two dimensional screen. This is done by using the
number returned by your function to choose between six different
colors. The succinct explanation is that everything before the
decimal point in your floating point number is discarded, and the
fractional part is used to select a color from the following table:
Go ahead and build and run the programs in this project.
Then look at Main3D.cpp for
details of the plotting routines.
Once again you modify Funky.cpp
which, this time, contains five function similar to:
Your five functions for the 3D plot are:
float MyFuncN(const float x)
{
return N*x ;
}
Your task
-x, if x is negative,
and x, if x is positive
0, if x is zero
Go into a for-loop,
and execute z = z*z 10 times.
In a second for-loop,
execute z = sqrt(z) 10 times.
Return z as the result of your function.
Lab instructor check-off 1
Once you've got the five functions plotted, show your work
to the lab instructor.
Plot in 3-D
Range Color
.00 to .1666.. Red
.1666.. to .3333.. Yellow
.3333.. to .50 Green
.50 to .6666.. Cyan
.6666.. to .8333.. Blue
.8333.. to .00 Magenta
Your modifications
float MyFuncN(const float x, const float y)
{
return x+N*y ;
}
y, if x < y
Don't worry, your function will not be called when either
x or y is equal to zero.
MAX(|x|, |y|)
Lab instructor checkoff 2
When your plotting is complete, have
your lab instructor take a look.
Return to CSCI 201 page
Return to the UNCA Computer Science home page