Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1 3.14 And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and.

Similar presentations


Presentation on theme: "Computer Science 1 3.14 And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and."— Presentation transcript:

1 Computer Science 1 3.14 And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it about. (I Kings 7: 23) 950 BC

2 Learning Objectives Be able to fix a program that uses functions
Be able to write programs that use functions. Be able to translate an algorithm for calculating PI into Pascal.

3 FixFunction4-5-2018.pas from the class website and fix it.
Fix the following program FixPhunXion; [This program uses a function that is sent an array of 10 integers and returns the highest value) type array = array(1 to 10) of integers; var highest:integer; //********************************* function highest(array:arraytype); begin for count is 1 to 10 do if array[count]< high then high = count; end highest := high; end_function //***************************** for count = 1 to 10 array[count] = randomize highest = highest(array) writeln(The highest value is highest) end. Download the program FixFunction pas from the class website and fix it.

4 Function #2 Program Options
Sent nothing, but inside the functions gets 10 scores and calculates and returns the average Factorial Function Input: Any positive integer; Output: The factorial of the number Example: Input: 5 Output: 5! = 120 Create the header and call statement for one.

5 PI Memorizers

6 How many digits of PI can you recite?

7

8 Today there are 3 PI themed options
Describe each methods Give an example on how each works Online time to generate the code to create a function to calculate PI. At the end of class. A round bracelet to the person (team) that generates PI the most digits.

9 Write a program to approximate PI
1400 method (Madhana of Sangamagrama, and rediscovered by Leibniz in the 1600s) Use this method to estimate PI. What value do you get after 500 iterations, 1000, 10000, …? Push: How could you write a program to use this method to calculate PI to +/- 1/1000

10 Wallis Method (1655) Use this method to estimate PI. What value do you get after 500 iterations, 1000, 10000, …? Push: How could you write a program to use this method to calculate PI to +/- 1/1000

11 Random Circle Area Method
Using a 100 pixel x100 pixel square with a circle inscribed with a 50 pixel radius. Generate random points (x, y) inside the square. ( 0 <=x <=100, 0<=y<=100). Count how many of these points are inside the circle and use this to estimate the value of PI. Try with 500 points, 1000 points, points … Push: Show graphically Push: Compare with Squares and Circles of different sizes to see if it makes a difference. (Dots in)/(total Dots) = (Circle Area)/(Total Area) = (PI*r2)/(2*r)2 = (PI*r2)/(4*r2) = PI/4 Multiplying both sides by 4 4*(Dots in)/(total Dots) = PI


Download ppt "Computer Science 1 3.14 And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and."

Similar presentations


Ads by Google