80
2 Watcharin Puangplia 01/06/2554

chapter2

Embed Size (px)

DESCRIPTION

การเขียนผังงาน

Citation preview

Page 1: chapter2

�������������� ������� �������������� ������� �������������� ������� �������������� �������

���� ���� 22 ����������������������������

Watcharin Puangplia 01/06/2554

Page 2: chapter2

���������� ________________� �� � ������ _______________________����� _____________(5 �����)

2

����� _____________(5 �����)

��� ���������������� 1. _________________________ ���� ________________ 2. _________________________ ���� ________________

3. _________________________ ���� ________________ 4. _________________________ ���� ________________ 5. _________________________ ���� ________________ 5. _________________________ ���� ________________ 6. _________________________ ���� ________________ 7. _________________________ ���� ________________

Page 3: chapter2

Objectives ($%&�'(�)*)

• '()�*+�,-��. /�0�������)123�45���.�+'6��7• ���8.�9����:+�+�,-(�/�;<���)+�,-��'��*�:��5��5=<)

3

• ���8.�9����:+�+�,-(�/�;<���)+�,-��'��*�:��5��5=<)• ���8��);��5��)545'� �� if ��� if/else '. ��'� �������4D=<)• ���8��);��5��)54DE/D while '. �� execute �D���5��;1�����E/D L ���=<)• '()�*��4DE/D;<���)6�+��:������;<���)6�+6�+*6����• '()�*��'(-��;1��������5�-;��5��)5• ���8+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55�=<)• ���8+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55�=<)• ���8�D��<6�+�1�4-�*D'1N�6)�5��)��;1�����=<)• ���8�()��O��D'()4-�6)�5���'()=1��;1�����=<)

Page 4: chapter2

������������ ����������������������� � ����� ������!����"�#$�����%���&������'$������������&#�&�������(���������� %�)�$���� ��'��$*��

4

2.1. Introduction ( ��4�)

��&������'$������������&#�&�������(���������� %�)�$���� ��'��$*���#�+#���%,�%������-�� ����������� ���������� .����/����0��)"�#������������ ������%��1��2�&

Page 5: chapter2

วงจรการพฒันาโปรแกรม (PDLC) ��� �������� ����� ���������������������������������� ������� !

5

5�$����6�7������� Cycle: PDLC)

��� �������� ����� ���������������������������������� ������� ! 6 ������ ������

1. �� %��������&'�� (Program Analysis)

2. ������������� (Program Design)

3. �����!������� (Program Coding)

4. �� ���������� (Program Testing)4. �� ���������� (Program Testing)

5. �� � ��� ��������������������@� ��! (Program Formalization)

6. ������@���C������� (Program Maintenance)

Page 6: chapter2

1. ������������

• ������ Program Specification Package

• ����������������������� (SA) ���������

• �������������� ��!����" ��#� ���$% ��� $% �����"����

2. ������!����"

• ��#�����&'(���� (Main Module) ��!����"����)� Module #��*

• �������������&+"���� #��!"���

• &��������$,&'(-������������&+"

6

6. ����%����.�!����"

• ���- Error &'($�����#�����������!����"����!�/������

• ����%�����$�("� �"���"��"��0������!����""�� +1�

3. � '/�!����"

• ��'(/��������&+"�� �1� ��&'( 2 "��)�2�.�!����""�(�

• � '/�!����" ���&�������!����"��

�������$�3��!����"

5. &�&�����&����� ��!����"���1��%�&��/

• ��!���&'(�"#����������"� ����������!����"���#� &�����-��������"����-"#

• �����"������&'(��'(/�&�1��"���� SA

4. &����!����"

• �"�(�$� Error ��!����"������- &��&'

• ��� Error ������� +1�������� '/�-�/���4 ��2�.��������������&'(�������&+"�5-��

��&'( 9.1 �����'�� �����$�3��!����"

Page 7: chapter2

�-��O� 3 (�/�6��� �

7

�������...������� �����

1. � ?�(@�����$'������'�4�����A��&BC�?��D

- ��)'4����4-�'�-��+� E������� $�� �C�C?�� (Top-Down Design)K

2. ���� ��C���@�L� (Algorithm) ��������

- ��)'4����4-�'�-��+� E������� )��(���� (Structured Design)K - ��)'4����4-�'�-��+� E������� )��(���� (Structured Design)K

3. �&(� ��C���@�L����R&�$���������

- ��)'4����4-�'�-��+� E������� )��(���� (Structured Design)K

Page 8: chapter2

'1N�'4�������:�5 �+�6)�5��(�5;1����� (Program Requirement)

8

������� $�� �C�C?�� (Top(Top(Top(Top----Down Design)Down Design)Down Design)Down Design)

'1N�'4�������:�5 �+�6)�5��(�5;1����� (Program Requirement) ���'1N���+�����L '. ��1��;���7��������::�������4��*�4D=<)5��(�/�

6�+���5������:: Top-down Design

- ��6�<'��<������

- ���D�+^ OT - ���D�+^ OT

Page 9: chapter2

9

Main Module

������� $�� �C�C?�� (Top(Top(Top(Top----Down Design)Down Design)Down Design)Down Design)

Initialization Wrap-UpProcess

�'��S��5��

6@�6*T�5���(��

)4��5U�?����))��*&����BC

�5���& 6@�6*���C'����&

T�)?��VC��� 6@�6*��&�5��C')?��VC���

Ex2: ���D�+^ OT

)?����C?5��5C�

)?����W��5C���@

�5�)?��������T�&

Page 10: chapter2

10

� ����)123�;<���;1��������.�+'6��7*�6)�5'�-��+()�5��:�����4D�D���5��<����5 L =16��D<�:4-��D��<=+) E��5���:+���������)123�4-�'�-��+� algorithm (���:+�+�,-) ��/�*�1����:<)+�

2222....2222 AlgorithmsAlgorithmsAlgorithmsAlgorithms (��' 5�5@X�)

�D���5��<����5 L =16��D<�:4-��D��<=+) E��5���:+���������)123�4-�'�-��+� algorithm (���:+�+�,-) ��/�*�1����:<)+�� �����4D (actions)� �D<�:(�5�����4D (order in which these actions are to be executed)

� �D<�:(�5��<�D���5�D���:����)123� (�/�6��+�,-4-�<-�D���:��;1�����6)�5�-��^���^�<�5�-/�-��^���^�<�5�-/� �6����D���56)�5=���D�+����'1N��D���54-����.�+'6��7���84D5�=<)� ���5*����.�+'6��7<D'�������:�D���5�<L ��)+ �D���58�<=14-�*���)���.�+'6��74D5���/�6)�5=���D�+�<)+�

� ��4D5�(�5�D���54�/5��<6)�5*:����(�/�6��4-�*D��<

Page 11: chapter2

11

���(���� AlgorithmsAlgorithmsAlgorithmsAlgorithms (��' 5�5@X�)

1. �,����6� (Nature language)2. M�55� (Flowchart) 2. M�55� (Flowchart) 3. ��'(-��EO;<;�e< �� � ����*D��5 (Pseudo Code)4. ��'(-��;��5��)5��4D5� (Structure Chart)

Page 12: chapter2

12

Y�Z�X���[��@ (Nature language)(Nature language)(Nature language)(Nature language)

��)�1�6�����'(-��(�/�6����4D5� ;<���<������'(-��6��O1�::��4D5�+���=�:)5 E��5�**�'(-��'1N�()� L �h=<)'. ���+���<+����'()�*5����4D5�+���=�:)5 E��5�**�'(-��'1N�()� L �h=<)'. ���+���<+����'()�*5��

