30
Watcharin Puangplia 01/06/2554 1

chapter1_2

Embed Size (px)

DESCRIPTION

ความรู้เบื้องต้นเกี่ยวกับการเขียนโปรแกรม

Citation preview

Page 1: chapter1_2

Watcharin Puangplia 01/06/2554

1

Page 2: chapter1_2

� Hardware: Hardware: � Software:� People ware:

2

Page 3: chapter1_2

� ��������� (Hardware) �� ��� ����������� � ������ �!"�#�$���#��%&"����� '(�������� )�" ��*��(+!� �,��������� (Hardware) �� ��� ����������� � ������ �!"�#�$���#��%&"����� '(�������� )�" ��*��(+!� �,

1. ���� ������� (Input unit) ��� ��������!(�56� �7� 6�����!(8��'���'9*56��:9�56�):��#�$���#��%&"����� ��������!(�56����;<6�! ��� )�" ;=�

2. ��������������� (Central Processing Unit) �$� CPU �� 2 )�" #$�2.1 ��������� (Control Unit �$� CU) �7� 6����#"(#��97�+!(5!, �� ����7���

5�� �" �!(56��:9 �" ')+�G9 �" #7� "�'9* �" ���� �" #"��H7�'9*'�9#7�)!�� 5�� �" �!(56��:9 �" ')+�G9 �" #7� "�'9* �" ���� �" #"��H7�'9*'�9#7�)!�� 2.2 ��������������� (Arithmetic and Logic Unit �$� ALU) �7� 6����; ���

#7� "���!"�95 �<� ���("� 9( ������� (��� ( 3. ��������� (Output Unit) �7� 6����')+�G99!%O����P+6H�������*�"9G95��

�#�$���#��%&"����� �$�;<6��Q(G99!%O��%$�� 7�P�;<6R� 9!� P+6'�� H�R�% (Monitor) ��� �������)�����������)�+ �#�$���%&�%� (Printer)

3

Page 4: chapter1_2

� 8��'������ �9���5��<�+#7�)!�� (Instruction)8��'�������:��5� 5�, ��H��R�T�#��%&"�����;6�7��� � ���;+� ��� ���; 8��'������ �9���5��<�+#7�)!��

� 8��'�������:��5� 5�, ��H��R�T�#��%&"�����;6�7��� � ���;+� ��� ���; #��%&"�����

� '(�������� 2 ��*�R� #$�� U�V��'"���*(( (System Software)

� U�V��'"����* ���� (Application Software)

4

Page 5: chapter1_2

� #$� 8��'�������7� 6����; ���#"(#������7��� 5��#��%&"������"���������������� �"�����7� 6������� �!"�9���*"���G:6;<6�� �!(#��%&"�����#$� 8��'�������7� 6����; ���#"(#������7��� 5��#��%&"������"���������������� �"�����7� 6������� �!"�9���*"���G:6;<6�� �!(#��%&"�����

� '(�������� 2 � ��� #$�� �*((�W&(!�&��� (Operating System) �7� 6����#"(#��+:'9���+7�� & �������� R� ; �*((#��%&"�����'9*��� �!"�9��; �����*)� �� ����7��� 5��Z���+'"��'9*U�V��'"������� �<� Dos, Windows, Mac OS X

� 8��'���������*8 < � (Utility Program) �<� ScanDisk, System Restore� 8��'���������*8 < � (Utility Program) �<� ScanDisk, System Restore

5

Page 6: chapter1_2

� ��� 8��'����$�<�+#7�)!������5� 5�, �%$��;6�#�$���#��%&"������7��� �a%�*� ������ 8��'����$�<�+#7�)!������5� 5�, �%$��;6�#�$���#��%&"������7��� �a%�*� ����$��a%�*+6�

� '(�������� 2 � ��� #$�� U�V��'"����� 7���;<6)7��!(�� �a%�*+6� (Application-Specific) �$�8��'�������5� 5�, ��� ��� <�+U�V��'"������� ���;<6�!(�*((�� ���O���&H�$��*((��� �$� � ������� "56�� �<� 8��'���(!=<�, )& #6�#�#9!�, U�V��'"��"&�#��*�G:6�d" ������'%� ����'%� �

� U�V��'"����� 7���;<6�� �!�"� P� (General Purpose) �$�8��'���)7���QH�:� ��� U�V��'"�����G:6;<6)����� 7�U�V��'"��+!��9��"P�;<6�� �!�"� P�P+6 �<� 8��'�����*�"9G9#7�, 8��'���f� 56��:9, 8��'������VVg�

6

Page 7: chapter1_2

� ������� (People ware) �� ��� (�#9������#��%&"���������7� 6����; ���;<6'9*+:'9�#�$���#��%&"����� �<� !��5� 8��'��� (Programmer) !�"&�#��*�������� (People ware) �� ��� (�#9������#��%&"���������7� 6����; ���;<6'9*+:'9�#�$���#��%&"����� �<� !��5� 8��'��� (Programmer) !�"&�#��*��*(( (System Analyst) ��� �6

7

Page 8: chapter1_2

� �!(56��:9 (Input) : K/B, Mouse, File, Barcode Reader, RFID

��*�"9G9 (Process) : Program�!(56��:9

� ��*�"9G9 (Process) : Program� ')+�G956��:9 (Output) : Monitor, Printer, File

� H!+��Q(56��:9 (Storage) : Disk, Tape, CD, DVD

8

Page 9: chapter1_2

9

Page 10: chapter1_2

� #$� R�T����)����� 7���;<6�5� 8��'���#��%&"�����P+6���%!h �5��R�T�#��%&"�����'(�������� 5 �# +!� �,#$� R�T����)����� 7���;<6�5� 8��'���#��%&"�����P+6

� ���%!h �5��R�T�#��%&"�����'(�������� 5 �# +!� �,� �#��� 1 (First Generation Language: 1GL)

� �#��� 2 (Second Generation Language: 2GL)

� �#��� 3 (Third Generation Language: 3GL)

� �#��� 4 (Fourth Generation Language: 4GL) �#��� 4

� �#��� 5 (Fifth Generation Language: 5GL)

10

Page 11: chapter1_2

� R�T��#�$��� (Machine Language)��� R�T�%$, f� ���#��%&"�����)������56�;HP+6 '��9*#7�)!����*��(5�, H��R�T��#�$��� (Machine Language)

� ��� R�T�%$, f� ���#��%&"�����)������56�;HP+6 '��9*#7�)!����*��(5�, H���9����!"�95 0 '9* 1 U������ �95f� )��

11

Page 12: chapter1_2

� R�T�'�)�U�(9� (Assembly Language)��� R�T����;<6)!=9!�T��56�#"�� '� �9���5���!"�95f� )�� �%$��;6��� ���R�T�'�)�U�(9� (Assembly Language)

� ��� R�T����;<6)!=9!�T��56�#"�� '� �9���5���!"�95f� )�� �%$��;6��� �������5� '9*���H+H7����5�, ����7��� 5��8��'���H*�6���7����'�9R�T�'�)�U�(9�;6��� R�T��#�$��� 8+ ;<6�!"'�9������ �"�� '�)�U��(9��� (Assembler)

12

Page 13: chapter1_2

� R�T�<!, ):� (High-Level Language) �$�R�T���� ��� 3�:�)�6��5�, ���%$��;6�5� 8��'���P+6��� 5�, 8+ ��9!�T�*��$� �!(R�T�<!, ):� (High-Level Language) �$�R�T���� ��� 3

� �:�)�6��5�, ���%$��;6�5� 8��'���P+6��� 5�, 8+ ��9!�T�*��$� �!(R�T��!��nT�!�"P� G:6�5� P��H7���� �6����#"���:6���� "�!(Z���'"��'��� ���;+ R�T� �,H7���� �6�����!"'�9R�T��#�$����<� �! ��� ��!"'�9 �,"�� #��P%�9��� (Compiler) �$� �& �����%������� (Interpreter) � ���;+� ��� ���

� �!"� ���5��R�T�<!, ):� �<� R�T���)#�9 R�T�U� R�T8#(�9 R�T�()&� R�T�V���'�� R�T�V���'��

13

Page 14: chapter1_2

� R�T�<!, ):���� (Very High-Level Language)�$�R�T���� ��� 4 (4GL)��� R�T������9!�T�*#96� R�T�%:+������&5��� �T � R�T� �,H*<�" ;6���R�T�<!, ):���� (Very High-Level Language)�$�R�T���� ��� 4 (4GL)

� ��� R�T������9!�T�*#96� R�T�%:+������&5��� �T � R�T� �,H*<�" ;6����5� 8��'�����Q"���5�, �"��R�T�; ��� ��� 3 � $���H�����#�$����$����<�" ; ���)�6��'((V���� 6�H� �%$��H!+����!(56��:9�"�P������������ �� �� :���� �

� �!"� ���5��R�T�<!, ):����P+6'�� informix-4GL, MAGIC , Delphi , Power Builder r9r

14

Page 15: chapter1_2

� R�T�O���<��& (Natural Language) �$�R�T���� ��� 5 (5GL)��� R�T����)�����)!���� #��%&"�����8+ ;<6�:�'((5��R�T�� �T �P+6�9 R�T�O���<��& (Natural Language) �$�R�T���� ��� 5 (5GL)

� ��� R�T����)�����)!���� #��%&"�����8+ ;<6�:�'((5��R�T�� �T �P+6�9 #7�)!��� :�; �:�'((���P��' � � �� �!" '��#��%&"�����H*�7����'�9;6�����; �:����#��%&"������56�;HP+6 R�T� �,�:�)�6��5�, ��H����#8 89 ����+6� �*((G:6�<� "<�= (Expert System)

� �!"� ���R�T�; ��� ��� 5 P+6'�� R�T� PROLOG ��� �6

15

Page 16: chapter1_2

� �*+!(5��R�T�#��%&"�����'(�������� 3 �*+!( +!� �,�*+!(5��R�T�#��%&"�����'(�������� 3 �*+!( +!� �,� R�T��#�$��� (Machine Language)

� R�T��*+!(��7� �$� R�T�)!=9!�T�� (Low Level Language �$� Symbolic Language)

� R�T��*+!():� (High Level Language)

16

Page 17: chapter1_2

� ��� R�T�����5� ��� �!)�95f� )�� U���#��%&"�����)������56�;HP+6�! �� �9��"#$� H*;<6�a%�*�95 0 '9* 1 ���� !, �5� )9!(�! P����%$��;<6��� �!)��� R�T�����5� ��� �!)�95f� )�� U���#��%&"�����)������56�;HP+6�! �� �9��"#$� H*;<6�a%�*�95 0 '9* 1 ���� !, �5� )9!(�! P����%$��;<6��� �!))!���� ;6�#�$���#��%&"������7��� ����6�����

