Chapter 7 Empowering Programs with Math

Slides:



Advertisements
Similar presentations
Please turn in your Home-learning, get your notebook and Springboard book, and begin the bell-ringer! Test on Activity 6, 7 and 8 Wednesday (A day) and.
Advertisements

Coming up in Math 110: Today: Section 8.2 (Quadratic formula)
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Percentages, Decimals, & Fractions 5 th Grade Mathematics By: Rebecca Farrell Click the arrows to go to the Main Menu.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Subtracting Integers! By Zachary E. Hebrank.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
PSSA – Assessment Coach Mathematics- Grade 11. Chapter 1 Lesson 1 Orders of Operations and Number Properties.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
Confidential Adding Positive and Negative Integers.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Confidential1 OUR LESSON: Adding Integers. Confidential2 WARM-UP: 1.) Order from least to greatest 7, -3, 0, -1, 3 -3, -1, 0, 3, 7 2.)-35 = 35 3.)56 x.
Compare and order integers Find the absolute value of an expression Lesson 2-1 Rational Numbers and Exponents.
Pythagorean Theorem We’ve studied the relationship between interior angles of a triangle, and the exterior angles of a triangle. One thing we haven’t.
5.1 Exponential Functions
Math operations 9/19/16.
ALGORITHMS AND FLOWCHARTS
Introduction to Computing Science and Programming I
Complete Math Skills Review for Science and Mathematics
End Behavior.
Chapter 6: User-Defined Functions I
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Pythagorean Theorem MACC.8.G Apply the Pythagorean Theorem to determine unknown side lengths in right triangles in real-world and mathematical problems.
INVERSE TRIGONOMETRIC FUNCTIONS
Exponents Scientific Notation
Statistical Analysis with Excel
Lesson 18 Math Functions Lesson 19 Format Functions
WARM UP!!! 5,783,000, x x 10-4.
Chapter 7 Objectives Define basic terms in algebra: integer, number statement, expression, and coefficient Learn the relationships between positive and.
Variables, Expressions, and IO
Arithmetic, Exponents, Equations and Inequalities
Time Value of Money Math
Learning to Program in Python
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Standard Deviation.
January 2014 Compass Review.
Section 4.5: Solving Polynomial Equations
Pythagorean Theorem Apply the Pythagorean Theorem to determine unknown side lengths in right triangles in real-world and mathematical problems in two and.
INPUT & OUTPUT scanf & printf.
Number and String Operations
Section 4.7 Inverse Trig Functions
Applying Exponent Rules: Scientific Notation
Learning Outcomes –Lesson 4
Math 083 Bianco Warm Up! List all the perfect squares you know.
Digital Logic & Design Lecture 02.
MATH 010 JIM DAWSON.
Writing Functions( ) (Part 4)
Christina Maggio Grades 10th -12th October 21, 2012
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Solving Multi-Step Equations
Solving Linear Equations
Pythagorean Theorem MACC.8.G Apply the Pythagorean Theorem to determine unknown side lengths in right triangles in real-world and mathematical problems.
Chapter 6: User-Defined Functions I
CST-115 Introduction to Computer Programming
15 Minute Math This presentation will review different math skills that will help you with every day math problems. Each lesson takes approximately 15.
Mathematical Explorations
Basic Lessons 5 & 6 Mr. Kalmes.
Introduction An exponent is a quantity that shows the number of times a given number is being multiplied by itself in an exponential expression. In other.
Pythagorean Theorem Chapter 5 Lesson 5.
Flashback Calculate the solutions without a calculator.
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
Chapter 1 Introducing Small Basic
Chapter 9 Using Decisions to
Basic Mr. Husch.
Game Description Player 1: Decides on integer x > 0
Warm-up Simplify as far as possible, do not make a decimal. Your answer will still have a square root sign in it. 1. (5 + 4x) + (7 - 2x)    
Chapter 1B Powers This section is not in the textbook and will mostly be a review from Math 10 Pre-Calculus 11.
Presentation transcript:

Chapter 7 Empowering Programs with Math

LESSON: So far, we have seen the four basic math operations. To do more, the Math OBJECT gives us access to other operators and we will explore these. The format is: variable = Math.Operator (number(s)) When you click on the word, “Math”, a menu of choices pops up on the right. We will learn the different functions by example and practice. Prepare a new Chapter 7 folder on your flash drive to store these programs.

This is how we use the Square Root function: ans = Math.SquareRoot (num) Type this in EXACTLY as you see it and press RUN. {First, get INPUT for the number.} {Next, perform the CALCULATION.} {Lastly, print out the OUTPUT.} Run the program three times: Use a perfect square, a non-perfect square, and a negative number.

To find an Exponential Expression: ans = Math.Power(base, exponent) Now, to find , type this in EXACTLY as you see it and press RUN. {The first number, “3”, is the base. The second number, “5”, is the exponent} The “3” and “5” could have been variables, also.

Please type in the POWERDEMO program on page 85 or on your note taking guide, EXACTLY as you see it and press RUN. Here is the result: Wow, what a crazy answer! Now, let’s look at how to get numbers to round correctly.

Please type in the POWERDEMO program on page 85 or on your note taking guide, EXACTLY as you see it and press RUN.

