This lab is worth 10 points and accounts for 12.5 percent of your laboratory grade. The points will be subjectively assigned by your TA based upon whether they believe you made a good faith effort toward complete the tasks that are assigned. Showing up on time, respecting your fellow classmates learning environment, and adherance to laboratory policies also factor into the determination of your score.
The following is an outline of the tasks for you to attempt during the lab period.
A framework containing the files and folders you will need can be found here. Download the .tgz file and decompress it in your account using the command:
tar -xzvf <file_name>
The following tasks require you to use the graphical package that is described in Chapter 3 of the Big C++ book. A introduction to using the tools that are described in that chapter can be found here.
Use the file star.cpp in the folder star to program the following task. Using any coordinate system that you want, draw a five pointed star. The output of your program may look like the following:
To compile your program use g++ from the command line.( ie. type g++ -L ... ).
Useing the file Makefile in the folder star write a makefile which compiles the star program and generates an executable named "star". Your makefile should use all the compiler options to g++ that are specified in the class coding standard.
A common problem when working with graphics is that you may want to draw the same object at different sizes. For example you may be writing a program that allows you to zoom in to see greater detail. One way that you can do this with the graphics package provided with the book is to change the coordinate system of the window so that the object is drawn either smaller or larger. Although this is quite handy, not all graphics libraries support this feature.
Another way of supporting this feature is to write the code which draws the object in terms of a generic unit that is redefined every time the drawing routine is called. Hence the object being drawn is always the same number of units high, and the same number of units wide; only the size of the unit changes.
Use the files triangle.cpp and Makefile in the folder triangle to implement the following task. Using the unit strategy write a function which draws a triangle. In the main function write a loop that draws the triangle in the center of the drawing window at about 5 different sizes ( start small and finish when the triangle is roughly the size of the drawing window. ) In order to be able to see the triangle drawn each time you should read in a mouse click each iteration of the loop. When the person running your program is ready to see the next size of triangle they will click on the drawing window.
Use the files click.cpp and Makefile in the folder click to program the following task. Using the default coordinate system, write a program which recieves mouse clicks from the user and prints a message in the graphic window stating "You Clicked Here" wherever the mouse was clicked. Your program should loop until the user clicks in the 3rd quadrant of the graphic area using the standard cartesian coordinate system( ie. both the x and y coordinate of the mouse click will be negative ).
In addition to the program, write a makefile to compile your program. Again, use the options to the compiler which are given in the class coding standard, but this time use the default executable name of "a.out"
Use the files box.cpp and Makefile in the folder box to program the following task. Using whatever coordinate you desire, write a program ( and accompaning makefile ) which draws a rectangle in the graphic window. Next get a mouse click from the user, then tell the user whether the mouse click was inside the rectangle or outside of the rectangle.
Once your program works correctly, re-write the code for detecting whether the mouse click fell inside the rectangle as a function. The function should take as parameters:
Have the function return a boolean variable. True if the users click was inside the rectangle, and false if the users click was outside of the rectangle.