��5��?����� 1 *5'(-���������4��'. ���D�+^��+��+(�54-�<���1�5����5 ;<�4�:��. /�4-�����+��+)5 ��)+��<5M�45��)*�

5@X��4� (1) �D��<��'����6)�(�5�+��+4-�<�� '1N� 0

(2) ��:��(�5()��O�. /�4-�����+��+)5(�54-�<��(1) �D��<��'����6)�(�5�+��+4-�<�� '1N� 0

(2) ��:��(�5()��O�. /�4-�����+��+)5(�54-�<�� (3) �D�+^�� �+��+4-�<�� = . /�4-� * �+��+)5

(4) ��<5M����+��+4-�<��4-�=<)*����D�+^

Page 13: chapter2

13

2222.3333. PseudocodePseudocodePseudocodePseudocode ()\&�����)• '1N�����5=��'1N�45�� 4-�MO)'(-��;1�������)����.�9����:+�+�,- (algorithm) Pseudocode �-���^���)��4-���)���-+�61��*D+�� �-���^���)5�����'(-��=<);<���<+� ��)+�*�=��=<)'1N��4-���)����'(-��(algorithm) Pseudocode �-���^���)��4-���)���-+�61��*D+�� �-���^���)5�����'(-��=<);<���<+� ��)+�*�=��=<)'1N��4-���)����'(-��;1�����*��5 L �h6�• Psudocode 4-�'6�-��=+)<-*����8�1�5��)'1N�;1������E- =<);<�5�� ;<��**�'.-�5�6���)�D���5�E- 4-�'4-�:'4�����4�4-��D���5 psudocode '()=1• MO)'(-��;1������**�'(-���D���5 psudocode ����5�D���5��)���8�5��• MO)'(-��;1������**�'(-���D���5 psudocode ����5�D���5��)���8�5�����4D��<����5 E��5�**D'1N�6)�5�4�4-�<)+��D���5�E- ����D���5�h=<) 4�/5�-/����) psudocode ����(�/���:*�<1���5�7(�5����) E��5�1�'1�-���=1=<)6��+�'�����

Page 14: chapter2

• ��'(-��(�/�6��+�,-;<�����)�,����6��*�-�+��D�+��� �� <�+'���=1 4D��)'��<��M�<.�<=<)5�� ��+�����);1�������*�-�+�

14

2222.3333. PseudocodePseudocodePseudocodePseudocode (�?�)

'���=1 4D��)'��<��M�<.�<=<)5�� ��+�����);1�������*�-�+�'l.�*�'���=1 MO)4-�=��'()�*;1������4-���)'(-���*=�����8'()�*=<) ����'4-��'1N���+�M��(�5����)�,����6����;1������ '. ����)����� �������+�5MO)��)��������4-��-�+�6)�5����)(�/�6��+�,-6�5������=1• ����'4-��=���-�m����'(-��6�6�+ ;<���(�/���O���:�+�8��<(�5MO)��) �6��-()�6��5:5���5��+����'1N���� ��+�1����:4-��D��3(�5����'4-�� =<)��� ()�6��5:5���5��+����'1N���� ��+�1����:4-��D��3(�5����'4-�� =<)��� � �� �D���5�D��<5� �D���5�+:��� �����(�5�D���5 ���()�:��4���� ��D�,�:�• Pseudocode �*'1N��=4��� ��� ���h=<) ((���)'�'()�*'4���/� '1N�.�) �6�����)���5�n*���<+�4-���< '.��5��6�����1�5'1N�����.�+'6��7

Page 15: chapter2

TC����U]*W��������� Pseudocode1. �+���)�5�� L =��*D'1N�6)�5�D��58�5����.�+'6��7

15

2222.3333. PseudocodePseudocodePseudocodePseudocode (�?�)

1. �+���)�5�� L =��*D'1N�6)�5�D��58�5����.�+'6��72. �+�'(-����)�-�����)'1N�:��4�< L '. ����<+�������������4D

�+�'()�*3. �D���54-�'1N����5�n4-�6)�5����)1o�:�6� �+�'(-��'1N�6�+.��.7��3�

'��� 4. MOVE '1N�6)�5. =��*D'1N�6)�5�-'�� ��5���+���6��5. =��*D'1N�6)�5�-'�� ��5���+���6��6. 8)'1N���'(-��;1�����4-��-'5 ���=( '��� IF *�6)�5*:<)+� END IF �� �

DO ..... *�6)�5*:<)+� END DO

Page 16: chapter2

��5��?�� PseudocodePseudocodePseudocodePseudocode ���)4��5U)'��������������START

SCORE1 (�� ����������������), SCORE2 (�� ��������������),

SUM (�� ���� ), NAME("#่%) ,GRADE (�(�))

DO UNITL � ),% .�

16

READ NAME, SCORE1, SCORE2

SUM = SCORE1 + SCORE2

IF SUM > 84 THEN

GRADE = A

ELSE IF SUM > 70 THEN

GRADE = B

ELSE IF SUM > 60 THEN

GRADE = C GRADE = C

ELSE IF SUM > 50 THEN

GRADE = D ELSE

GRADE = F

ENDIF

DISPLAY NAME, SUM, GRADE

ENDDO

END

Page 17: chapter2

• ���(�/�6)�<)+��D+� procedure 6�<)+�� ��(�5(�/�6��+�,- ����D<�:������<(�56�+�1�4-���)��:()��O��D'() '���

17

[��� (NameNameNameName)

(�56�+�1�4-���)��:()��O��D'() '���• Procedure FindMax(a1, a2, t, an : integers)

Page 18: chapter2

��)'�� ��5��� := (�� �:5���/5��) ←) �D���:�D��<��*���.*�745(+��)���6�+�1�45<)�E)�

18

)4�(����4�T�&��� (Assignment StatementsAssignment StatementsAssignment StatementsAssignment Statements)

6�+�1�45<)�E)�'���

Variable := expressionb := 5a := n + 10d := sqrt(4)z ← *D�+�4-���4-���<���D<�: Ld := sqrt(4)z ← *D�+�4-���4-���<���D<�: La ← ���:��(�56�+�1� a ��: b

Page 19: chapter2

�D���5�*�-���+������'. ����)5��6����'()�*;<�(�/�6)������(Block) <)+��D+� begin �����/���<<)+��D+� end 4�/5�-/�6���:��4�<(�5�D���5*��-�������)4-�'4����<)+�

19

�C%?����)4�(��� (Blocks of StatementsBlocks of StatementsBlocks of StatementsBlocks of Statements)

begin �����/���<<)+��D+� end 4�/5�-/�6���:��4�<(�5�D���5*��-�������)4-�'4����<)+�'���

beginb:=in:=sqrt(b)q:=b/nq:=b/n

end

Page 20: chapter2

:��4����'�� ��5��� /* t..*/ '. ����+�'6 ���+�*D�� ��,�:�(�/�6��4-��*'()�*��'���

20

��� ���L�T���)4��X@ ��

'���n := floor(x)/*floor function floor(1.5) = 1 and floor(-1.5) = -2 */

Page 21: chapter2

;<�1�6� �D���5��;1�����*�4D5�6��'� ��5���=16��D<�:4-�'(-��=+)��;1����� ;<�*�'�-����4D5����5�-/+� sequential execution (��

21

2222.4444. Control Structures Control Structures Control Structures Control Structures ()��(����)5 )%�)

��;1����� ;<�*�'�-����4D5����5�-/+� sequential execution (��4D5�6��D<�:) �D���56�5 L (�5�E- 4-�*�=<)���6��=1�-/*�4D��)MO)'(-��;1��������8�+:���=<)+� �D���58�<=14-�*�4D5�'1N��D���5�< E��5'�'�-�����5�-/+� Transfer of control (����������������)

