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.

Slides:



Advertisements
Similar presentations
Professor John Peterson
Advertisements

CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
Quit Pì The Radian Estimates of  Gabriel’s Horn.
Computer Science: A Structured Programming Approach Using C1 3-7 Sample Programs This section contains several programs that you should study for programming.
Section 7.2 Computations with Decimals
Simulation Time-stepping and Monte Carlo Methods Random Number Generation Shirley Moore CS 1401 Spring 2013 March 26, 2013.
Celebrating π – Trivia Quiz ANSWERS 1.Which letter of the Greek alphabet is π? the 16th 2.Which of the following is NOT true? a. There is a movie named.
Even more problems.. Mean (average) I need a program that calculates the average of student test scores. I need a program that calculates the average.
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
ESTIMATING PRODUCTS BY ROUNDING. 1)Round both factors to the greatest place value. 2)Multiply the front end digits of the rounded number. 3)Count your.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
PIPI Jill Keeve
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
Programming revision Revision tip: Focus on the things you find difficult first.
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Introduction to Algorithms
AP Java 10/4/2016.
CMPT 120 Topic: Functions – Part 4
Some problems for your consideration
CS1371 Introduction to Computing for Engineers
Chapter 8 Arrays Objectives
JavaScript Functions.
Program Options: 10 Minutes online
Control Structure Senior Lecturer
Equations of Circles Part a.
Higher-Order Procedures
Program options Write a program for one of the following
Review Finish program Graphics Programming
Computer Science 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.
How do you store a bunch of similar stuff?
Chapter 8 Arrays Objectives
Count Controlled Loops (Nested)
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 2 Review the Bubble Sort
Point Question Point Question Point Question Point Question
Variables and Data Types
tape measure (for showing ratio) Pi book prize (for most pi digits)
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
Program Options: 10 Minutes online
Truth tables: Ways to organize results of Boolean expressions.
How do you store a bunch of similar stuff?
Computer Science 1 Warm-up: True/False Dry Run
Computer Science
Computer Science Sorting Pre-Test Discussion/program
What do you do when you don’t know how to get started.
Truth tables: Ways to organize results of Boolean expressions.
Chapter 8 Arrays Objectives
AP Java 9/21/2018.
Computer Science 1 Online time for Graphics Program Random review
Computer Science II Second With files.
Sorting Develop a sorting algorithm
Computer Science 2 More Trees.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Warm-up: Dry Run DIV / MOD 2nd If Then Program
Computer Science
How do you store a bunch of similar stuff?
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Computer Science I: Get out your notes.
Computer Science 1 10/16/2018.
Program options Write a program for one of the following
Dry Run Fix it Write a program
Counting to 100 Counting by ones
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Random Numbers while loop
Dry Run Fix it Write a program
Computer Science 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.
CS5760: Computer Vision Lecture 9: RANSAC Noah Snavely
Presentation transcript:

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

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.

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 FixFunction4-5-2018.pas from the class website and fix it.

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.

PI Memorizers

How many digits of PI can you recite?

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.

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

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

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, 10000 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