Computer Science 1 Warm-up: True/False Dry Run Online Time to Finish/push the If program DIV / MOD 2nd If Then Program
Take out your notes and number your paper from 1 to 11. Var A,b,c:integer; E,f,g:real; H, i:string; Begin A:= 5; b:=10;c:=2; E:=5.0;f:=3.0;g:=10.5; H:= ‘Howdy’;i:= ‘Doody’; 1) a<b 2) c>a 3) e>c 4) h<= i 5) (a<b) or (a<c) 6) (3*a >g) 7) (a<b) and (b<c) 8) NOT (a>10) 9) H > i 10) NOT (H = ‘howdy’) 11) H > A Take out your notes and number your paper from 1 to 11. George Boole True, False or crash
Dry run the following program dryruny; var one, two:integer; begin two:= one*2 - 1; writeln(one:6, two:6); if (one <= two) then writeln('Scooby') else writeln('Scrappy'); end.
Program options. Quiz this Thursday Input: A test score. Output: A congratulations if the score is above 90. Push: Add comments for scores 80-90, 70 – 80 , 60 – 70 etc… Input: The lengths for three sides of a triangle. Output: Whether or not the three sides make a triangle. Push: Calculate the area of this triangle. Push: Determine if it is a right triangle. Input: Three scores. Output the three scores in order lowest to highest.
Dry Run DIV..MOD If..then review Conditions Program Computer Science 1 Dry Run DIV..MOD If..then review Conditions Program
Dry Run the following program ifOne; var a,b:integer; begin a:= 10; if a>b then a:= a - 4; b:=b+1; end; writeln(a,b); readln; end.
DIV Pascal’s Integer Division How can you get an integer result when you divide? For example, if you divide 5 by 2 what do you think the answer would be? What about the remainder. Pascal has math operations for finding the result of integer division and the remainder of integer division.
DIV and MOD DIV is used to find the result of integer division For example X := 13 DIV 5; X:= 21 DIV 10; X:= 20 – 8 DIV 3; x:= 1 DIV 2; MOD is used to find the remainder of integer division X := 13 MOD 5; X:= 21 MOD 10; X:= 20 – 8 MOD 3; x:= 1 MOD 2;
DIV and MOD samples Ans:=23 DIV 10; Ans:= 14 DIV 4; Ans:= 52 DIV 5; Ans:= 23 MOD 10; Ans:= 14 MOD 4; Ans:= 52 MOD 5; Ans:= 14 MOD 3; Ans:= 8 MOD 9; Ans:= 5 MOD 10; Ans:= 4.13 MOD 2;
If..then and if..then..else When Semantics If it makes sense to say if, it probably makes sense to use if Semantics
Syntax: If..Then If (condition) then Begin {Commands to do when the condition is TRUE} end; Program IfThenSample; Var Testscore:integer; Begin Writeln(‘Please enter a test score’); Readln(testscore)’ If (testscore>95) then Writeln(‘Congratulations’); Writeln(‘Keep up the good work’); End; End.
Conditions: Boolean Always results in a TRUE or FALSE Go over <, >, <=, >=, =, <>, AND, OR, NOT Use () as needed Types must match* (Can compare real and integer)
Dry run the following program dryrun5; var one, two:integer; begin two:= one*2 - 1; writeln(one:6, two:6); if ((two MOD 2) = 0) then writeln('Scooby') else writeln('Scrappy'); if (one MOD 2 <>0) then writeln(‘Fred’) writeln(‘Wilma’); end.
Program options. Quiz Friday Input: The amount of change (Integer value, like 66 cents) Output: The least amount of coins it takes to make the change: For 66 cents 2 Quarter(s) 1 Dime(s) 1 Nickel(s) 1 Penny/Pennies Input: The number of Chirps per minute for a cricket. Output: The outside temperature in Fahrenheit and give an appropriate statement if the temperature is greater than 90 degrees F. Using his equation, called Dolbear's Law, you can determine the approximate temperature in Fahrenheit, based on the number of cricket chirps you hear in one minute. Dolbear's Law: T = 50+[(N-40)/4] T = temperature N = number of chirps per minute Push: Add other comments for different temperatures, The above equation is for field crickets, look up equations for different types of crickets.