Page 22: chapter2

'1N�;��5��)54-���)5��O������E- ��O���)+ ����� � 8)=��=<):��'1N����5� �� ���.�+'6��7*�4D5��D���5�E- =16��D<�:4-�'(-��=+)

22

2222.4444.1111 )��(�������C4�&�

���5� �� ���.�+'6��7*�4D5��D���5�E- =16��D<�:4-�'(-��=+) Flowchart ���O14-� 1 ��<5;��5��)56��D<�:(�5�E-

add gradeto total

total = total + grade;counter = counter + 1;

�O14-� 1 Flowchart (�5;��5��)56��D<�:(�5�E-

add 1 to counter

counter = counter + 1;

Page 23: chapter2

;��5��)545'� ����)����'� �����+�5�����4D��� L ���5

23

2222.4444....2 2 2 2 The if, if/else Selection StructureThe if, if/else Selection StructureThe if, if/else Selection StructureThe if, if/else Selection Structure ()��(��������C��� if, if/elseif, if/elseif, if/elseif, if/else)

;��5��)545'� ����)����'� �����+�5�����4D��� L ���5 6�+���5'��� 8)������*���:M�� '� ��=<)����� 60 �����(�/�=1 �D���5 pseudocode �**�'1N�

▫ If ������������ ����� ������� �� 60����� �Passed������ �Passed���)��5'�6+� �-��'+)�������5'� /�5'()=1��:��4�<4-���5(�5

pseudocode ��4D'����-/4D��);�e<���5��(�/� <�5��/�*�5�+���)��'+)�������5���5'1N���::����'(-��;1�����4��;1����� =��+�*�'(-��'1N� pseudocode �� �'1N�;�e<� C++ �h6�

Page 24: chapter2

)��(��������C���� ����&��5���Y�Z� �̂

Pseudocode ()56)����8'(-��'1N�;1������ C++ =<)<�5�-/

if (grade >= 60)

24

if (grade >= 60)cout << |Passed\n~; // printf(|Passed\n~); �E-

Flowchart (�5;��5��)545'� ���::45'<-�+(�5�E-

grade >= 60 Print “Passed”true

false

Page 25: chapter2

25

)��(��������C��� if/elseif/elseif/elseif/else

if #���������5��6�) ��$�����������& 60�+��9 :Passed@�+��9 :Passed@

else�+��9 :Failed@

Pseudocode �������(����a������A������Y�Z� C++ R&�&�����if (grade >= 60)if (grade >= 60)cout << |Passed\n~; // printf(|Passed\n~);

elsecout << |Failed\n~; // printf(|Failed\n~);

Page 26: chapter2

Flowchart (�5;��5��)545'� �� if/ else (�5�E-

26

grade >= 60

Print “Passed”

true

Print “Falsed”

false

Page 27: chapter2

• ;��5��)54DE/D 4D��)MO)'(-��;1�������:���)4D�����4D����5E/D=1'� ���L

27

2222.4444....3 3 3 3 The While Repetition Structure (The While Repetition Structure (The While Repetition Structure (The While Repetition Structure ()��(�����4� �̂4� While)While)While)While)

• ;��5��)54DE/D 4D��)MO)'(-��;1�������:���)4D�����4D����5E/D=1'� ���L��(^�4-�'5 ���=(:5���5��5�5'1N�*��5��O� 6�+���5'���▫ while (�F���) ���#����������.����� �%�������.������ (shopping list)▫ .������,+��!��(� �'�����,+�������+��(����������• '5 ���=(4-�+� |��5�5�-(�54-�*�E /���O�������E /�(�5~ �**�'1N�*��5�� �'4h*�h=<)��'5 ���=(�-/'1N�*��5 �h*�4D�D���5 |E /�(�5��/�6��=1 ����(�5��/���/�4�/5=1*���'5 ���=(�-/'1N�*��5 �h*�4D�D���5 |E /�(�5��/�6��=1 ����(�5��/���/�4�/5=1*�����~ �����4D�-/*�4D6��=1'� ��� L ��(^�4-�'5 ���=(��5�5'1N�*��5��O�

Page 28: chapter2

)��(�����4� �̂4� whilewhilewhilewhile

'. ��'1N�6�+���5(�5����)�O1 while ��5<O;1�����4-���)����D��5(�5��5�����4-����+� 1000 (�D��5(�5��5 ���8�5 2n '� �� n '1N�*D�+�'6h�:+�) '� ��;��5��)54DE/D while <)���54D5�'��h* 6�+�1� product �h*��-��M���.,74-�

28

�����4-����+� 1000 (�D��5(�5��5 ���8�5 2 '� �� n '1N�*D�+�'6h�:+�) '� ��;��5��)54DE/D while <)���54D5�'��h* 6�+�1� product �h*��-��M���.,74-�6)�5��

product <= 1000 product = 2 * producttrue

Flowchart (�5;��5��)54DE/D while

product = 2;while (product <= 1000)

product = 2 * product;

product <= 1000 product = 2 * product

false

Page 29: chapter2

������ (Flowchart)(Flowchart)(Flowchart)(Flowchart)

• '1N�'�� ��5� ��-��::����54-���)�O1�. ��<58�5(�/�6����4D5� (�/�6����'(-��;1����� �� �(�/�6��������)123�4-��(�/�

29

'(-��;1����� �� �(�/�6��������)123�4-��(�/�• �-'�)�4-���<54��45��=��(�5()��O�6�/5�6�*�<'����6)�*����4�/5=<)M���.,76�4-�6)�5��• 4D��)MO)������8������4D�+�'()�*=<)5��

1. 4D��)'()�* ���������123�=<)5�� (Problem Define)

�'�[�*���������

1. 4D��)'()�* ���������123�=<)5�� (Problem Define) 2. ��<5�D<�:��4D5� (Step Flowing) 3. �()�M�<.�<=<)5�� (Easy to Debug) 4. 4D�+�'()�*;1�����=<)5�� (Easy to Read) 5. =��(�/���:��<�����5 (Flexible Language)

Page 30: chapter2

�T�%�C�������W[������� FlowchartFlowchartFlowchartFlowchart

• '� ��5*�M�55�'1N��M�M�5�� ��O1�.4-���<5��+�+���<��)6�<6��1����5����+�5MO)+�'����7��::��:MO)'(-��;1����� �� �MO)'(-��;1�������:MO)��)����'(-��;1�������)'�h�'1N��..*�7+�;1�����*�4D5����5=�

30

���+�5MO)+�'����7��::��:MO)'(-��;1����� �� �MO)'(-��;1�������:MO)��)����'(-��;1�������)'�h�'1N��..*�7+�;1�����*�4D5����5=�• ��)'1N�'�����)5��5 '. ����)MO)'(-��;1�������� ��=<)4�: 4�/5�-/M�55�4-�<-*�6)�5=��(�/���:��<�����5• ���8��)M�55�����4<��:�� ���)=(��4D5�(�5;1�����=<) ;<���5=��6)�5�5� �'(-��'1N�����(�5'�� ��5�� ���5'()4<��:��:'�� ��5

Page 31: chapter2

�'�Y����������

31

• ��<5(�/�6����4D5�4�/5��< 4D��)'()�*

1. �������' (System Flowchart)

• ��<5(�/�6����4D5�4�/5��< 4D��)'()�*��::5�����(�5��::5����� 5 L4-�'�-��+()�5��:5�4�/5��< • ��<5(�/�6����4D5�����::���5�+)5 L �6�=��'*��5����::5�����

Page 32: chapter2

• :5���/5'�-��+� Block Diagram �:�5��::���'1N���+�L �����<5(�/�6�����

32

�'�Y���������� (�?�)

2. ������������&BC (Modular Programming Flowchart)

• :5���/5'�-��+� Block Diagram �:�5��::���'1N���+�L �����<5(�/�6�����+�,-��4D5����5=� �6�*�=���-����'�-�<������;�<O���/�▫ �6���(�/�6����<5�+�������(�:'(6;<�=��6)�5�-����'�-�<��▫ ���84�:8�5(�/�6������(�5;1������� �;�<O�4-�'�-��+()�5 ��+�4D��)'�h�

��+45��)123���'(-��;1�����=<)5��(�/�▫ ��<+������*�<:�.���5�� ��+�M�<.�<�� ��+�M�<.�<4-��**�'��<(�/�=<)▫ ��<+������*�<:�.���5�� ��+�M�<.�<�� ��+�M�<.�<4-��**�'��<(�/�=<)

Page 33: chapter2

• M�55�4-���<58�5(�/�6������4D5�(�5;1����� 6�/5�6�(�/�6������:()��O�

33

�'�Y���������� (�?�)

3. ������������������� (Programming Flowchart)

• M�55�4-���<58�5(�/�6������4D5�(�5;1����� 6�/5�6�(�/�6������:()��O� �D�+^ ��1���+�M� *�8�5����<5M���.,7• ��5��?�� M�55�;1������-/��<5���D�+^'5��'< ��(�5.���5� ;<�8)���+;�5��4D5���'< ����/� L =��'��� 160 ���+;�5 '5��'< ��*�8O��D�+^;<���)��6�����56�1�6� �6�8)���+;�5��4D5�'��� 160 ���+;�5 160 ���+;�5���*���)��6�6�1�6� �6�8)���+;�5��4D5�'��� 160 ���+;�5 160 ���+;�5���*���)��6�����56�1�6� ���*D�+����+;�54-�'���*���<����5;<���)��6�(�5����+5'+� (overtime �� � OT) E��5'4���: 1.5 '4�(�5��6�����51�6

Page 34: chapter2

34

Programming Flowchart������

�� �� �������� �������� ��� � �������� ��� �

���� �� ���

�� � � = �������� ��� � * ���� �� ����������� ��� � > 160!��"��

"��

�� � � = ((�������� ��� � -160) * 1.5 *) + (160 *���� �� ���)

�)

�*+��������� �,-�� � �

Page 35: chapter2

1. '����6)�;1����� ��)��3���^7'4��7�����2. ��:()��O�'() �� ������(�5()��O� ��)��3���^7����:���� ���<5M�

;<�()��O�4-���:1����:<)+� - � ��.���5�

$��������(����a�(&������������4����R&�&������

35

3. .�*�^'5 ���=(+�*D�+����+;�5��4D5���+� 160 ��/+;�5�� �=�� ;<���)��3���^7��6�<����*3.1 8)��� ��)��)����6��=1�-/�����D�+^��*)5

��*)5 = ((���+;�5��4D5� - 160) *1.5 * ��6�����5)+(160 *��6�����5)

;<�()��O�4-���:1����:<)+� - � ��.���5� - *D�+����+;�5��4D5� - ��6�����5

��*)5 = ((���+;�5��4D5� - 160) *1.5 * ��6�����5)+(160 *��6�����5) 3.2 8)=����� ��)��)����6��=1�-/�����D�+^��*)5

