CSCI 201 Lab 8 -- Flow Control and References in C++

Getting ready

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

You get two projects to start the lab. Download a ZIP'ed copy of the Lab 8 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: Color100 and Char104.

Conditional statement execution

Start up Visual C++ and open the workspace c:\files\Lab08\Color100\Color100.dsw. This workspace should contain three files

The driver program Color100.cpp plots four functions that you will write. You will use the mouse to move between these functions, just like you did in Lab 7.

"Templates" for the four functions you will modify are found in Funky.cpp. These functions receive two integers as arguments and return an EzWindows color. The driver function will divide the screen into 100 squares, 10 on each side. These squares will be addressed by their x and y co-ordinates, integers from zero to nine. Your program will be called with each of the 100 possible co-ordinate pairs and will be expected to return a color for the corresponding squares. Examine Funky.cpp and then build and execute Color100 to learn a bit more about the process.

Your task and your instructor's checkoff

You are to write four functions that do the following:
0 Returns Red, if x > y; White, if x equals y; and Blue, if x < y
1 Returns values that cause the window to resemble the flag of Ireland (three vertical stripes: green, white, and red) or any other European country.
2 Returns values that cause the window to resemble the flag of the state of North Carolina, but without the seal.
3 Returns values that cause the window to resemble the flag of the United States, but without the stars.

Reference variables

Open the workspace c:\files\Lab08\Char104\Char104.dsw. The driver program Char104.cpp displays the results of four procedures you will write. These procedures, or functions, are invoked with a single single input variable, a character, and with two reference variables, EzWindows background and foreground colors. Your program will examine its character input and use it to set the background and foreground colors.

Go ahead and look at Funky.cpp to see how these functions should look. The function MyFunc0 sets the foreground to blue for characters corresponding to digits and to yellow for all other characters. The background is set to green for vowels and to red for non-vowels. Build and execute the project to see it run.

Your task and your instructor's checkoff

You are to write three functions that do the following:
0 Sets the background to blue for all characters. Sets the foreground to red for characters that are hexadecimal digits and to blue for all other characters.
1 Sets the background to black for all letters in your last name and to white for all other characters. Sets the foreground to green for all letters in your first name and to red for all other characters.
2 Sets the foreground to black for all characters. Sets the background so that each of the colors red, green, blue, and yellow appears at least nineteen times.

Return to CSCI 201 page
CSCI logo Return to the UNCA Computer Science home page