CSCI 201 Lab 7 -- Functions in C++

Getting ready

If a directory called C:\FILES\Lab07 presently exists on your computer, delete it.

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.

Go into the MS-DOS prompt and execute the following commands:

This should create two new directories, PLOT2d and PLOT3d. If you didn't see files being inflated when you run the pkunzip command, you need to see your instructor.

Plot in 2-D

Start up Visual C++ and open the workspace c:\files\Lab07\PLOT2D\PLOT2D.DSW. This workspace should contain three files

The driver program Main2D.cpp uses the EzWindows library to sequentially plot five functions that you will write. Use the mouse to move between functions. Press the X in the upper right corner of the window to terminate the program.

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:

float MyFuncN(const float x)
	return N*x ;

Go ahead and build and execute this project and look at its boring functions.

Your task

You are to replace these five functions with five functions that return the following values:

Lab instructor check-off 1

Once you've got the five functions plotted, show your work to the lab instructor.

Plot in 3-D

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 function you will write. It will pass two float arguments. 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:
.00 to .1666..Red
.1666.. to .3333..Yellow
.3333.. to .50Green
.50 to .6666..Cyan
.6666.. to .8333..Blue
.8333.. to .00Magenta

Go ahead and build and run the program. Then look at Main3D.cpp for details of the plotting routines.

Your modifications

Once again you modify Funky.cpp which, this time, contains five function similar to:
float MyFuncN(const float x, const float y)
	return x+N*y ;

Your five functions for the 3D plot are:

Lab instructor checkoff 2

When your plotting is complete, have your lab instructor take a look.
Return to CSCI 201 page
CSCI logo Return to the UNCA Computer Science home page