Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical Thinking CS 104 9/12/11. Agenda Today  College Board survey reminder  Note: Simple “how to” guide on Scratch posted on eLearning  Review HW.

Similar presentations


Presentation on theme: "Logical Thinking CS 104 9/12/11. Agenda Today  College Board survey reminder  Note: Simple “how to” guide on Scratch posted on eLearning  Review HW."— Presentation transcript:

1 Logical Thinking CS 104 9/12/11

2 Agenda Today  College Board survey reminder  Note: Simple “how to” guide on Scratch posted on eLearning  Review HW #2  Review of control constructs  Examples in BYOB Scratch Wednesday  Quiz #2 on Wednesday  Review Research Paper #1  More BYOB Scratch ideas

3 Review: Decision Structure “if” statements are used to test whether a certain condition is met This requires comparison operators and a way to connect multiple comparisons to create complex statements

4 Comparison Operators Relational Operators: Evaluate to true or false SymbolMeaning <Less than <=Less than or equal to =Equal to >Greater than >=Greater than or equal to <>Not equal to Scratch does not provide <>, >= or <= –These can be simulated as x > 10 or x = 10, and not x = 10

5 Operator Precedence What is 2 + 3 * 4? What about (2 + 3) * 4? The concept of operator precedence dictates which operators are applied first and have higher importance In most programming languages, the order is: 1. terms inside parentheses or brackets 2. exponents and roots 3. multiplication and division As they appear left to right 4. addition and subtraction As they appear left to right

6 Comparison Operators: You Answer

7

8 Boolean Operators Boolean logic – basis of computer logic, used to create complex comparisons Invented by George Boole, an English mathematician and philosopher... no general method for the solution of questions in the theory of probabilities can be established which does not explicitly recognise... those universal laws of thought which are the basis of all reasoning... http://en.wikipedia.org/wiki/George_Boole

9 Boolean Operators AND  Both conditions must be true in order for the entire condition to be true OR  At least one condition must be true in order for the entire condition to be true NOT  Opposite; if the condition is true, the result is false, and if the condition is false, the result is true Operator Precedence  Not  And  Or

10 Boolean Operators: AND You Answer

11 Boolean Operators: OR You Answer

12 Boolean Operators: Complex You Answer

13

14 Truth Tables PQP or Q TT TF FT FF PQP and Q TT TF FT FF PNot P T F

15 Implication, we denote as => "If it rains, I will stay at home" There are 4 possibilities: 1) it rains and he stays at home This is compatible with the statement: he did not lie. 2) it rains and he does not stay at home This is NOT compatible with the statement: he lied. 3) it does not rain and he stays at home This is compatible with the statement: he did not lie. 4) it does not rain and he does not stay at home This is compatible with the statement: he did not lie. Truth Tables PQP => Q TT TF FT FF

16 Grader Write a program to assign a letter grade to a given numeric grade.  If the given grade is between 90 and 100, print an A.  If the given grade is between 80 and 89, print a B.  If the given grade is between 70 and 79, print a C.  If the given grade is less than 70, print an F.

17 Review: Loops Loops are used to perform a single task repetitively until a specified condition is met

18 Types of Loops Infinite loops  The command(s) placed inside a never ending loop will repeat until the program is stopped For loops  The loop will execute for a specified number of times

19 Types of Loops While loop  This loop will repeat while the specified condition is true Do Until loop  This loop will repeat until the specified condition is true

20 Class Grader Write a program to average three grades per student. The grades will be submitted by the user, and the number of students in the class should be a random number.  If the average grade is between 90 and 100, print an A.  If the average grade is between 80 and 89, print a B.  If the average grade is between 70 and 79, print a C.  If the average grade is less than 70, print an F.

21 Next Time Quiz #2 9/14/11 HW #2 due 9/21/11 Feel free to email both Dr. Gray and Amber with any questions


Download ppt "Logical Thinking CS 104 9/12/11. Agenda Today  College Board survey reminder  Note: Simple “how to” guide on Scratch posted on eLearning  Review HW."

Similar presentations


Ads by Google