Unit 1-Introduction To Programming And Computer Science PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides an introduction to programming and computer science. It covers topics such as computer history, different generations of computers, programming languages, and operating systems. The document is suited to a secondary school educational setting.
Full Transcript
UNIT 1. INTRODUCTION TO PROGRAMMING AND COMPUTERS PROGRAMMING YEAR 2020-2021 Unit 1. Introduction to computers and programming Contents OUTLINE 1. Computers and Computer Science 2. Historic perspective 3. Algorithms and programs. Tools for algorithm design 4. Informa...
UNIT 1. INTRODUCTION TO PROGRAMMING AND COMPUTERS PROGRAMMING YEAR 2020-2021 Unit 1. Introduction to computers and programming Contents OUTLINE 1. Computers and Computer Science 2. Historic perspective 3. Algorithms and programs. Tools for algorithm design 4. Information representation in computers 5. Software: Programs and Programming languages 6. Hardware: Functional structure of a computer. Computer architecture. 7. Computer networks 3 Unit 1. Introduction to computers and programming 1.1. Computers and Computer Science COMPUTER Electronic machine able to accept input data, perform operations with data, and provide a result as output. This transformation process is controlled by a set of instructions (the program), which has been previously stored in the computer Features – automatic information processing – capacity for storing data and programs – Able to communicate with other computers (networking) and people (human-computer interfacing) 4 Unit 1. Introduction to computers and programming 1.1. Computers and Computer Science BASIC COMPONENTS OF A COMPUTER Physical support: Hardware – Mechanical and electronic elements that physically make up the computer memory modules, screen, keyboard, motherboard, etc. Logical support: Software – Logic part that directs the actions of the physical support – Set of programs that make the computer perform useful tasks text processor, image editor, video game, etc. 10 2. BRIEF HISTORY OF COMPUTERS (SEE ANNEX FOR MORE I N F O R M AT I O N ) Unit 1. Introduction to computers and programming 1.2. History of computers HISTORY OF COMPUTERS TIMELINE 1.2. History of computers Source: Randy Cannon & The History of Computing 14 Unit 1. Introduction to computers and programming 1.2. History of computers THE FIVE GENERATIONS OF COMPUTERS See annex I for more information First generation: Vacuum tubes on computers history Second generation: Transistors Third generation: Integrated circuits Fourth generation: Microprocessors Fifth generation: ?? Circuit module from early IBM computer 15 (IBM 700) with vacuum tubes 3. ALGORITHMS AND PROGRAMS ALGORITHMS AND PROGRAMS An algorithm is a specific set of steps (sequence of instructions) to solve a problem (in a finite time) A program implements an algorithm using a specific programming language MY FIRST ALGORITHM Design an algorithm to implement the access control to a system, such as a smartphone – Use your own words or a diagram – Don't use a programming language! – As if you were explaining it to a lay person Enter your PIN Unit 1. Introduction to computers and programming Algorithms and programs PSEUDOCODE START attempts=0 REPEAT Input password count attempt If password NOT correct message “incorrect, please re-enter” WHILE (password NOT correct and attempts loss of precision – Be careful when comparing two numbers They will only be considered equal by the computer if they are equal bit by bit 41 Unit 1. Introduction to computers and programming 2. Information representation in computers IEEE 754 STANDARD FOR FLOATING POINT REPRESENTATION Most commonly used representation in current computers – 32 bits Base 2 (by default, not encoded so no additional bits are used) Mantissa: 1 bit for the sign, 23 bits for the digits Exponent: 8 bits – 64 bits extension for double precision encoding 42 Unit 1. Introduction to computers and programming 2. Information representation in computers REPRESENTING ALPHABETIC AND ALPHANUMERIC DATA Alphabetic: Skywalker; Alphanumeric: R2D2 Character encoding – bi-univocal correspondence between a set of characters and a set of bit combinations representing numbers (by means of an encoding table) – characters include numerical, alphabetical, special, and control symbols 43 Unit 1. Introduction to computers and programming 2. Information representation in computers REPRESENTING ALPHABETIC AND ALPHANUMERIC DATA Common character encodings – Extended ASCII code (American Standard Code for Information Interchange) ASCII encoding uses 7 bits – 128 (27 ) different characters can be represented Extended ASCII: 8 bits – 256 (28 ) different characters can be represented – UNICODE handling of text expressed in most of the world's writing systems – 154 modern and historic scripts Standard maintained by the Unicode Consortium 44 Unit 1. Introduction to computers and programming 2. Information representation in computers From 0 to 31 control ASCII TABLE characters dec bin oct hex char dec bin oct hex char dec bin oct hex char dec bin oct hex char 32 010 0000 040 20 space 57 011 1001 071 39 9 103 110 0111 147 67 g 80 101 0000 120 50 P 33 010 0001 041 21 ! 58 011 1010 072 3A : 104 110 1000 150 68 h 81 101 0001 121 51 Q 34 010 0010 042 22 " 59 011 1011 073 3B ; 82 101 0010 122 52 R 105 110 1001 151 69 i 35 010 0011 043 23 # 60 011 1100 074 3C < 83 101 0011 123 53 S 106 110 1010 152 6A j 36 010 0100 044 24 $ 61 011 1101 075 3D = 84 101 0100 124 54 T 107 110 1011 153 6B k 37 010 0101 045 25 % 38 010 0110 046 26 & 62 011 1110 076 3E > 85 101 0101 125 55 U 108 110 1100 154 6C l 39 010 0111 047 27 ' ? 86 101 0110 126 56 V 109 110 1101 155 6D m 63 011 1111 077 3F 40 010 1000 050 28 ( 87 101 0111 127 57 W 110 110 1110 156 6E n 64 100 0000 100 40 @ 41 010 1001 051 29 ) 88 101 1000 130 58 X 111 110 1111 157 6F o 65 100 0001 101 41 A 42 010 1010 052 2A * 89 101 1001 131 59 Y 112 111 0000 160 70 p 66 100 0010 102 42 B 43 010 1011 053 2B + 90 101 1010 132 5A Z 113 111 0001 161 71 q 44 010 1100 054 2C , 67 100 0011 103 43 C 91 101 1011 133 5B [ 114 111 0010 162 72 r 45 010 1101 055 2D - 68 100 0100 104 44 D 46 010 1110 056 2E. 92 101 1100 134 5C \ 115 111 0011 163 73 s 69 100 0101 105 45 E 47 010 1111 057 2F / 93 101 1101 135 5D ] 116 111 0100 164 74 t 70 100 0110 106 46 F 48 011 0000 060 30 0 94 101 1110 136 5E ↑ 117 111 0101 165 75 u 71 100 0111 107 47 G 49 011 0001 061 31 1 118 111 0110 166 76 v 72 100 1000 110 48 H 95 101 1111 137 5F ← 50 011 0010 062 32 2 w 96 110 0000 140 60 @ 119 111 0111 167 77 73 100 1001 111 49 I 51 011 0011 063 33 3 97 110 0001 141 61 a 120 111 1000 170 78 x 52 011 0100 064 34 4 74 100 1010 112 4A J 98 110 0010 142 62 B 121 111 1001 171 79 y 53 011 0101 065 35 5 75 100 1011 113 4B K 99 110 0011 143 63 c 122 111 1010 172 7A z 54 011 0110 066 36 6 76 100 1100 114 4C L 100 110 0100 144 64 d 123 111 1011 173 7B { 55 011 0111 067 37 7 77 100 1101 115 4D M 124 111 1100 174 7C ACK 101 110 0101 145 65 e 78 100 1110 116 4E N 125 111 1101 175 7D } 102 110 0110 146 66 f 126 111 1110 176 7E ESC 45 79 100 1111 117 4F O Unit 1. Introduction to computers and programming 2. Information representation in computers REPRESENTING SOUND AND MUSIC Sound is an analogic signal First step is to discretize (digitalize) – Data is sampled at a given frequency Second step: Each sample is encoded (e.g., as an integer) Quality of the reconstructed signal (to reproduce the original sound) depends on the: – Number of samples per second – Number of bits used to encode each sample Information is lost! 47 Unit 1. Introduction to computers and programming 2. Information representation in computers IMAGE REPRESENTATION (BASIC) The image is sampled in a pixel matrix Each pixel is a value representing a colour value 1-bit per pixel allow representing B & W pictures More bits per pixel are required to represent colours Compression techniques are used to eliminate redundant data and reduce the file size 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 48 Unit 1. Introduction to computers and programming 2. Information representation in computers IMAGE REPRESENTATION Image quality depends on: – Resolution: number of pixels by surface unit – Number of bits per pixel (8, 16, 24, 32) 8 bits/pixel allows representing 256 different colours 256 colours 16 colours 2 colours 40 pixels / cm 32.000 colours 8 pixels / cm 32.000 colours 49 5. SOFT WARE Unit 1. Introduction to computers and programming PROGRAM Program: Set of orders (instructions or sentences) written in a programming language that are provided to the computer to develop a task – A program implements an algorithm Problem Algorithm Program Programming Language 51 PROGRAMMING LANGUAGES, INTERPRETERS AND COMPILERS. Human High level language languages Source code Interpret Compile (instructions one by one) Assembly code Object code Low level Assembler Linker languages Machine (binary) code Binary PROCESSOR code interpreted language — The source code is read by an intermediate program that directly executes the commands. Examples: Matlab, Python Compiled language — The source code is converted into a machine-readable file, called the binary or executable, by a compiler. The binary is then executed separately by the user. Examples: Fortran, C, C++. High level language Assembly code Unit 1. Introduction to computers and programming OPERATING SYSTEMS An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between programs and the computer hardware Multi-tasking operating system allows more than one program to be running in concurrency : the available processor time is divided between multiple processes (time sharing) 56 56 6. HARDWARE COMPUTER ARCHITECTURE Basic hardware structure of a computer – Defined by Von Neumann (1945) Secondary memory Central Processing Unit (CPU) Processor Arithmetic- Control Unit Logic Unit Input devices (ALU) Output devices Communication Main memory buses HOW DOES A COMPUTER RUN A PROGRAM? every high level instruction is translated into many lower level instructions, that perform very simple steps What are the steps to add up two numbers? COMPONENTS OF THE CENTRAL PROCESSING UNIT PROCESSOR MAIN MEMORY CONTROL Instruction counter register UNIT Data 1 Instruction register Instruction Data address Data 2 Data 3 clock Decoder Operand 1 Register Operand 2 Register Instruction 1 Instruction 2 ARITHMETIC- Instruction 3 LOGIC UNIT Result register RUNNING A PROGRAM PROCESSOR MAIN MEMORY F002 CONTROL Instruction counter register UNIT Data 5 1 0002 Instruction register Instruction Data address Data 3 2 0004 ADD($0002,$0004,$0006) Data 8 3 0006 clock Decoder Operand 1 Register Operand 2 Register Instruction 1 ADD($0002,$0004,$0006) F002 5 3 Instruction 2 ARITHMETIC- Instruction 3 LOGIC UNIT 8 Result register BUSES PROCESSOR MAIN MEMORY F004 F002 CONTROL UNIT Instruction counter register Data 5 1 0002 Instruction register Instruction Data address Data 3 2 0004 ADD($0002,$0004,$0006) Data 8 3 0006 clock Decoder Operand 1 Register Operand 2 Register Instruction 1 ADD($0002,$0004,$0006) F002 5 3 Instruction 2 F004 ARITHMETIC- LOGIC Instruction 3 UNIT 8 Result register Data bus Instruction bus Control bus Unit 1. Introduction to computers and programming 2.2.2. Ejecución de Instrucciones RUNNING AN INSTRUCTION The execution of an instruction is based on the following steps: 1. The control unit fetches from main memory the instruction to be executed (by reading from the memory address specified by the instruction counter register). 2. That instruction is stored in the instruction register, which consists of two parts: one containing the operation code and the other containing the memory address where the data involved in that operation is located. 65 Unit 1. Introduction to computers and programming 2.2.2. Ejecución de Instrucciones RUNNING AN INSTRUCTION (CONT) The execution of an instruction is based on the following steps: – 3. The control unit sets the necessary connections via the system buses. It takes from memory, if necessary, the data to be processed (e.g. by storing them in the operand one and operand two registers). Sends the control signals to different the elements (e.g. the arithmetic logic unit) to carry out the instructions Sends the data in the registers if needed – 4. If the instruction has resulted in new data, this piece of data is moved to main memory. – 5. Increments the instruction counter register and moves on to the next instruction. 66 7. COMPUTER N ET W O R KS Unit 1. Introduction to computers and programming COMPUTER NETWORKS set of interconnected computers computers use common communication protocols over digital interconnections to communicate with each other. physically wired, optical, and wireless radio-frequency methods Fuente: Wikimedia Commons [link] 69 Unit 1. Introduction to computers and programming PACKET SWITCHED NETWORKS AND THE INTERNET 3. Packets are transmitted from computer to computer towards the destination. The path may 2. Each packet is be different for two attached a header with packets. Packets may be information: sender, unsorted at the destination receiver, and number ROUTER computer of packet 2 1 1 2 2 5 6 4 1 3 ROUTER 5 1 4 ROUTER 1 2 3 4 5 6 ROUTER 5 6 1 2 3 4 5 6 4 4 3 6 3 4. The receiver sorts 1. Information is sliced the information to ROUTER into small pieces rebuild the original (packets) message send receive 70 UNIT 1. INTRODUCTION TO PROGRAMMING AND COMPUTERS PROGRAMMING