��*)5 = (���+;�5��4D5� * ��6�����5) ** ���D�+^��*)5��(�/�6��4-� 3.1 ��� 3.2 ��)��3���^7��1���+�M�

4. ��<5� ��.���5� �����*)54-�=<)*����D�+^ ��)��3���^7����:'()�� ���<5M� 5. *:;1�����;<���)��3���^7'4��7�����

Page 36: chapter2

(�dC��ZU*���W[�W��������������� (FlowchatingFlowchatingFlowchatingFlowchating SymbolsSymbolsSymbolsSymbols)

36

Page 37: chapter2

(�dC��ZU*���W[�W��������������� (FlowchatingFlowchatingFlowchatingFlowchating SymbolsSymbolsSymbolsSymbols)

37

Page 38: chapter2

(�dC��ZU*���W[�W��������������� (FlowchatingFlowchatingFlowchatingFlowchating SymbolsSymbolsSymbolsSymbols)

38

Page 39: chapter2

(�dC��ZU*���W[�W��������������� (FlowchatingFlowchatingFlowchatingFlowchating SymbolsSymbolsSymbolsSymbols)

39

Page 40: chapter2

(�dC��ZU*���W[�W��������������� (FlowchatingFlowchatingFlowchatingFlowchating SymbolsSymbolsSymbolsSymbols)

40

Page 41: chapter2

��5)@&W�������edT�• Initialization ���D��<��'����6)�• Input ����:()��O�

41

Input ����:()��O�• Process ��1���+�M�• Output ����<5M���.,7• Dicision ��'1�-�:'4-�: '. �����:=14DE/D

Page 42: chapter2

42

1. ����4�T�&)?���@����� (Initialization) '1N����D��<��'����6)���)��:6�+�1�:56�+ '��� 6�+�1�4-�4D ��)4-�'1N����+���:(Counter) 6�+�1�4-���'1N�M����D�+^���� '��� '��D��<��) High �-��'����6)� '4���: 0 (high = 0) �� � long �-��

��5)@&W�������edT�&�W[�������

���� '��� '��D��<��) High �-��'����6)� '4���: 0 (high = 0) �� � long �-��'����6)�'4���: 0 (long = 0)

2. ����� ����BC(Input) '1N�����:��6�+�1�4-���:�=+)��(�/�6�����D'()()��O�(�5��+�'����5� ����:()��O�*� 6)�5���4D����*��-���D()��O���/�=1��) '��� �D=1�D�+^ '��� '���:()��O�(�5 High = 10, long = 5

3. ����'�5C�C(Process) '1N�����<5+�,-1���+�M� '��� . /�4-�(�5�O1�-�'��-��� = high * long <�5��/� . /�4-�(�5�O1�-�'��-��� = 10 * 5 = high * long <�5��/� . /�4-�(�5�O1�-�'��-��� = 10 * 5

4. ����(&��CC�6X*(Output) '1N�����<5M���.,7 �� ���(�56�+�1�4-���:�=+) ����+()�M���.,74-�6)�5��<5����+�'����5� '��� '��D�+��O5(�5�O1�-�'��-���4-��D�+^=<)4-�'4���:50 ���<545��)*�

5. ������� ���� (Decision) '1N���'1�-�:'4-�:'. ��'�-�5()��O��� �'. ���)�� ���:=14DE/D

Page 43: chapter2

1. 6�+*��:+��+���)6�+�1��<����'�h:()��O� *��O6����. /�4-���'��-��� � � 0.5 *�O5*0� 4D��)'��O)+��+��O5����+��+(�50��*���4-����()��O�'�*�5*�6)�5�D��<6�+�1���) �+��O5 ��:�+��+(�50�;<�4��+=1*�

43

��5��?�� : $�T�5?�6�������B(���TC������)?���?�R�

� � 0.5 *�O5*0� 4D��)'��O)+��+��O5����+��+(�50��*���4-����()��O�'�*�5*�6)�5�D��<6�+�1���) �+��O5 ��:�+��+(�50�;<�4��+=1*�=��������)� ��6�+�1�'1N��=4� *��O6�*���) high = �+��O5 long = �+��+(�50� total = . /�4-�(�5�O1��'��-���

2. *��O6�����:()��O�'���:()��O�*��-�7:��7< E��5*��-6�+�1�4-���:'()�� � high = 5, long = 5

3. ��1���+�M�'�*�4D��1���+�M�*��O6� 0.5*high*long *�����:()��O�'()'�4D���D�+^=<)<�5�-/ total = 0.5*5*5 = 12.5 ()��O�'()'�4D���D�+^=<)<�5�-/ total = 0.5*5*5 = 12.5

4. ����<5M���.,7'�*��D��(�5. /�4-���'��-���4-��D�+^=<)���<5M�45��)*���4-��-/� � 12.5

