Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1 Online time for Graphics Program Random review

Similar presentations


Presentation on theme: "Computer Science 1 Online time for Graphics Program Random review"— Presentation transcript:

1 Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?

2 Some Pascal Graphics Commands
Some Commands SetColor(Integervariable); Circle(x, y, radius); ClearViewPort; //Like clearscreen Outtext(x, y, ‘String you will show on the screen’); Line(x1, y1, x2, y2); Lineto(x,y); Putpixel(x, y, ColorValue); Rectangle(x1, y1, x2, y2); Ellipse(x, y, Start Degrees, End Degrees, Horizontal Radius, Vertical Radius); Colorvariable:=getpixel(x, y);

3 Today Graphics program Inside circle program:
Open and modify the graphy1.pas program from the class website. Today Graphics program Face Stick figure House Inside circle program: Input: The (x,y) coordinate and center of a circle. Also the (x2,y2) coordinates of another point Output: Whether or not the point is inside the circle. (Hint: Use the distance formula) Push: In addition, show this graphically Intersecting circles program: Input: x, y and radius for two circles. Output whether or not the circles intersect. Push: Add graphics

4 Learning Objectives Be able to write a program that will be able to repeat an unknown number of times.

5 Random Review 1) random(6)+1 2) random(14)+2 3) random(7)-4

6 Write the line of code to generate the following ranges of values

7 Guessing game What do you need to be able to do?

8 Repeat..until When Semantics
When you want to repeat something an unknown number of times and at least once. Semantics Initialize variable (Pick the number the other person needs to guess) Repeat Get/calculate variable (Make a guess) Do all the other stuff you want to repeat (Have the timer ticking, tell them if the guess is too high or too low, etc.) Until variable = flag (They guessed correctly)

9 Syntax Repeat Until (condition); {All the commands to be repeated}
It will repeat until the condition is true. If the condition is false when it gets to the until line, it will repeat again.

10 Dry run sample program dryRunRepeat; var a,b,c:integer; begin b:=1;
c:= a + 2*b; writeln(a:6, b:6, c:6); a:= a + c div b; until (a>25); end.

11 Program options Guessing game. Implement the guessing game, but also include showing how many guesses it took the user to guess the number. The computer picks a number (1-100) and you guess it. The computer needs to tell you if your guess is high or low. When you guess it correctly, the computer shows how many guesses it took. Push: Write a program where the computer guesses the number you enter. Make this as efficient as possible without cheating. Ulam’s conjecture: If you take any positive integer greater than one. If it is even you divide it by two, if it is odd, you multiply it by 3 and add 1. When you continue this process, you will eventually get down to 1. Write a program to verify or disprove this conjecture.


Download ppt "Computer Science 1 Online time for Graphics Program Random review"

Similar presentations


Ads by Google