CSC 15 Lab 2 Due one week from date assigned The week's assignment is in two parts. part I: Following the example of the minutes and seconds program shown in class (also on webpage), you are to write a similar program that does the following: Take as input an integer value representing an amount of money in cents. For example, if the user enters 72, it's meant to represent 72 cents. You are to compute the optimal change one should make using quarters, dimes, nickels and pennies. The optimal change is made with the fewest coins possible. For example, you don't use 1 dime and 62 pennies for 72 cents, but 2 quarters, 2 dimes, 0 nickels, and 2 pennies. SKETCH OUT the algorithm you will use on paper before coding! You'll need to turn in this draft. You'll need to define at least four variables for the number of coins of each type you might need. You may also need additional variables to hold intermediate values. ********** You MUST describe in COMMENTS (preceeded by #) what the purpose of each variable is. The basic algorithm is: compute the number of quarters needed. determine the amount of money left over after subtracting the quarters compute the number of dimes needed. determine the amount of money left over after substracting the dimes and so on ... You program's transcript should look something like this: Enter amount of money in cents: 82 The optimal change is: 3 quarters, 0 dimes, 1 nickels and 2 cents. OPTION: After you have the basic program working, modify it by using a while loop to run the program repeatedly until the user enters 0 cents. ------------------------------------------------------------------------------ part II: The second part of this lab will try to teach you the advantage of making your programs abstract by using variables. NOTE: There's a separate sheet attached to this lab! For this assignment you are to draw a stick figure like the one shown in class. It should have a round head, nose, mouth, torso, arms, and legs. You may add other features as you see fit. ************************************** YOU MUST FIRST complete the worksheet by working out the coordinates of all the major points of the figure. ************************************** First download the skeleton program fig.py from the class homepage and make sure you can run it. It draws a diamond. Find the procedure "drawfigure" towards the bottom of this program. There's already code in the methods, but you are to erase (or comment them out) and replace it with your own code. Instead of a diamond it should draw a stick figure. The object 'brush' manages the drawing of shapes onto a display area. You can use the following basic drawing statements in your code: brush.draw_line(gc,x1,y2,x2,y2); : this statement draws a line between the two point coordinates x1,y1 and x2,y2 brush.draw_rectangle(gc,False,x,y,w,h); : This statement draws a rectangle with upper left corner at coordinate x,y, and has width w and height h. Note that the last two argument does not represent a coordinate; they are relative to x and y. If False is changed to True, it would draw a solid (filled-in) rectangle instead. drawcircle(brush,x,y,r,False): this statement will draw a circle centered at coordinate x,y and has radius r. Again, if True was used instead of false, the circle will be filled in. Note that this statement is called differently from draw_line and draw_rectangle. That's because it's a function that I defined for you, instead of a built-in pygtk function. gc.set_foregroud(blue); : Changes drawing color. I've defined the most common colors (see file). If you want to experiment with other drawing methods, go to www.pygtk.org/docs/pygtk/class-gdkdrawable.html The size of the window is 800X650 pixels - this means that the range of the x coordinate is 0-799, and for the y coordinate 0-649. Coordinate 0,0 represents the top left hand corner of the window. coordinate 0,649 represents the lower left hand corner, etc... The variables (at the top of the skeleton file) width and height controls the size of the window, so you can change it as well. For commenting, make clear as to what part of the anatomy you're drawing with each command. If you have additional code, you need to comment on what they're for too. Also make sure that ALL VARIABLES ARE CLEARLY COMMENTED. That is, describe the role of the variable in your program in english. For example # integer w = width of window in pixels:n w = 800 Writing down the type (integer) of the variable is a good idea. Here's a bad comment: l = w+50 # assign l to w+50 It's a bad comment because it doesn't help us to understand the program any better. How much commenting is enough? Imagine yourself looking at your code a year from now. Would you be able to understand it? Comment as much as possible. ********** USE OF VARIABLES ************ You must use the parameter variables to represent the values of the coordinates and dimensions of your figure. By using the variables, you can change various attributes of the figure by just changing the value of one or two varibles, without touching the rest of the program. Refer to the diagram and demonstration given in class. We will be comming back to this program later in the semester, and you will regret it if your program does behave well if the values of the variables are changed. BE CAREFUL!!!!!! Remember that integer division throws away the reminder. It's not appropriate to use doubles in this program since screen coordinates are in integers. But let's say you want to compute three-fourth times the variable scale, if you write the expression as (3/4)*scale, the value will be ZERO! That's because 3/4 throws away the remainder. To get the value you want, use (3*scale)/4 instead. ********** Adding Variations ************* After you've drawn the stick figure, I will ask you to modifiy your program so that the figure is smaller, larger, at a different position, etc... If your figure becomes dismembered you'll lose points. There are also other variations you can add to your figure. You should add a variable that controls the position of the arms (up, down, or straight). Other options, which are optional, include: making the mouth smile or frown, and varying the size of the head independently of the size of the body, etc ... You may optionally experiment with animating the stick figure using the animation template and example that I have provided. It will require you to use while loops.