� ��� R�T�����5� �� � $���H��G:6�5� H*�6��H7��!)#7�)!���������� H7� " ��� H��P����� ��� & �; �uHH�(!

� R�T��#�$������ �%� �R�T��+� "���� !, ���#��%&"�����)������56�;H'9*�W&(!�&�� ���P+68+ P���6�������'�9P���� R�T��$� ����W&(!�&�� ���P+68+ P���6�������'�9P���� R�T��$� ���

17

Page 18: chapter1_2

� ���("�'� +6" �!) 10101010� ���("�'� +6" �!) 10101010� �95 5 00000101� �95 6 00000110� +!� !, #7�)!�� 5+6 �QH*�6���5� "�� � 00000101 10101010 00000110

18

Page 19: chapter1_2

� ��� R�T����;�96<&+�!(�#�$���#��%&"�������� �#�$���#��%&"�����)������56�;H#7�)!��; R�T� !, P+6��� ��� R�T����;�96<&+�!(�#�$���#��%&"�������� �#�$���#��%&"�����)������56�;H#7�)!��; R�T� !, P+6���

� R�T� Assembly (Assembly Language) �$�R�T�)!=9!�T�� (Symbolic Language) H*� :�; �:�5��)!=9!�T�� 8+ ��� 7��!"�!�T� ���$�)!=9!�T���������;<6�5� '� �!"#7�)!�� U���H*�7�;6)�����H7�'9*�5� #7�)!�������P+6��� 5�, �"��R�T��#�$���

