Full Transcript

CSBP119 Algorithms & Problem Solving CIT, UAEU CHAPTER 1 Introduction to Computers and Programming Copyright © 2018 Pearson Education, Ltd. ...

CSBP119 Algorithms & Problem Solving CIT, UAEU CHAPTER 1 Introduction to Computers and Programming Copyright © 2018 Pearson Education, Ltd. Topics Introduction Hardware and Software How Computers Store Data How a Program Works Using Python Copyright © 2018 Pearson Education, Ltd. Introduction Computers can be programmed Designed to do any job that a program tells them to Program: set of instructions that a computer follows to perform a task (e.g., Microsoft Word and PowerPoint) Commonly referred to as Software Programmer: person who can design, create, and test computer programs Also known as software developer Copyright © 2018 Pearson Education, Ltd. Hardware and Software Hardware: The physical devices that make up a computer Computer is a system composed of several components that all work together Typical major components: Central processing unit (CPU) Main memory Secondary storage devices Input and output devices Copyright © 2018 Pearson Education, Ltd. Hardware and Software https://www.youtube.com/watch?v=HB4I2CgkcC o&ab_channel=LearnFree Copyright © 2018 Pearson Education, Ltd. The CPU Central processing unit (CPU): the part of the computer that actually runs programs Most important component Without it, cannot run software Microprocessors: CPUs located on small chips Copyright © 2018 Pearson Education, Ltd. The CPU The ENIAC Computer Modern microprocessor Copyright © 2018 Pearson Education, Ltd. Main Memory Main memory: where computer stores a program while program is running, and data used by the program Known as Random Access Memory or RAM CPU is able to quickly access data in RAM Volatile memory used for temporary storage while program is running Contents are erased when computer is off Copyright © 2018 Pearson Education, Ltd. Secondary Storage Devices Secondary storage: can hold data for long periods of time, even when there is no power to the computer Programs normally stored here and loaded to main memory when needed Types of secondary memory: Hard Disk drive (HDD): magnetically encodes data onto a spinning circular disk Solid state drive (SSD): faster than disk drive, no moving parts, stores data in solid state memory Flash memory: portable, no physical disk Optical devices: data encoded optically Copyright © 2018 Pearson Education, Ltd. Input Devices Input: data the computer collects from people and other devices Input device: component that collects the data Examples: keyboard, mouse, touchscreen, scanner, camera Copyright © 2018 Pearson Education, Ltd. Output Devices Output: data produced by the computer for other people or devices Can be text, image, audio, or bit stream Output device: formats and presents output Examples: video display, printer Copyright © 2018 Pearson Education, Ltd. Software Everything the computer does is controlled by software General categories: Application software System software (operating systems, utility programs such as virus scanners and data backup programs) Application software: programs that make computer useful for everyday tasks Examples: word processing, email, games, and Web browsers. Copyright © 2018 Pearson Education, Ltd. How Computers Store Data All data in a computer is stored in sequences of 0s and 1s Byte: just enough memory to store letter or small number – Divided into eight bits – Bit: electrical component that can hold positive or negative charge, like on/off switch – The on/off pattern of bits in One bite a byte represents data stored in the byte One byte Copyright © 2018 Pearson Education, Ltd. Storing Numbers Bit represents two values, 0 and 1 Computers use binary numbering system Position of digit j is assigned the value 2j-1 To determine value of binary number sum position values of the 1s Byte size limits are 0 and 255 0 = all bits off; 255 = all bits on To store larger number, use several bytes Copyright © 2018 Pearson Education, Ltd. Storing Characters Data stored in computer must be stored as binary number Characters are converted to numeric code, numeric code stored in memory Most important coding scheme is ASCII ASCII is limited: defines codes for only 128 characters Unicode coding scheme becoming standard Compatible with ASCII Can represent characters for other languages Copyright © 2018 Pearson Education, Ltd. How a Program Works CPU designed to perform simple operations on pieces of data Examples: reading data, adding, subtracting, multiplying, and dividing numbers Understands instructions written in machine language and included in its instruction set Each brand of CPU has its own instruction set To carry out meaningful calculation, CPU must perform many operations Copyright © 2018 Pearson Education, Ltd. How a Program Works (cont’d.) Program must be copied from secondary memory to RAM each time CPU executes it CPU executes program in cycle: – Fetch: read the next instruction from memory into CPU – Decode: CPU decodes fetched instruction to determine which operation to perform – Execute: perform the operation Copyright © 2018 Pearson Education, Ltd. From Machine Language to Assembly Language Impractical for people to write in machine language Assembly language: uses short words (mnemonics) for instructions instead of binary numbers Easier for programmers to work with Assembler: translates assembly language to machine language for execution by CPU Copyright © 2018 Pearson Education, Ltd. High-Level Languages Low-level language: close in nature to machine language Example: assembly language High-Level language: allows simple creation of powerful and complex programs No need to know how CPU works or write large number of instructions More intuitive to understand Copyright © 2018 Pearson Education, Ltd. Key Words, Operators, and Syntax: an Overview Key words: predefined words used to write program in high-level language Each key word has specific meaning Operators: perform operations on data Example: math operators to perform arithmetic Syntax: set of rules to be followed when writing program Statement: individual instruction used in high- level language Copyright © 2018 Pearson Education, Ltd. Examples of Key words Copyright © 2018 Pearson Education, Ltd. Compilers and Interpreters Programs written in high-level languages must be translated into machine language to be executed Compiler: translates high-level language program into separate machine language program Machine language program can be executed at any time Copyright © 2018 Pearson Education, Ltd. Compilers and Interpreters (cont’d.) Interpreter: translates and executes instructions in high-level language program Used by Python language Interprets one instruction at a time No separate machine language program Source code: statements written by programmer Syntax error: prevents code from being translated Copyright © 2018 Pearson Education, Ltd. Compilers and Interpreters (cont’d.) Figure 1-19 Executing a high-level program with an interpreter Copyright © 2018 Pearson Education, Ltd. Using Python Python must be installed and configured prior to use One of the items installed is the Python interpreter Python interpreter can be used in two modes: Interactive mode: enter statements on keyboard Script mode: save statements in Python script Copyright © 2018 Pearson Education, Ltd. Interactive Mode When you start Python in interactive mode, you will see a prompt Indicates the interpreter is waiting for a Python statement to be typed Prompt reappears after previous statement is executed Error message displayed If you incorrectly type a statement Good way to learn new parts of Python Copyright © 2018 Pearson Education, Ltd. Writing Python Programs and Running Them in Script Mode Statements entered in interactive mode are not saved as a program To have a program use script mode Save a set of Python statements in a file The filename should have the.py extension To run the file, or script, type python filename at the operating system command line Copyright © 2018 Pearson Education, Ltd. Summary This chapter covered: Main hardware components of the computer Types of software How data is stored in a computer Basic CPU operations and machine language Fetch-decode-execute cycle Complex languages and their translation to machine code Installing Python and the Python interpreter modes Copyright © 2018 Pearson Education, Ltd.

Use Quizgecko on...
Browser
Browser