Lesson 1b: Computer Systems and Program Development CPS118
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.planecell phone Meet me outside baggage claim.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/ /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
Components of a Computer
Computer Components Central Processing Unit Main Memory ALUCU CD zip disk floppy disk Secondary Storage: mouse monitor keyboard hard disk printer scanner Input & Output Devices
Computer System CPU + Main Memory ~ “core” Secondary Storage + I/O Devices ~ “peripherals” Bus ~ communication between components CP U Sec. Storage I/O 1 I/O 2 I/O n Memo ry Bus
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:
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 positive fractional partreal numberpositivefractional 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= for 32 bit float number (8: exp, 23 mantissa):
32 bit real number 1: : : : : : : : :
32 bit real number cont’d 10: : : : : : :
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, ,... and so on. 1 if needed, 0 if not. So 9.0 is:
Characters Characters are expressed using the ASCII code: A =65 = g =103= $ =36 = =43= See code here:
Programming Languages Generation 1: Machine languages (pure binary) 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
End of lesson