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
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
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.
Microsoft® Small Basic The Math Object Estimated time to complete this lesson: 1 hour.
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.
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.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
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:
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
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.
Section 3-4 Radian Measures of Angles. Definition: Radian Measure of an Angle.
Programming revision Revision tip: Focus on the things you find difficult first.
Chapter 2 Writing Simple Programs
A little more practice You’ve got this! High five!
Grade Homework HW 13.2A Answers.
Python: Experiencing IDLE, writing simple programs
AP Java 10/4/2016.
CS1371 Introduction to Computing for Engineers
Volume of Cones.
Program Options: 10 Minutes online
Turkey Parts Unit 11 Review.
Radian Measure of a Central Angle
Java Methods Making Subprograms.
3-7 Sample Programs This section contains several programs that you should study for programming technique and style. Computer Science: A Structured.
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.
Computer Science Procedures
Java Methods Making Subprograms.
Count Controlled Loops (Nested)
Truth tables: Ways to organize results of Boolean expressions.
tape measure (for showing ratio) Pi book prize (for most pi digits)
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.
Dry run Fix Random Numbers
Program Options: 10 Minutes online
Truth tables: Ways to organize results of Boolean expressions.
Volume.
Learn to plug in variables to solve problems.
Java Methods Making Subprograms.
CS150 Introduction to Computer Science 1
Computer Science 1 Warm-up: True/False Dry Run
Computer Science
What do you do when you don’t know how to get started.
AP Java 9/21/2018.
Computer Science 1 Online time for Graphics Program Random review
Computer Science II Second With files.
Drill Solve for x: Find the surface Area of a rectangular prism if the dimensions are 3 x 5 x 6. Find the volume of a right cylinder with radius 5 cm.
Computer Science Procedures Day 2.
Computer Science 2 More Trees.
Computer Science Procedures Day 2.
Computer Science 1 while
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
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
Computer Science I: Get out your notes.
Computer Science 1 10/16/2018.
( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , )
EQ: Are there other ways to describe the location of a point in the plane other than by giving its x- and y- coordinates?
Section 7.2 Day 5 Cross Sections
Program options Write a program for one of the following
Dry Run Fix it Write a program
Computer Science 1 Review and finish Number base conversion
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Random Numbers while loop
Computer Science 1 while
Dry Run Fix it Write a program
H446 Computer Science.
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 Targets Be able to read a program that uses functions. Be able to write a program that uses functions.

Dry Run the following begin a:= 6; b:= 12; writeln(a:4,b:4); program funInFunction; var a,b:integer; function one(a,b:integer):integer; c:integer; begin c:= a+2*b; one:= c DIV 2; end; function two:integer; first, second:integer; first:= 15; second:= 10; two:= first - second; Dry Run the following begin a:= 6; b:= 12; writeln(a:4,b:4); a:= one(b,a); writeln(two:4); b:= one(a,b) + two - 6; writeln(a:4,b:4 ); end.

Functions Program #1 Write a function to convert from Radians to degrees Convert from Fahrenheit to Celsius Sent the radius and height and calculate the volume of a cylinder.

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.

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.

Program 3: 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 on Monday, EPIC ticket to the person whose code calculates the most digits of PI.

PI Memorizers

How many digits of PI can you recite?

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

Function Programs Function Program #2: PI 1) 2) Write a function to convert from Radians to degrees Convert from Fahrenheit to Celsius Sent the radius and height and calculate the volume of a cylinder. Function Program #2 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 Function Program #2: PI 1) 2) 3) (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