Page 44: chapter2

5@X������������������&�

• ��)��3��� 7̂6�4-��D��<=+)

44

• ��)��3��� 7̂6�4-��D��<=+)• ��)�O�����<54��45��=��(�5()��O�*�:��5��5 E)�=1(+• �D�,�:����.�+���/���4�<��< '()�*5��• 4���M��.*�6)�5�-�O���'()���• =���+�;�5'�)�'� ���M�55�4-���O�=���� �+���)*�<'� ���6���4�• �+��-��4<��:�+�8O�6)�5�����D=1��)5�• �+��-��4<��:�+�8O�6)�5�����D=1��)5�

Page 45: chapter2

���������������� 3 �

1. Sequence Flowchart ��������������� �����C4�&�

45

���� �����C4�&� • 6.�. *5'(-��M�55���<5(�/�6�����D�+^�. /�4-��-�'��-���▫ Pseudo Code▫ Flowchart

Page 46: chapter2

���������������� 3 �

2. Selection or Condition Flowchart

��������������� ������C���

46

��������������� ������C���T�����������R�• 6.�. ��6�+*��:+��O��)4-����):����'1N�������� �=�� 8)'1N������*��<��) 10%

Page 47: chapter2

���������������� 3 �

3. Repeation or Loop Flowchart

��������������� ���

47

��������������� ����4����5�^�4�• 6.�. :+�'�(6�/5�6� 1-10

Page 48: chapter2

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ;1������D�+^. /�4-���'��-��� *D�+� 1 �O1

48

��5��?�� ������� �����C4�&�

�D�+^. /�4-���'��-��� *D�+� 1 �O1 . /�4-���'��-��� = 1/2 X 0� X �O5

5@�)��'T*edT� : '. ���D�+�. /�4-���'��-���*D�+� 1 �O1��5�����W[� : base 0�, high �O5 , area . /�4-���'��-��� ;<��D�+^=<)*��O6� area = 1/2 * base * high����BC�4����� : 0� (base) ��� �O5 (high)�CC�6X* : . /�4-���'��-����CC�6X* : . /�4-���'��-����B� �CC�6X*���������� :

Base = 4

High = 2.5

Area = 5

Page 49: chapter2

49

�����������4���� ������ (Flowchart)

1. '����6)�4D5� Start 1. '����6)�4D5�2. �D��<��6�+�1� area, high ��� base3. ��:()��O� base ���()��O� high 4. �D�+^�. /�4-���'��-���*��O6�

area = 1/2 * base * high 5. .��.7. /�4-���'��-���

6. *:��4D5�

read high, base

area = 1/2 * base * high

area, high, base

6. *:��4D5�

end

area = 1/2 * base * high

area

Page 50: chapter2

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ;1������D�+^. /�4-���'��-��� *D�+� 5 �O1

50

��5��?�� ������� �����C4�&� + ������� ����4����5�^�4�

�D�+^. /�4-���'��-��� *D�+� 5 �O1 . /�4-���'��-��� = 1/2 X 0� X �O5

5@�)��'T*edT� : '. ���D�+�. /�4-���'��-���*D�+� 5 �O1��5�����W[� : base 0�, high �O5 , area . /�4-���'��-��� ;<��D�+^=<)*��O6� area = 1/2 * base * high ��� x 6�+�1���:*D�+���:(�5��4D5�

x = 1 (%���F���� x ��#���+��!�������& 1 �����"����#�& 1 ��& �O�x = 1 (%���F���� x ��#���+��!�������& 1 �����"����#�& 1 ��& �O��+��#��������' 1 ������������"����#�&�"��$���&���!������ 2������#���+��!�����!�$��� x = 1 �'�+��#��%��!�'��& x = x + 1)

����BC�4����� : 0� (base) ��� �O5 (high)�CC�6X* : . /�4-���'��-��� 5 �O1

Page 51: chapter2

51

��5��?���B� �CC�6X*���������� :

Base = 4Base = 4

High = 2.5

Area = 5

Base = 2

High = 8

Area = 8

5 ��

Base = 15

High = 3.75

Area = 28.125

Page 52: chapter2

52

�����������4����

1. '����6)�4D5�2. �D��<��6�+�1���:*D�+���:(�5��4D5� x = 1, 6�+�1� high, base ��� area3. 6�+*��:*D�+���:(�5��4D5�(x) +��-���)���+� �� �'4���: 5 *��5�� �=��3. 6�+*��:*D�+���:(�5��4D5�(x) +��-���)���+� �� �'4���: 5 *��5�� �=��

3.1 8)*D�+���:(�5��4D5�(x) �-���)���+��� �'4���: 5 ��: (x <= 5) *��5 ��)4D5���()� 4

3.2 ���'�� �*��-/ ��)4D��(�/�6��4-� 8 4. ��:()��O� base ���()��O� high '()�4-��'����7<

5. �D�+^�. /�4-���'��-���*��O6� area = 1/2 * base * high5. �D�+^�. /�4-���'��-���*��O6� area = 1/2 * base * high6. .��.7. /�4-���'��-���7. '.���*D�+���:(�5��4D5�(�/�4-�� 1 (x = x +1) ����)�����:=14D5���()� 38. *:��4D5�

Page 53: chapter2

53

������ (Flowchart)

Start

x = 1, high, base, area

1

2

x <= 5 end

read high, base

area = 1/2 * base * high

no

yes

3

4

5

8

3.1 3.2

area = 1/2 * base * high

x = x+ 1

Print area

5

6

7

Page 54: chapter2

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ������)123���'(-��;1�����'. �����1M���.,7M�����:(���:�:���36'1N�

54

��5��?�� 1 ������� ������C���T�����������R�

��)123���'(-��;1�����'. �����1M���.,7M�����:(���:�:���36'1N�6�+�4�*D����4-�<��(�5������ 1 ��

������������/���:M�� 8�<*���� ��*��-6�+'�( 1 '(-����O�������������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O�

�O1�::M���.,74-�6)�5��

Name : Watcharin Puangplia

Score ( 1 = Pass, 2 = Fail ) : 1

Result : Pass

Page 55: chapter2

55

5@�)��'T*edT� : '. �����1M���.,7M�����:(���:�:���36'1N�6�+�4�*D����4-�<��(�5������ 1 �� ������������/���:M�� 8�<*���� ��*��-6�+'�( 1 '(-����O� ������������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O�����������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O���5�����W[� : name � ��������, score �����(�5������, result M�����:����BC�4����� : � �������� (name) ��������(�5������ (score)�CC�6X* : M�����:(�5������

Page 56: chapter2

56

�����������4����

1. '����6)�4D5�2. �D��<��'����6)���)��:6�+�1� result = | ~, 6�+�1� name ��� score2. �D��<��'����6)���)��:6�+�1� result = | ~, 6�+�1� name ��� score3. ��:()��O�� �������� ��������(�5������'()4-��'����7<

4. 6�+*��:�������(�5���'�-��+���:M�� �� ���:6� score == 1 *��5�� �=�� 4.1 8)�������(�5������'4���: 1 *��5 ��������:M�� result = |Pass~ ��)4D5���()�4-� 5

4.2 ���'�� �*��-/ (�������(�5������'4���: 2 �� ��������(�5������ =��'4���: 1) ��������:6� ��)4D5���()�4-� 5=��'4���: 1) ��������:6� ��)4D5���()�4-� 5

