情報基礎B Lecture 7 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information Systems
COMPUTATION AND PROGRAMMING
Computation The world of {0, 1} AND operation OR operation Boolean algebra Logical operation AND operation 0 × 0 = 0 × 1 = 1 × 0 = 0, 1 × 1 = 1 Series circuit OR operation 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, 1 + 1 = 1 Parallel circuit NOT operation NOT(0) = 1, NOT(1) = 0 NOT
Computation AND operation 0 × 0 = 0 × 1 = 1 × 0 = 0, 1 × 1 = 1 Series circuit Switching : relay, transistor, diode
Computation OR operation 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, 1 + 1 = 1 Parallel circuit
Computation a NOT(a) NOT operation NOT(0) = 1, NOT(1) = 0 electromanget NOT(a)
Example of Adder a b Circuit to calculate a + b (a, b = 0 or 1) 0 + 0 = 00 1 + 0 = 01 0 + 1 = 01 1 + 1 = 10 NOT Upper Bit Lower Bit
Computation Model AND, OR, NOT Logical operation Addition, subtraction, multiplication, division, comparison IF Programming model (decision tree model) Load data from storage Store data to storage
Program and Decision Tree IF(B2>=90, “A”, IF(B2>=80, “B”, IF(B2>=70, “C”, IF(B2>=60, “D”, “F”)))) B2 True False A True False B True False C True False D F Computation proceeds through the tree
Loop SUM(A2:A100) Decision tree becomes deep Loop structure Loop management When to stop? In Excel… By setting range A2:A100 Read a cell in column A Adder Temporal Result
Loop Example: SUM(A2:A100) i=2 i = i + 1 Read A(i) TRUE Adder i<100 Temporal Result i = i + 1 TRUE i<100 FALSE Output Temporal Result
Programming Think about an algorithm e.g. Grading procedure Show a flowchart with decision tree and loop structure Write the algorithm in programming language Small vocabulary, easy
Programming Make an operation which a computer work on Algorithm designing Logical work Coding Learning a programming language Read programs Make some change on programs Debug(Error correction)
Programming hints Learning programming language Follow examples Practice makes perfect Follow examples This is a pen > This is a dog Follow good examples Learn from the mistakes This is a apple ?? I is a man ?? System will tell you mistakes Guess what is wrong: logical mind and imagination
Exercise Write a flowchart of program that acts same as COUNTIF(B2:B21, “A”) without using COUNTIF