� '����� ���H* 7�P�)!���� �#�$���#��%&"�����P+6 �6��'�9 (Compile);6��� � '����� ���H* 7�P�)!���� �#�$���#��%&"�����P+6 �6��'�9 (Compile);6��� R�T��#�$������ 8+ ;<68��'��� Assembler

19

Page 20: chapter1_2

� ��� R�T����;�96�#� ��!(R�T�� �T �������)�+ �7�;6)������5� '9*�7�#"���56�;HP+6��� ��� R�T����;�96�#� ��!(R�T�� �T �������)�+ �7�;6)������5� '9*�7�#"���56�;HP+6���

� � $���H������� 7�#7�x!%��'9*56�#"������� ���� �T �;<6� :�; <�"&���*H7�"! ����� #7�)!���%$��;6#��%&"������7��� �<� #7�"�� READ, WRITE, GOTO, PRINT ��� �6

� ; )�" ���#7� "�������Q�5� ��� #7�)!�������9!�T�*#96� ��!():��#�&�x�)���O���+� �7�;6)�����x��T�'9*�5� #7�)!��P+68+ ��� O���+� �7�;6)�����x��T�'9*�5� #7�)!��P+68+ ���

20

Page 21: chapter1_2

X = 5 + 6

� R�T��*+!():� P+6'�� R�T� PASCAL, C, COBOL, BASIC ��� �6