5. .��.7M�����:(�5������6. *:��4D5�

Page 57: chapter2

57

������ (Flowchart) 1

2name,score,result = “ ”

Start

3

4

name,score

T F

result =“Pass” result =“Fail”

score == 14.1 4.2

5

6end

result

Page 58: chapter2

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ����

58

��5��?�� 1.1 ������� ������C���T�����������R� +

������� ����4����5�^�4�

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ������)123���'(-��;1�����'. �����1M���.,7M�����:(���:�:���36'1N�6�+�4�*D����4-�<�� ;<�=<)��:��� ��(�5������ 10 ��

������������/���:M�� 8�<*���� ��*��-6�+'�( 1 '(-����O�������������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O����8)���-���������+� 6 ����:M�� ��).��.7()��+� ���8)���-���������+� 6 ����:M�� ��).��.7()��+�

|Very Good~

Page 59: chapter2

59

�B� �CC�6X*���������� :

Name : Watcharin Puangplia

Score ( 1 = Pass, 2 = Fail ) : 1

Result : PassResult : Pass

Name : Krengkrai Punya

Score ( 1 = Pass, 2 = Fail ) : 1

Result : Pass

Name : Parinda Pumdokmai

Score ( 1 = Pass, 2 = Fail ) : 2

Result : Fail

_________________________________

+���: 10 ���/5

_________________________________

Count Pass = 7

Count Fail = 3_________________________________

Very Good

���1M� ���5*�+���: 10 ���/5

8)���-���������+� 6 ����:M�� ��).��.7()��+� |Very Good~

Page 60: chapter2

60

5@�)��'T*edT� : '. �����1M���.,7M�����:(���:�:���36'1N�6�+�4�*D����4-�<��(�5������ 10 �� ������������/���:M�� 8�<*���� ��*��-6�+'�( 1 '(-����O� ������������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O� 8)���-���������+� 6 ����������/���:6� 8�<*���� ��*��-6�+'�( 2 '(-����O� 8)���-���������+� 6 ����:M�� ��).��.7()��+� |Very Good~ ��5�����W[� : name � ��������, score �����(�5������, result M�����:, count_pass 6�+�1���:*D�+��D���:������4-���:M��, count_fail 6�+�1���:*D�+��D���:������4-���:6�, n ��6�+�1���:*D�+���:(�5��4D5� n = 1����BC�4����� : � �������� (name) ��������(�5������ (score)�CC�6X* : M�����:(�5������, 8)��������+� 6 ����:M�� .��.7�CC�6X* : M�����:(�5������, 8)��������+� 6 ����:M�� .��.7()��+� |Very Good~

Page 61: chapter2

61

�����������4����

1. '����6)�4D5�2. �D��<��'����6)���)��:6�+�1� result = | ~, count_pass = 0, count_fail = 0, n = 13. 6�+*��:*D�+���:(�5��4D5�(n) +��-���)���+� �� �'4���: 10 *��5�� �=��3. 6�+*��:*D�+���:(�5��4D5�(n) +��-���)���+� �� �'4���: 10 *��5�� �=��

3.1 8)*D�+���:(�5��4D5�(n) �-���)���+��� �'4���: 10 ��: (n <= 10) *��5 ��)4D5���()� 4

3.2 ���'�� �*��-/ ��)4D��(�/�6��4-� 8 4. ��:()��O�� �������� ��������(�5������'()�4-��'����7<

