Chapter-1-Introduction-to-Computers-and-Programming.pdf

Full Transcript

Chapter 1 Introduction to Computers and Programming This chapter begins by giving a concise and easy-to-understand explanation of how computers work, how data is stored and manipulated, and why we write programs in high-level languages Introduction Hardware How a Program...

Chapter 1 Introduction to Computers and Programming This chapter begins by giving a concise and easy-to-understand explanation of how computers work, how data is stored and manipulated, and why we write programs in high-level languages Introduction Hardware How a Program Works Types of Software How Computers Store Data Introduction People use computers at… School for writing papers, research, email, online classes, etc. Work for analyzing data, make presentations, business transactions, communicating, control machines, etc. Home for paying bills, shopping online, communicating, playing computer games, etc. Computers can do such a wide variety of things because they can be programmed. This means that computers are not designed to do just one job, but to do any job that their programs tell them to do. A program is a set of instructions that a computer follows to perform a task. Figure 1-1 shows screens from two commonly used programs: Microsoft Word and PowerPoint. Programs are commonly referred to as software. Software is essential to a computer because without software, a computer can do nothing. A programmer, or software developer, is a person with the training and skills necessary to design, create, and test computer programs. 1 Hardware CONCEPT: The physical devices that a computer is made of are referred to as the computer’s hardware. Most computer systems are made of similar hardware devices. Hardware refers to all of the physical devices, or components, that a computer is made of. A computer is not one single device, but a system of devices that all work together. Figure 1-2, a typical computer system consists of the following major components: The central processing unit (CPU) Main memory Secondary storage devices Input devices Output devices Central Processing Unit, or CPU, is the part of a computer that actually runs programs. It is the most important component in a computer because without it, the computer could not run software. CPUs were huge devices made of electrical and mechanical components such as vacuum tubes and switches. Figure 1-3 shows such a device. 2 ENIAC - world’s first programmable electronic computer - was built in 1945 to calculate artillery ballistic tables for the U.S. Army. - 8 feet tall, 100 feet long, and weighed 30 tons. Today, CPUs are small chips known as microprocessors. See Figure 1-4. In addition to being much smaller than the old electro-mechanical CPUs in early computers, microprocessors are also much more powerful. Main Memory Considered the computer’s work area Computer stores the program that is running as well as the data Commonly known as the random-access memory (RAM) Data is quickly accessed RAM is a volatile type of memory Used for temporary storage RAM is erased when computer is turned off Inside your computer, RAM is stored in chips, similar to the ones shown in Figure 1-5. Secondary Storage Devices ▪ USB drives are small devices that plug into the computer’s universal serial bus (USB) port It does not contain a disk The data is stored on flash memory Also known as memory sticks and flash drives Inexpensive, reliable, and small ▪ Optical devices (CD or DVD) Data is encoded as a series of pits on the disc’s surface Uses laser to encode the data Holds large amounts of data Good medium for creating backups 3 Input Devices Any data the computer collects from people and from other devices is called input. The hardware component that collects the data is called an input device. Common input devices are: ▪ Keyboard ▪ Mouse ▪ Scanner ▪ Microphone ▪ Digital camera Output Devices Any data the computer produces for people or for other devices is called output. The hardware component that formats and presents the data is called an output device. Common output devices are: ▪ monitor ▪ printer Everything a computer does is controlled by software. ▪ Two categories of software: 1. System software - Programs that control and manage the basic operations of a computer. Includes the following types: Operating System controls the internal operations of the computer’s hardware and manages all of the devices connected to the computer. It acts as the interface with the application program. Utility Programs perform a specialized task that enhances the computer’s operation or safeguards data. In short it manage, maintain and control computer resources. Examples are Anti-Virus Software (An antivirus is a utility software that helps to keep the computer virus-free.), File Management System (These utility software are used to manage files of the computer system. This utility software helps to browse, search, arrange, find information, and quickly preview the files of the system. Ex. Windows Explorer), Compression Tools ( This utility program used to compress big files and decrease their size, these are compression tools. Ex. WinRAR, WinZip, etc.), Disk Management Tools (These utility software are used to manage data on disks. Moreover, they perform functions like partitioning devices and manage drives). Software Developments Tools are programs that are used to create, modify, and test software. NetBeans, Visual Studio Code, GitHub, Chrome Dev Tools, HTML5 builder, Assemblers, compilers, and interpreters are examples of programs that fall into this category etc. 2. Application software - Programs that people normally spend most of their time running on their computers performing everyday tasks. Microsoft Word, a word processing program, and Microsoft PowerPoint, a presentation program. Some other examples of application software are spreadsheet programs, email programs, Web browsers, and game programs. 4 How Computers Store Data CONCEPT: All data that is stored in a computer is converted to sequences of 0s and 1s. A computer’s memory is divided into tiny storage locations known as bytes. One byte represents one number A byte is divided into eight smaller storage locations known as bits (binary digits) Bits are tiny electrical components that can hold either a positive or a negative charge. A positive charge is similar to a switch in the on position A negative charge is similar to a switch in the off position The positive charge or the on position is represented by the digit 1 The negative charge or the off position is represented by the digit 0 This corresponds to the binary numbering system where all numeric values are written as a sequence of 0s and 1s Each digit in a binary number has a value assigned to it To determine the value of a binary number you simply add up the position values of all the 1s. In the binary number 10011101, the position values of the 1s are 1, 4, 8, 16, and 128.This is shown in Figure 1-10. The sum of all of these position values is 157. So, the value of the binary number 10011101 is 157. Figure 1-11 shows how you can picture the number 157 stored in a byte of memory. Each 1 is represented by a bit in the on position, and each 0 is represented by a bit in the off position. 5 Figure 1-11 shows how you can picture the number 157 stored in a byte of memory. Each 1 is represented by a bit in the on position, and each 0 is represented by a bit in the off position. Storing Numbers The largest value that can be stored in a byte with eight bits is 255 Two bytes are used for larger numbers; maximum value is 65535 Storing Characters Characters are stored in the computer’s memory as binary number ASCII (American Standard Code for Information Interchange) is a coding scheme The acronym ASCII is pronounced “askee.” ASCII is a set of 128 numeric codes, ASCII is limited Unicode is an extensive encoding scheme It is compatible with ASCII. It represents characters for many languages in the world. 6 Advanced Number Storage Binary numbering system can be used to represent only integer numbers Negative numbers are encoded using two’s complement Real numbers are encoded using floating-point notation Other Types of Data Digital data is data that is stored in binary A digital device is any device that works with binary data Digital images are composed of tiny dots of color known as pixels (picture elements) Digital sound is broken into small pieces known as samples For example, consider the pictures that you take with your digital camera. These images are composed of tiny dots of color known as pixels. (The term pixel stands for picture element.) In Figure 1-14, each pixel in an image is converted to a numeric code that represents the pixel’s color. The numeric code is stored in memory as a binary number How a Program Works CONCEPT: A computer’s CPU can only understand instructions that are written in machine language. Because people find it very difficult to write entire programs in machine language, other programming languages have been invented. CPU is the most important component in a computer CPU is an electronic device that is designed to do specific things. CPU is designed to perform the following operations: Read a piece of data from main memory Adding two numbers Subtracting one number from another number Multiplying two numbers Dividing one number by another number Moving a piece of data from one memory location to another Determining whether one value is equal to another value CPU only understands instructions written in machine language Machine language instructions are written in 1s and 0s The entire set of instructions that a CPU can execute is known as the CPU’s instruction set Each brand of microprocessors (Intel, AMD, and Motorola) has a unique instruction set 7 Fetch-decode-execute cycle is the term used when the CPU executes the instructions in a program. The cycle consist of three steps: 1. Fetch - A program is a long sequence of machine language instructions. The first step of the cycle is to fetch, or read, the next instruction from memory into the CPU. 2. Decode - A machine language instruction is a binary number that represents a command that tells the CPU to perform an operation. In this step the CPU decodes the instruction that was just fetched from memory, to determine which operation it should perform. 3. Execute - The last step in the cycle is to execute, or perform, the operation. From Machine Language to Assembly Language Computers only understand machine language Machine language is difficult to write Assembly language uses short words that are known as mnemonics Assembler is used to translate an assembly language program to machine language The first assembly language was most likely developed in the 1940s at Cambridge University for use with a historical computer known as the EDSAC. Assembly language programs cannot be executed by the CPU, however. The CPU only understands machine language, so a special program known as an assembler is used to translate an assembly language program to a machine language program. This process is shown in Figure 1-17. The machine language program that is created by the assembler can then be executed by the CPU. 8 High-Level Languages Assembly language is referred to as a low-level language High-level languages allow you to create powerful and complex programs without knowing how the CPU works, using words that are easy to understand. For example: Java, C++, Python, Visual Basic, C#, Ada, Fortran Key Words, Operators, and Syntax: an Overview Keywords or reserved words have specific meaning and purpose in the programming language Operators perform various operations on data Syntax is a set of rules that must be strictly followed when writing a program Statements are individual instructions written in a programming language Compilers and Interpreters The statements written in a high-level language are called source code or simply code Source code is translated to machine language using a compiler or an interpreter Syntax error is a mistake such as a: Misspelled word Missing punctuation character Incorrect use of an operator Compiler is a program that translates a high-level language program into a separate machine language program. Figure 1-18. As shown in the figure, compiling and executing are two different processes. An interpreter is a program that both translates and executes the instructions in a high-level language program. NOTE: Programs that are compiled generally execute faster than programs that are interpreted because a compiled program is already translated entirely to machine language when it is executed. A program that is interpreted must be translated at the time it is executed. 9 10

Use Quizgecko on...
Browser
Browser