Créer une présentation
Télécharger la présentation

Télécharger la présentation
## Lesson 1b: Computer Systems and Program Development

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**CPS118**Lesson 1b: Computer Systems and Program Development**Objectives**• What Is a Computer? • What is an algorithm? • Computer Components • Binary number system • Software Development Method • problem solving**Computer Systems**• Computers are electronic systems that can transmit, store and manipulate information (data). • Data can be numeric, character, graphic and sound. • For beginner programmers, the two most important are character and numeric. • To manipulate data, a computer needs a set of instructions called a program. • To write such programs is the object of this course.**Computer**• An electronic machine that can receive, store, transform, and output data of all kinds numbers, text, images, graphics, and sound, to name a few.**Algorithms**• An algorithm is a series of instructions on how to solve the problem. • An algorithm is a finite set of instructions which, if followed, accomplish a particular task. • Computing definition: • A computable set of steps to achieve a desired result.**Characteristics of algorithms**• Algorithms have the following characteristics: • Precision • Uniqueness • Finiteness • Input • Output • Generality**Criteria of algorithm**• must satisfy the following: • input: • there are 0 or more quantities which are externally supplied; • output: • at least one quantity is produced; • definiteness: • each instruction must be clear and unambiguous; • finiteness: • for all cases the algorithm will terminate after a finite number of steps; • effectiveness: • every instruction must be sufficiently basic • it can in principle be carried out by a person using only pencil and paper.**A friend come to visit you:**• The taxi algorithm: • Go to the taxi stand. • Get in a taxi. • Give the driver my address. • The call-me algorithm: • When your plane arrives, call my cell phone. • Meet me outside baggage claim. • The rent-a-car algorithm: • Take the shuttle to the rental car place. • Rent a car. • Follow the directions to get to my house. • The bus algorithm: • Outside baggage claim, catch bus number 70. • Transfer to bus 14 on Main Street. • Get off on Elm street. • Walk two blocks north to my house.**Algorithm Example**• Input (what is needed by the program): n • Output (the value computed by the program): 1/1+1/2+...+1/n • 1. answer=0 (initialize the answer at 0) • 2. d=1 (start the denominator at 1) • 3. answer=answer+1/d (adding 1/d to the previous answer) • 4. d=d+1 (adding 1 to the denominator) • 5. repeat lines 3 and 4 until d is equal to n**Computer Systems**3 types of computer systems: • Mainframes and minicomputers • Workstations • Personal computers • PCs • Laptops**Input & Output Devices**Secondary Storage: monitor CD Central Processing Unit printer ALU CU zip disk scanner floppy disk keyboard Main Memory hard disk mouse Computer Components**I/O 1**I/O 2 I/O n Bus CPU Memory Sec. Storage Computer System • CPU + Main Memory ~ “core” • Secondary Storage + I/O Devices ~ “peripherals” • Bus ~ communication between components**Storage Types**CPU Registers: Only a few cells on CPU Main memory (RAM): Millions of cells on circuits separate from CPU. Secondary storage: Billions of cells on disks or tapes. Secondary storage is not volatile.**Internal representations**Bit: Binary digit (0 or 1). Byte: A group of 8 bits. One character. Word: The width of a memory cell. Each byte of main memory has an address. All numbers are represented in binary.**Integer numbers**• NOTE: The following number representations are simplified. They do not represent the actual pattern inside most computers. All numbers are converted in binary: ex: 9 = 1001 In a computer system, the leftmost bit is the sign bit (0 is positive, 1 is negative). So 9 in a 32 bit system would be: 00000000000000000000000000001001**Real numbers**Real numbers in binary are expressed with a mantissa, a base and an exponent. For a real number , the mantissa is defined as the positivefractional part Suppose 9.0 in binary: In 32 bits a simple view is bit sign=0 base and exponent=16 (base=2, exponent=4). mantissa=9/16=0.5625 for 32 bit float number (8: exp, 23 mantissa): 0 00000100 10010000000000000000000**32 bit real number**• 1: 0 00000001 10000000000000000000000 • 2: 0 00000010 10000000000000000000000 • 3: 0 00000010 11000000000000000000000 • 4: 0 00000011 10000000000000000000000 • 5: 0 00000011 10100000000000000000000 • 6: 0 00000011 11000000000000000000000 • 7: 0 00000011 11100000000000000000000 • 8: 0 00000100 10000000000000000000000 • 9: 0 00000100 10010000000000000000000**32 bit real number cont’d**• 10:000000100 10100000000000000000000 • 11:0 0000010010110000000000000000000 • 12:0 0000010011000000000000000000000 • 13:0 0000010011010000000000000000000 • 14:0 0000010011100000000000000000000 • 15:0 0000010011110000000000000000000 • 16:0 000010001000000000000000000000**Real numbers**A double number is expressed in 64 bits: 52 bits for the mantissa, 11 bits for the exponent and 1 sign bit. Exponent: right to left, like an integer. Mantissa: left to right, 0.5, 0.25, 0.125, 0.0625,... and so on. 1 if needed, 0 if not. So 9.0 is: • 0000000001001001000000000000000000000000000000000000000000000000**Characters**Characters are expressed using the ASCII code: A = 65 = 01000001 g = 103 = 01100111 $ = 36 = 00100100 + = 43 = 00101011 See code here: http://www.asciitable.com/**Programming Languages**Generation 1: Machine languages (pure binary) 101011101010101010111010101011 Generation 2: Assembly languages (mnemonic codes) MV R1,R3 Generation 3: High-Level Languages (C, Fortran, Java)**Solving Problems**1. Define the problem 2. Analyse the problem. 3. Design a solution. 4. Implement the solution. 5. Test the program. 6. Update and maintain the program.**Implementation**Here is a detail of step #4, implementation (actual programming): 4.1 Write the program source. 4.2 Compile the source code and check for errors. 4.3 Link the code with libraries and build the program. 4.4 Run the program.**Why C?**1. It is portable. 2. It is efficient. 3. It is easy to learn. 4. It is modular. 5. It is widespread.**Summary**• Computer • algorithm • Computer Components • Binary number system • Software Development Method • problem solving