570 likes | 731 Views
Flowchart. Basic. 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 … … … … . INPUT: id, name, sal. Basic. START. INPUT id, name, sal. tax = sal * .1 net = sal - tax. PRINT id, name, sal, tax, net. END. Heading. ID NAME SAL ARY TAX NET
E N D
Basic 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 … … … … ... INPUT: id, name, sal
Basic START INPUT id, name, sal tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net END
Heading ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000
START Heading PRINT ‘ID NAME SAL…’ ‘-----------’ INPUT id, name, sal tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net END
START Heading PRINT heading INPUT id, name, sal tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net END
User can change TAX RATE START 1 2 INPUT id, name, sal 3 INPUT trate tax = sal * .1 net = sal - tax 4 PRINT id, name, sal, tax, net 5 END
User can change TAX RATE START INPUT trate 1 INPUT id, name, sal tax = sal * trate net = sal - tax PRINT id, name, sal, tax, net END INPUT: id, name, sal, trate
How to get out from the loop? START INPUT id, name, sal tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net END
How to get out from the loop? START 1 2 n y id = 0 ? INPUT id, name, sal D U M M Y 3 tax = sal * .1 net = sal - tax is the answer. 4 PRINT id, name, sal, tax, net END 5
How to get out from the loop? START INPUT id, name, sal 3 y id = 0 ? n tax = sal * .1 net = sal - tax END PRINT id, name, sal, tax, net
Iteration • DO WHILE LOOP • จะทำการทดสอบ เพื่อออกจาก loop ต้นสุด • เงื่อนไขที่จะออกจาก loop จะต้องเป็น เท็จ (False) Condition test False True . . .
Iteration • DO UNTIL LOOP • จะทำการทดสอบ เพื่อออกจาก loop ท้ายสุด • เงื่อนไขที่จะออกจาก loop จะต้องเป็น จริง (True) . . . Condition test True False
How to get out from the loop? START n id <> 0 ? DOWHILE y INPUT id, name, sal END tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net Condition PASS Position PASS Logic Fail
START How to get out from the loop? INPUT id, name, sal DOWHILE n id <> 0 ? y tax = sal * .1 net = sal - tax END PRINT id, name, sal, tax, net Condition PASS Position PASS Logic PASS INPUT id, name, sal
START How to get out from the loop? INPUT id, name, sal DOUNTIL tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net INPUT id, name, sal y id = 0 ? END n
Footing 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ Processed by: MIS department
START Footing INPUT id, name, sal n id <> 0 ? y PRINT “-------------” “Processed by MIS” tax = sal * .1 net = sal - tax PRINT id, name, sal, tax, net END INPUT id, name, sal
ID NAME SALARY TAX NET ---------------------------------------------------------- 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ---------------------------------------------------------- Processed by: MIS department
ACCUMLATION: SUM 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ 67500
ACCUMLATION: SUM net = sal - tax tnet = tnet + net
START ACCUMLATION: SUM INPUT id, name, sal 1 n id <> 0 ? 6 y 2 tax = sal * .1 net = sal - tax END 3 PRINT id, name, sal, tax, net tnet = tnet + net 4 INPUT id, name, sal PRINT tnet 5
START ACCUMLATION: SUM INPUT id, name, sal n id <> 0 ? 6 y tax = sal * .1 net = sal - tax tnet = tnet + net PRINT tnet 3 tnet = tnet + net PRINT id, name, sal, tax, net END INPUT id, name, sal
ACCUMLATION: SUM 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ 75000 7500 67500
START ACCUMLATION: SUM INPUT id, name, sal n id <> 0 ? y tax = sal * .1 net = sal - tax tnet = tsal - ttax tsal = tsal + sal ttax = ttax + tax PRINT id, name, sal, tax, net PRINT tsal, ttax, tnet INPUT id, name, sal END
ACCUMLATION: SUM 1 Tom 20000 2000 18000 18000 2 Mary 25000 2500 22500 40500 3 Klien 30000 3000 27000 67500
START ACCUMLATION: SUM INPUT id, name, sal n id <> 0 ? y tax = sal * .1 net = sal - tax END tnet = tnet + net PRINT id, name, sal, tax, net, tnet tnet INPUT id, name, sal
ACCUMLATION: COUNT 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ counts: 3
START ACCUMLATION: COUNT INPUT id, name, sal 1 n id <> 0 ? 6 y 2 tax = sal * .1 net = sal - tax END 3 PRINT id, name, sal, tax, net count = count + 1 4 INPUT id, name, sal PRINT count 5
ACCUMLATION: SUM Count = count + 1
START ACCUMLATION: COUNT INPUT id, name, sal n id <> 0 ? y 2 6 tax = sal * .1 net = sal - tax count = count + 1 PRINT count count = count + 1 3 PRINT id, name, sal, tax, net END 4 INPUT id, name, sal 5
INPUT ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ counts: 3
INPUT ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ counts: 3 INPUT OUTPUT
INPUT ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 20000 2000 18000 2 Mary 25000 2500 22500 3 Klien 30000 3000 27000 ------------------------------------------------------------------------ counts: 3 INPUT OUTPUT
Iteration • DO WHILE LOOP • จะทำการทดสอบ เพื่อออกจาก loop ต้นสุด • เงื่อนไขที่จะออกจาก loop จะต้องเป็น เท็จ (False) Condition test False True . . .
Iteration • DO UNTIL LOOP • จะทำการทดสอบ เพื่อออกจาก loop ท้ายสุด • เงื่อนไขที่จะออกจาก loop จะต้องเป็น จริง (True) . . . Condition test True False
START INPUT id, name, sal DOWHILE n id <> 0 ? y tax = sal * .1 net = sal - tax END PRINT id, name, sal, tax, net INPUT id, name, sal
START N X < 10? Y A = A + X X = X + 1
Quiz • ให้นักศึกเขียน flowchart เพื่อให้ได้รายงานดังด้านล่าง ID NAME G.P.A. 101 Tom 3 102 Mary 2 103 Mike 4 Average GPA = 3
Selection • DO WHILE LOOP • จะทำการทดสอบ เพื่อออกจาก loop ต้นสุด • เงื่อนไขที่จะออกจาก loop จะต้องเป็น เท็จ (False) True False Condition . . . . . .
Tax rate < 10000 10% >= 10000 20% Selection ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 8000 800 7200 2 Mary 25000 5000 20000 3 Klien 30000 6000 24000
START Before any Selection INPUT id, name, sal n id <> 0 ? y tax = sal * .1 net = sal - tax END PRINT id, name, sal, tax, net INPUT id, name, sal
After Selection START INPUT id, name, sal n id <> 0 y y n sal < 10000 y END tax = sal * .1 tax = sal * .2 net = sal - tax PRINT id, name, sal, tax, net INPUT id, name, sal
Tax rate < 10000 0% >= 10000 20% Selection ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 8000 0 7200 2 Mary 25000 5000 20000 3 Klien 30000 6000 24000
START INPUT id, name, sal n id <> 0 y y n sal < 10000 y tax = 0 tax = sal * .2 net = sal - tax PRINT id, name, sal, tax, net INPUT id, name, sal A
START START INPUT id, name, sal INPUT id, name, sal n n id <> 0 id <> 0 y y y n y n sal < 10000 y sal < 10000 y tax = 0 tax = sal * .2 tax = sal * .2 net = sal - tax net = sal - tax PRINT id, name, sal, tax, net PRINT id, name, sal, tax, net INPUT id, name, sal INPUT id, name, sal A B
START START INPUT id, name, sal INPUT id, name, sal n n id <> 0 id <> 0 y y y n y n sal < 10000 y sal < 10000 y tax = 0 tax = sal * .2 tax = sal * .2 net = sal - tax net = sal - tax PRINT id, name, sal, tax, net PRINT id, name, sal, tax, net INPUT id, name, sal INPUT id, name, sal A B
Tax rate < 10000 0% >= 10000 20% >= 30000 30% Selection ID NAME SALARY TAX NET ------------------------------------------------------------------------ 1 Tom 8000 0 7200 2 Mary 25000 5000 20000 3 Klien 30000 9000 24000