5. 6�+*��:�������(�5���'�-��5. 6�+*��:�������(�5���'�-�� 5.1 8)�������(�5������'4���: 1 (��������:M��) ��)6�+��:*D�+�MO)4-���:M���-��'.���(�/�4-������5 count_pass = count_pass + 1

5.2 ���'�� �*��-/ (�������(�5������'4���: 2 �� ��������(�5������=��'4���: 1) ��������:6� ��)6�+��:*D�+�MO)4-���:6��-��'.���(�/�4-������5 count_fail = count_fail + 1

Page 62: chapter2

62

�����������4���� (�?�)

6. .��.7M�����:(�5������7. '.���*D�+���:(�5��4D5�(�/�4-�� 1 (n = n +1) ����)�����:=14D5���()� 38. .��.7M�����:*D�+�(�5MO)4-���:M�� ���M�����:*D�+�(�5MO)4-���:6�6� ���4D��8. .��.7M�����:*D�+�(�5MO)4-���:M�� ���M�����:*D�+�(�5MO)4-���:6�6� ���4D��6�+*��:'5 ���=(

8.1 8)*D�+�(�5MO)4-���:M�����+� 6 ��).��.7()��+� Very Good8.2 ���'�� �*��-/ ��)4D5���()� 9

9. *:��4D5�

Page 63: chapter2

63

������ (Flowchart)

n=1, result = W X, count_pass = 0, count_fail = 0

Start

Print count_pass,

1

2

3F 3.2 7

end

read name, score

score == 1T F

result =WPassX result =WFailX

n <= 10Print count_pass,

count_fail

count_pass > 6Print

WVery GoodX

3

94.1 4.2

T

F

3.1

3.2

4

7

88.1

8.2

endresult =WPassXcount_pass = count_pass +1

result =WFailXcount_fail = count_fail +1

Print result

n = n+1

9

5

6

Page 64: chapter2

*5+�'����7123� '(-��(�/�6����4D5� ���'(-��M�55� (Flowchart) ������)123���������'l�-��(�5������ 4 ������/�'�-��E��5=<)4D�::�����<

64

��5��?�� 3 ������� �����C4�&� + ������� ����4����5�^�4�

��)123���������'l�-��(�5������ 4 ������/�'�-��E��5=<)4D�::�����<�O6��D�+^��'l�-��(�56�+'�(

��M��+�(�56�+'�(4�/5��< *D�+�6�+'�(4�/5��<

�O1�::M���.,74-�6)�5��

��'l�-�� =

Num = 3Num = 3

Num = 4

…..

Num = 7

--------------------------------

Sum = …..

Mean = …..

--------------------------------

Page 65: chapter2

65

5@�)��'T*edT� : '. ��������'l�-��(�5������ 4 ����5�����W[� : num ��6�+'�(, sum ��M��+�(�56�+'�(4�/5��<, mean ��'l�-��(�56�+'�(4�/5��<, n ��6�+�1���:*D�+���:(�5��4D5� ;<�4-� n �-��'����6)�'1N� 1 (n = 1) ����-��'.���(�/�4-�� 1 ����4D5��6�����: (n = n + 1)����-��'.���(�/�4-�� 1 ����4D5��6�����: (n = n + 1)����BC�4����� : ��6�+'�( (num) �CC�6X* : ������+�(�56�+'�( ��������'l�-��(�56�+'�(

Page 66: chapter2

66

�����������4����

1. '����6)�4D5�2. �D��<��'����6)���)��:6�+�1� n = 1 ��� sum = 03. 6�+*��:*D�+���:(�5��4D5�(n) +��-���)���+� �� �'4���: 4 �� �=��3. 6�+*��:*D�+���:(�5��4D5�(n) +��-���)���+� �� �'4���: 4 �� �=��

3.1 8)*D�+���:(�5��4D5�(n) �-���)���+��� �'4���: 4 ��: (n <= 4) *��5 ��)4D5���()� 4

3.2 ���'�� �*��-/ ��)4D��(�/�6��4-� 7 4. ��:()��O�6�+'�('()�4-��'����7<

5. �D�+^M��+����� sum = sum + num5. �D�+^M��+����� sum = sum + num6. '.���*D�+���:(�5��4D5�(�/�4-�� 1 (n = n +1) ����)�����:=14D5���()� 37. �D�+^��'l�-�� mean = sum / 4 �� � mean = sum / (n - 1)

T����T�% (*D�+���:����4DE/D*����+� 1 ���/5)8. .��.7������+�(�56�+'�( ��������'l�-��(�56�+'�(9. *:��4D5�

Page 67: chapter2

67

������ (Flowchart)n=1, sum= 0

Start

Print sum,

n <= 4 mean = sum / (n-1) mean = sum / 4����

end

read num

n = n+1

Print sum, mean

sum = sum + num

'��� ��6�+'�(�-<�5�-/ � � 3, 4, 5, 6, 8, 3

5@X�)@& n = 1, sum = 0 n <= 4 read num sum = sum + num n = n + 15@X�)@& n = 1, sum = 0 n <= 4 read num sum = sum + num n = n + 1��: 1 n = 1, sum = 0 1 <= 4 3 sum = 0+3 = 3 n = 1+1 = 2��: 2 n = 2, sum = 3 2 <= 4 4 sum = 3+4 = 7 n = 2+1 = 3��: 3 n = 3, sum = 7 3 <= 4 5 sum = 7+5 = 12 n = 3+1 = 4��: 4 n = 4, sum = 12 4 <= 4 6 sum = 12+6 = 18 n = 4+1 = 5��: 5 n = 5 ���*� Loop '.��l���/� n = 5, sum = 18, mean = sum / (n-1) = 4.5)4��� )�� sum = 18, mean = 4.5

Page 68: chapter2

68

1. *5'(-��;1�������:6�+'�(�< L 1 �� 6�+*��:6�+'�(4-���:'()�+�'1N�'�(�O�(EVEN) �� �'�(�-�(ODD) �O1�::M���.,74-�6)�5�� :

� ij�T�& $�5@�)��'T*edT� ����������������4���� �C'�����������(Flowchart)

�O1�::M���.,74-�6)�5�� : Input Number = 6Result = EVEN

2. *5'(-��;1�������:��6�+'�(�< L *D�+� 10 �� 6�+*��:��6�+'�(+�'1N�'�(�O� (EVEN) �� �'�(�-�(ODD) �O1�::M���.,74-�6)�5�� :

Input Number = 15Input Number = 15Result = ODD

0.. 10 ��:��4D5�Input Number = 90Result = EVEN

Page 69: chapter2

69

3. *5'(-��;1�������:��6�+'�(�< L *D�+� 10 �� 6�+*��:��6�+'�(+�'1N�'�(�O� �� �'�(�-� �����:*D�+�'�(�O� ���*D�+�'�(�-�+��-1��'�4���-�6�+�B� �CC�6X*����������

Input Number = 71Result = ODDInput Number = Result = ODDr 10 ��)� ��� � Input Number = 4Result = EVEN

Count EVEN = XXX # // ���1M�����:'�(�O� +��-�-�6�+Count ODD = XXX # // ���1M�����:'�(�-� +��-�-�6�+Count ODD = XXX # // ���1M�����:'�(�-� +��-�-�6�+

Page 70: chapter2

70

4. *5'(-��;1�������<5��6�+'�(6�/5�6� 1 8�5 1000 ����:�*��. .�)���M��+�(�56�+'�( �����'l�-���O1�::M���.,74-�6)�5�� :

1 2 3 t 1000 // ��<5��6�+'�(6�/5�6� 1 8�5 1000Summary 1-1000 = XXX # // �M��+�(�56�+'�(6�/5�6� 1 8�5 1000Mean 1-1000 = XXX # // ���'l�-��(�5��6�+'�(6�/5�6� 1 8�5 1000Mean 1-1000 = XXX # // ���'l�-��(�5��6�+'�(6�/5�6� 1 8�5 1000

5. *5'(-��;1�������<5M�:+�(�5'�(�O�4-��-����O�����+5 1 8�5 1000 '��� 2 + 4 + t + 1000 = ???6. *5'(-��;1������D�+^'��<+�����.�+'6��7(�5��������/�1�4-� 1 *D�+� 1 �� *�����()��O� ������:�5���'1N������'�h: 20% �������5�� 40% ��������1���� 40% ;<�.�)��4�/5��<5'��<(�5������ ;<�'�^�74-���)����6�<'��< � �

����� ����

�1�� # 80 +1�- A

70 0+� 79.99 B

60 0+� 69.99 C

50 0+� 59.99 D

���/��#� 50 F

Page 71: chapter2

71

�O1�::M���.,74-�6)�5�� : Student Id : 001Student Name : Ant BirdInput score1(20%) : 15.5Input score2(40%) : 27Input score1(20%) :Input score2(40%) : 27Input score3(40%) : 31Total(15.5 + 27 + 31) = 73.5 pointGrade is B

7. *5'(-��;1������D�+^'��<+�����.�+'6��7(�5��������/�1�4-� 1 *D�+� 70 �� *�����()��O� ������:�5���'1N������'�h: 20% �������5�� 40% ��������1���� 40% ����()��O� ������:�5���'1N������'�h: 20% �������5�� 40% ��������1���� 40% .�)��4�/5��<5'��<(�5������ �����:*D�+�'��<(�5������+��-1��'�4���-�6�+

Page 72: chapter2

72

�O1�::M���.,74-�6)�5�� : Student Id : 001Student Name : Ant BirdInput score1(20%) : 15.5Input score2(40%) : 27 70 �� Input score2(40%) : 27 70 �� Input score3(40%) : 31Total(15.5 + 27 + 31) = 73.5 pointGrade is Br

=================================Count Grade A = XXX people // ���1����:*D�+�'��< A +��-�-�6�+Count Grade A = XXX people // ���1����:*D�+�'��< A +��-�-�6�+Count Grade B = XXX people // ���1����:*D�+�'��< B +��-�-�6�+Count Grade C = XXX people // ���1����:*D�+�'��< C +��-�-�6�+Count Grade D = XXX people // ���1����:*D�+�'��< D +��-�-�6�+Count Grade F = XXX people // ���1����:*D�+�'��< F +��-�-�6�+

Page 73: chapter2

73

8. *5'(-��;1����� �D�+^��<'5���+�4�/5��<4-��������54�':-��'�-�����������4-� 1/2555 *D�+� 25 �� ;<��D��<��)

1.1. �����+���*454nm- ���+���*�� 120 :41.2 �����+���*451o�:�6� ���+���*�� 150 :41.2 �����+���*451o�:�6� ���+���*�� 150 :41.3 ��,���'�-������� ��������� 5000 :41.4 ()��O��������6����� � � � �������� ���������� *D�+����+���*454nm- ���*D�+����+���*451o�:�6�

(B��)4��5U2.1. �����+���*454nm- = *D�+����+���*454nm- x 1202.2 �����+���*451o�:�6� = *D�+����+���*451o�:�6� x 1502.2 �����+���*451o�:�6� = *D�+����+���*451o�:�6� x 1502.3 ��,���'�-���������������� 5000 :42.4 ��<�+�4-��������6�����6)�5�D�� = ��,���'�-�� + �����+���*454nm- + �����+���*451o�:�6�

Page 74: chapter2

74

�O1�::M���.,74-�6)�5�� :Student Id : 001Student Name : Ant BirdInput Theory : 10Input Practice: 5 25 �� Input Practice: 5 25 �� Total(10 + 5) = 15 creditAmount = XXX Batht================================= Summary(25 person) = XXXXXX Bath // ���1��<'5���+�(�5������ 25 ��

9. *5'(-��;1�������:()��O�6�+'�(�< L ����56�+ *5�+�6�+'�(4-���:'()�'� ��.�*�^���6�1��'�4��)+=<)'�(�O��7(zero) '�(*D�+�:+�(plus) �� �'�(�:(minus)�12�))3,,��4��5����� � :

Enter number = 9Result = Plus

Page 75: chapter2

75

10. *5'(-��;1�������:()��O�6�+'�(�< L 15 �� *5�+�6�+'�(4-���:'()�'� ��.�*�^���6�1��'�4��)+=<)'�(�O��7 '�(*D�+�:+� �� �'�(�: 1��'�4���-�6�+�12�))3,,��4��5����� � :

Enter number = 9Enter number = 9Result = Plust 15 �� Enter number = -7Result = Minus-------------------------------------Count Plus = XXX Ans // ���1M�����:*D�+�'�(:+�Count Plus = XXX Ans // ���1M�����:*D�+�'�(:+�Count Minus = XXX Ans // ���1M�����:*D�+�'�(�:Count Zero = XXX Ans // ���1M�����:*D�+�'�(�O��7

Page 76: chapter2

76

11. *5'(-��;1�������<5+�,-����:1��4�� 4-��:�5(�<6����(�5MO)4�<�5�-/������+� 10 1� ��:1��4����/5�� 2 �)���������+� 3 1� 8�5 10 1� ��:1��4����/5�� 1 �)���������+� 1 1� 8�5 3 1� ��:1��4����/5�� 1/2 �)������'��<8�5 1 1� �)���:1��4�������+� 1 1� 8�5 3 1� ��:1��4����/5�� 1/2 �)������'��<8�5 1 1� �)���:1��4�

�O1�::M���.,74-�6)�5�� :Enter Age = 0.5Eat Drug = 0 spoon

�� �Enter Age = 0.5Eat Drug = Donut Eat spoon Eat Drug = Donut Eat spoon

Page 77: chapter2

77

12. *5'(-��;1������D�+^��+��<(�5�)5 Big A *���E /�*D�+� 100 �� .�)��4�/5��<5��<�+���(���4,� <�5��5� �-��+��<<�5�-/

1. =���-:�6���+��< =��=<)��:��+��<�< L 2. Silver Card ��:��+��< 3% 3. Gold Card ��:��+��< 5% 2. Silver Card ��:��+��< 3% 3. Gold Card ��:��+��< 5% 4. Platinum Card ��:��+��< 10%

1��'�4��7< : Silver Card ������) : 850

'5���< : 1000

5@X����)@&(?5�C& 1.8)=���-��+��< ��+��< 0 :42.Silver Card ��+��< = ������) * 0.03'5���< : 1000

��+��< : 25.5 :4����4,� : 824.5 :4'5��4�� : 175.5 :4..........��<�+���4,� (100 ��) = tttttt. :4

2.Silver Card ��+��< = ������) * 0.03�� � ��+��< = ������) * (3/100)

3.Gold Card ��+��< = ������) * 0.05�� � ��+��< = ������) * (5/100)