To Round: ans = Math.Round(num) The answer will round correctly to the nearest integer. If you add: A = Math.Round(A) right after the calculation in the POWERDEMO program, the result will look like this: Pretty good, but we can do much better!

What if we want to Round to the nearest penny (1/100th) we use: A = Math.Round(A*100) / 100 Add this to your POWERDEMO program, then RUN. Now, this looks right! How would you round to ONE decimal place? A = Math.Round(A*10) / 10 How would you round to THREE decimal places? A = Math.Round(A*1000) / 1000

Another kind of rounding: ans = Math.Floor(num) The METHOD will round Down to the nearest integer. Better known as the Greatest Integer Function. Sounds backwards, but it is the largest integer less than or equal to the number. It always “snaps to the left.” For example, both 3.1 and 3.9 both round down to 3. 3 If we look at negative numbers, it still “snaps to the left.” However, you have to think about what is on the left. – 3.1 and – 3.9 snap to – 4. -4

A third kind of rounding: ans = Math.Ceiling(num) The METHOD will round Up to the nearest integer. Better known as the Least Integer Function. Also sounds backwards, but it is the smallest integer larger than or equal to the number. It always “snaps to the right.” For example, both 3.1 and 3.9 both round up to 4. 4 If we look at negative numbers, it still “snaps to the right.” However, you have to think about what is on the right. – 3.1 and – 3.9 snap to – 3. -3

Mathematics is important to computing, but not as important as what people can do:

Chapter 7 Programming Assignment 1 Use your SHELL and SAVE AS PAYMENTS The complete program instructions are on your handout. Just a few things to emphasize: Use CursorTop & CursorLeft to organize your output. Let the user input the interest in percent form, but we will divide it by 1200 (100 to convert to decimal and 12 as it is a monthly payment. Assign that to R for the formula. Convert the formula: to be able to program with it. Assign the exponent part (1 + R)N to a separate variable and use it in the formula. Print your program and output. Turn in. Due _________

Absolute Value: ans = Math.Abs(num) Absolute Value is distance from zero. Distance is always positive, therefore Absolute Value is always positive! Math.Abs(4) returns a value of 4, while Math.Abs(– 3 ) returns a value of 3 -3 4

This METHOD Returns The Larger Of Two Numbers: ans = Math.Max(num1, num2) Type this in EXACTLY as you see it and press RUN. {Why would you need this? When you are comparing variables!}

This METHOD Returns The Smaller Of Two Numbers: ans = Math.Min(num1, num2) Type this in EXACTLY as you see it and press RUN.

Remainder: ans = Math.Remainder(num1, num2) This METHOD uses two arguments: num1 is divided by num2. It returns the integer remainder. For example: ans = Math.Remainder(20, 3) Would return a value of 2, because Believe it or not, remainders are VERY important in mathematics. Just remember the rule: Divison by 3 leaves 3 remainders: 0, 1, 2 Divison by 7 leaves 7 remainders: 0, 1, 2, 3, 4, 5, 6 etc.

Look at the MONEY program on page 90 Look at the MONEY program on page 90. I have slightly modified the program. Lets look at it line, by line.

Chapter 7 Programming Assignment 2 Use your SHELL and SAVE AS WHEN IS EASTER? The complete program instructions are on your handout, along with the Easter Sheet and Student Worksheet. First, convert each equation from the Easter Sheet on the Student Worksheet. I will grade it. Next, write the code and apply the equation conversions. Print your program and output. Turn in. Due __________

Trigonometric METHOD covers several trig concepts Trigonometric METHOD covers several trig concepts. Today, we are only going to look at converting degree angles to radians. A game, described on page 93, has the user input an angle, to destroy the an enemy warehouse that is 500 feet away. “If at first you don’t succeed …” The computer uses radians, but we are more familiar with degrees, thus the conversion from lines 6 to 7. (Price, 2016) Mini Program 1: Type the program “Android Attack” and RUN until you get to 500 feet. SAVE, but do not print, I will check it via VISION. Due __________

Random Number between two numbers, i. e Random Number between two numbers, i.e. from a beginning (beg) number to an ending (end) number: (beg – 1) + Math.GetRandomNumber(end – beg +1) For example, to generate a number between 10 and 100: x = ___ + Math.GetRandomNumber( ____ ) 9 91 Type this in EXACTLY as you see it and press RUN. Did anyone get a number outside of the 10 to 100 range?

x = ___ + Math.GetRandomNumber( ___ ) A little easier is a Random Number METHOD that begins at 1. Say, between 1 and 6. What would you have? x = ___ + Math.GetRandomNumber( ___ ) The general formula for 1 to any ending number is: ans = Math.GetRandomNumber(end) 6 Do we really need the “0”? Type this in EXACTLY as you see it and press RUN.

Chapter 7 Programming Assignment 3 Use your SHELL and SAVE AS DICE GAME Using the coding from the previous slide, you will create a game for you and your friends. Give your game a name and use the Cursor METHODS to give it some readability. The player will enter his/her name. Each player will take a turn using the program. It will keep a running total (sum) of his/her points for each turn. Whoever gets the most points wins! Print your program and one output. Turn in. Due __________