| PSICS Fall 2004 Quiz #13 |
|   PSICS Home   |   Description |
Submit your solutions to this quiz by dropping in your webct drop box in the box labeled "Quiz13". Let Dave know if you have problems submitting!
| Assignment |
Below are listed two C++ functions you need to write, each of these functions prints out some scheme code. The main program below can be used to test your C++ functions, which should generate scheme code that produced the following drawing:
Write the function draw_circles that draws a number of circles whose center is given by x and y. The largest circle drawn should have a radius r, the function should generates a circle of radius r-10 (and r-20, etc) until the radius becomes smaller then 10 (stop once you have a circle with radius <= 10).
Your C++ function should generate the scheme code that draws the appropriate circles (use cout to output the scheme code). For example, if your function was called like this:
draw_circles(100,100,100);
the output should be some scheme code that calls the scheme draw-circle function that produces something like this:

Write the function draw_checkerboard that draws a black and red checkerboard whose top left coordinate is given by x and y. Each cell on the board should be a square of size cellsize. The checkerboard should be width x width (width rows and width columns).
Your C++ function should generate the scheme code that draws the checkerboard. For example, if your function was called like this:
draw_checkerboard(100,100,4,50);
the output should be some scheme code that calls the scheme draw-solid-rect function (many times) that produces something like this:

Below is a C++ main() function you can use to test your functions. If you take the output and save it in a scheme file, then run the scheme code you should see something like the image shown:
// Sample main
int main() {
// initial output calls the scheme start function
cout << "(start 400 400)" << endl;
// draw a bunch of circles
draw_circles(200,100,100);
draw_circles(100,200,100);
draw_circles(200,300,100);
draw_circles(300,200,100);
// draw a 4x4 checkerboard
draw_checkerboard(100,100,4,50);
return(0);
}
|
![]() |
You can run your C++ program from the command line (inside a "Shell Window") and save the output to a file, which you can then load in drscheme and run. Dave will demonstrate this in class.