4.Platinum Card ��+��< = ������) * 0.10�� � ��+��< = ������) * (10/100)

�����%&,� = ���������� w �#��������&�� = ������ w �����%&,�

Page 78: chapter2

Summary (Summary (Summary (Summary ((�%))))

• ����)123�45���.�+'6��7'1N������4D�D���5��<����5 L ���D<�:4-��D��<=+) ���:+�����)123�4-�1����:<)+� ���54-�*����4D ��� �D<�:(�5

78

�D��<=+) ���:+�����)123�4-�1����:<)+� ���54-�*����4D ��� �D<�:(�5�����4D '�-��+� ���:+�+�,- (algorithm)• ����:��D<�:4-��D���5*� execute ��;1��������.�+'6��7 '�-��+� ���+:���;1����� (program control)• Pseudocode '1N��=��'1N�45��4-���+�MO)'(-��;1���������.�9����:+�+�,- *�<�D��3 � � pseudocode ��+���)MO)'(-��;1����� |��<~ +�,-����)123���������4-�*��5� �'(-��;1��������;1����� '��� �E-���:+�+�,- *�<�D��3 � � pseudocode ��+���)MO)'(-��;1����� |��<~ +�,-����)123���������4-�*��5� �'(-��;1��������;1����� '��� �E-• ;��5��)545'� �� (selection structure) ��)'. ��'� �����+�5�����4D��� L ���5 �-����O1�:: =<)��� ;��5��)5 if, ;��5��)5 if/else ���;��5��)5 if/else �::E)����� (nested if/else)

Page 79: chapter2

79

Summary (Summary (Summary (Summary ((�%))))

• ;��5��)54DE/D (repetition structure) ��)'. ����:���)4D�D���5����5 L (�� ���<����5 L) E/D���=1'� ��� L ��(^�4-�'5 ���=(:5���5'1N�*��5 ;��5��)54DE/D������5 L) E/D���=1'� ��� L ��(^�4-�'5 ���=(:5���5'1N�*��5 ;��5��)54DE/D��:4�-/ � � while• Flowchart '1N���3��� 7̂�.4-���)�4����:+�+�,-�� ���+�����5(�5���:+�+�,- ��3��� 7̂4-���)���� flowchart =<)��� ��3��� 7̂�O1=(� (��3��� 7̂ Begin ��� End), ��3��� 7̂�-�'��-���M �M) (��3��� 7̂�����4D), ��3��� 7̂()+���6�< (��3��� 7̂��6�<����*) �����3��� 7̂+5���+5'�h� (��3��� 7̂*�<'� ���)• �O1�::��)6�+��:��� (counter-controlled loop) ��)6�+�1�6�+����5'1N�6�+��: '. ��• �O1�::��)6�+��:��� (counter-controlled loop) ��)6�+�1�6�+����5'1N�6�+��: '. ��6�+*��:+��O1�+�*����<'� ���<• �O1�::��)6�+6�+*6���� (sentinel-controlled loop) *��D��<��)�� L ����5'1N���6�+*6� '� ��MO)��)1�����6�+*6�'()=1 ;1�����*����*��O1

Page 80: chapter2

• ��.�9�;1�����;<���)+�,-��'��*�:��5��5 (top-down, stepwiserefinement) �-�+��D��3�� �+����1o�:�6���)'1N������ ����+�'(-�����:+�

80

Summary (Summary (Summary (Summary ((�%))))

refinement) �-�+��D��3�� �+����1o�:�6���)'1N������ ����+�'(-�����:+�+�,-�������O1 pseudocode ������'(-��;�e<���E- '���• Flowchart '1N���3��� 7̂�.4-���)�4����:+�+�,- �� ���+�����5(�5���:+�+�,- ����+< flowchart ��/�*���)��3��� 7̂4-��-�+����'l.� ���5'��� �-�'��-���M �M), ()+���6�<, �O1=(� ���+5���+5'�h� ��3��� 7̂'����-/*�'� ���'()<)+����;<���) flowline• Flowchart ��)������)5�������<5���:+�+�,- '���'<-�+��: pseudocode• Flowchart ��)������)5�������<5���:+�+�,- '���'<-�+��: pseudocode���5=��h6� ���'(-��;1�������+���3�*�������) pseudocode ���+� '� ��5*��+������:����'(-�� ��4-��-/*���) flowchart '. ����<5��)'�h�+� ;��5��)5�+:����6������<4D5����5=� '4���/