X = 5 + 6

PRINT X

� R�T��*+!():� P+6'�� R�T� PASCAL, C, COBOL, BASIC ��� �6

21

Page 22: chapter1_2

� �%��*"��; 9!�):�������� � :�; "&<�(!�#!(� �%��*"��; 9!�):�������� � :�; "&<�(!�#!(� �%��*�!"���<�(9!�):�� �,���!,�'���6 � �%��*� ���%&��%: #"���:6#��%&"������ �%��*�6������5� 8��'���P"6;<6���� �%��*"�����(6� � ��;6��� )� �,� �%$��;6��� ��� 5�, � ...... r9r� ...... r9r

** +������,�-��./��0�������0����1�2 3�0�������0�** 2 3�+�����,�4�5 ,267����8������������9:79������0��** ,�;���� ����8��-<���2 3�,9�++��:

22

Page 23: chapter1_2

� ��� �6 �7�� &+���)7�#!=5��R�T�;��H7� " ��� �<� Java, C#P�x��T����R�T��$� P+6��� ��� �6 �7�� &+���)7�#!=5��R�T�;��H7� " ��� �<� Java, C#

� P�x��T����R�T��$� P+6��� � ��� �:6��� � )�6���*((�W&(!�&���� #"(#���������Z���+'"��

23

Page 24: chapter1_2

� 8��'�������5� 5�, �� P��"��H*�5� 8+ ;<6�&+&����� (Editor) �*P��Q��� H*P+6U���)8#6+ (Source Code) U���H*��Q(; �:�'V|�56��:9 U���H*�� ��)��9'������8��'�������5� 5�, �� P��"��H*�5� 8+ ;<6�&+&����� (Editor) �*P��Q��� H*P+6U���)8#6+ (Source Code) U���H*��Q(; �:�'V|�56��:9 U���H*�� ��)��9'�������! P�+!� �,

=�>� ������ � ������

C++C

Pascal

.c.cpp.pas

hello.chello.cpphello.pasPascal

PerlPHPJava

.pas.pl.php.java

hello.pashello.plhello.phphello.java

24

Page 25: chapter1_2

----

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

?����+��� �����������+������ +������9:7�����29����0��+��0�������: source code

25

Page 26: chapter1_2

� �!"�9������7� 6����'�9H��R�T��*+!():�;6��� R�T��#�$���8��'���'�9R�T�#��%&"�����������7��� 3 9!�T�*�!"�9������7� 6����'�9H��R�T��*+!():�;6��� R�T��#�$���

� 8��'���'�9R�T�#��%&"�����������7��� 3 9!�T�*� 8��'���'�9R�T�'(('�)�U��(9��� (Assembler) ;<6'�9�!)#7�)!���a%�*R�T�'�)�U�(9�;6��� �95f� )��

� 8��'���'�9R�T�'((#��P%�9��� (Compiler): '�9�!,�'���6 H H(

� 8��'���'�9R�T�'((�& �����%������� (Interpreter): '�9��9*#7�)!��

26

Page 27: chapter1_2

� 8+ #��P%�9���H*��&����� #7�)!���!,��+; 8��'������ �%$��+:"����)�" ;+G&+H��9!����5��R�T� !, �$�P�� �6�P��%(56�G&+%9�+ #��P%9��9���H*'�98+ #��P%�9���H*��&����� #7�)!���!,��+; 8��'������ �%$��+:"����)�" ;+G&+H��9!����5��R�T� !, �$�P�� �6�P��%(56�G&+%9�+ #��P%9��9���H*'�9#7�)!���!,��+;6��� R�T��#�$���'9*%�6���7��� )�" ;=�H*��� R�T��*+!():� �<� Pascal, Cobol, Visual Basic, Java, C, C++ � ����:: �7��� P+6�"+��Q"�%��*P���6��'�9�!);�����#�!,�

� ���,�:�: �6���5� 8��'���;6#�(���)�" 5��8#��)�6��R�T�#��%&"�����H��H*)�����#��P%9�'9*��*�"9G9�%$��')+�G9P+6)�����#��P%9�'9*��*�"9G9�%$��')+�G9P+6

27

Page 28: chapter1_2

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

printf(“YY”);}

Main(){

printf(“XX”);printf(“YY”);}

� �������

���� !�"#$�

%&'��%��$()��

*���� +*���� +

�$�%��

28

Page 29: chapter1_2

� H*��� #7�)!��'(((���!+���(���!+#$���� (���!+'�����Q�7��� ��� !, �! �� ���P��Q��� (���!+���)����'96"�7�����! �� ��$��%(56�G&+%9�+H* �+�7��� ���P��Q��� (���!+���)����'96"�7�����! �� ��$��%(56�G&+%9�+H* �+�7��� '96"'H6�56�G&+%9�+;6���(�%$��'�6P5 H�� !, ��*�"9G9;��H �"��H*P����56�G&+%9�+ )�" ;=�H*��� R�T�)#�&������ & �;<6; ����5� �"Q( �<� Perl. PHP,ASP� ����:: #$���*�"9G9#7�)!���%$��+:G9����7��� P+6�! �� 8+ P���6���5� ���(���!+)�+�6� )�+�6�

� ���,�:�: ��8��'�����(���!+#7�)!��H7� " ���H*��*�"9G9<6� �%��*�6����&��'�9�!)#7�)!��;�����(���!+'�����#�!,�

29

Page 30: chapter1_2

� ��$���5� 8��'����)�QH G�� ���'�9R�T�'96"G9���P+6�QH*��� PV9�8��'������)����� 7�P�;<6P+6�9 8+ ��H�������9�+&)��P���g+����#�$����$� � P+6 U���H*��� ��$���5� 8��'����)�QH G�� ���'�9R�T�'96"G9���P+6�QH*��� PV9�8��'������)����� 7�P�;<6P+6�9 8+ ��H�������9�+&)��P���g+����#�$����$� � P+6 U���H*��� PV9�8��'���' �H���!"U���)8#6+�������5�

� PV9�8��'������P+6 !, ��� PV9�'((�95f� )�� �$�P( ���PV9� (.exe) ��� �"����Q�U�#&"���(&,9PV9� (Executable File)

30