Chapter 1 - An Overview of Computers and Programming Languages.ppt
Document Details
Uploaded by Deleted User
Full Transcript
Chapter 1: An Overview of Computers and Programming Languages Objectives In this chapter, you will: – Learn about different types of computers – Explore hardware and software – Learn about the language of a computer – Learn about the ev...
Chapter 1: An Overview of Computers and Programming Languages Objectives In this chapter, you will: – Learn about different types of computers – Explore hardware and software – Learn about the language of a computer – Learn about the evolution of programming languages – Examine high-level programming languages C++ Programming: Program Design Including Data Structures, Sixth Edition 2 Objectives (cont’d.) – Discover what a compiler is and what it does – Examine a C++ program – Explore how a C++ program is processed – Learn what an algorithm is and explore problem-solving techniques – Become aware of structured design and object- oriented design programming methodologies – Become aware of Standard C++ and ANSI/ISO Standard C++ C++ Programming: Program Design Including Data Structures, Sixth Edition 3 Introduction Without software, the computer is useless Software is developed with programming languages – C++ is a programming language C++ suited for a wide variety of programming tasks C++ Programming: Program Design Including Data Structures, Sixth Edition 4 Introduction Examples of Programming Languages C++ Programming: Program Design Including Data Structures, Sixth Edition 5 A Brief Overview of the History of Computers Early calculation devices – Abacus, Pascaline – Leibniz device – Jacquard’s weaving looms – Babbage machines: difference and analytic engines – Hollerith machine C++ Programming: Program Design Including Data Structures, Sixth Edition 6 A Brief Overview of the History of Computers (cont’d.) An abacus is a calculation tool used by sliding counters along rods or grooves, used to perform mathematical functions. C++ Programming: Program Design Including Data Structures, Sixth Edition 7 A Brief Overview of the History of Computers (cont’d.) A Leibniz device, or Stepped Reckoner, is a mechanical calculator invented by Gottfried Wilhelm Leibniz in the 17th century. It could perform addition, subtraction, multiplication, and division using a stepped drum mechanism. C++ Programming: Program Design Including Data Structures, Sixth Edition 8 A Brief Overview of the History of Computers (cont’d.) Jacquard's loom is a mechanical loom that used punched cards to control the weaving of complex patterns automatically. The punched cards dictated the pattern by controlling the movement of the loom's threads. C++ Programming: Program Design Including Data Structures, Sixth Edition 9 A Brief Overview of the History of Computers (cont’d.) Early computer – like machines - Mark I - ENIAC - UNIVAC - Von-Neumann Architecture C++ Programming: Program Design Including Data Structures, Sixth Edition 10 A Brief Overview of the History of Computers (cont’d.) The Mark I, was one of the first large-scale automatic digital computers. It was a massive electromechanical machine, over 50 feet long and consisting of thousands of components like switches, relays, and rotating shafts. C++ Programming: Program Design Including Data Structures, Sixth Edition 11 A Brief Overview of the History of Computers (cont’d.) UNIVAC (Universal Automatic Computer) was the first commercially produced digital computer in the United States. UNIVAC's introduction marked the beginning of the commercial computing era. C++ Programming: Program Design Including Data Structures, Sixth Edition 12 A Brief Overview of the History of Computers (cont’d.) The Von Neumann architecture. It describes a system where a computer's memory stores both data and program instructions, allowing the CPU (Central Processing Unit) to fetch and execute instructions sequentially. C++ Programming: Program Design Including Data Structures, Sixth Edition 13 A Brief Overview of the History of Computers (cont’d.) This architecture includes four key components: - Central Processing Unit (CPU): Performs calculations and executes instructions. - Memory: Stores data and instructions. - Input/Output Devices: Allow communication with the outside world. - Control Unit: Directs the operations of the CPU and memory. C++ Programming: Program Design Including Data Structures, Sixth Edition 14 A Brief Overview of the History of Computers (cont’d.) Categories of computers –Mainframe computers –Midsize computers –Micro computers (personal computers) C++ Programming: Program Design Including Data Structures, Sixth Edition 15 Elements of a Computer System Hardware CPU Main memory Secondary storage Input/Output devices Software C++ Programming: Program Design Including Data Structures, Sixth Edition 16 Central Processing Unit and Main Memory Central processing unit – Brain of the computer – Most expensive piece of hardware – Carries out arithmetic and logical operations C++ Programming: Program Design Including Data Structures, Sixth Edition 17 Central Processing Unit and Main Memory (cont’d.) C++ Programming: Program Design Including Data Structures, Sixth Edition 18 Central Processing Unit and Main Memory (cont’d.) Random access memory – Directly connected to the CPU All programs must be loaded into main memory before they can be executed All data must be brought into main memory before it can be manipulated When computer power is turned off, everything in main memory is lost C++ Programming: Program Design Including Data Structures, Sixth Edition 19 KEY POINTS 1. Direct Connection to the CPU: RAM is directly connected to the CPU, allowing for rapid data access. The speed of RAM is critical because it significantly impacts the performance of the CPU and, by extension, the entire computer. C++ Programming: Program Design Including Data Structures, Sixth Edition 20 KEY POINTS 2. Programs Must Be Loaded into Main Memory (RAM): Before the CPU can execute any program, that program must be loaded into RAM. This is because RAM provides the CPU with quick access to the instructions and data that the program needs to run. C++ Programming: Program Design Including Data Structures, Sixth Edition 21 KEY POINTS 3. Data Must Be Brought into Main Memory for Manipulation: Similarly, any data that needs to be processed by the CPU must first be brought into RAM. This ensures that the CPU can access and manipulate the data quickly and efficiently, which is essential for smooth computer operation. C++ Programming: Program Design Including Data Structures, Sixth Edition 22 KEY POINTS 4. Volatile Nature of RAM: One of the critical characteristics of RAM is that it is volatile. When the computer is powered off, all data stored in RAM is lost. This is why it’s essential to save any work to non-volatile storage (like a hard drive or SSD) before shutting down the computer. C++ Programming: Program Design Including Data Structures, Sixth Edition 23 Central Processing Unit and Main Memory (cont’d.) Main memory is an ordered sequence of memory cells – Each cell has a unique location in main memory, called the address of the cell Each cell can contain either a programming instruction or data C++ Programming: Program Design Including Data Structures, Sixth Edition 24 Secondary Storage Secondary storage: device that stores information permanently Examples of secondary storage: – Hard disks – Flash drives – Floppy disks – Zip disks – CD-ROMs – Tapes C++ Programming: Program Design Including Data Structures, Sixth Edition 25 Input/Output Devices Input devices feed data and programs into computers – Keyboard – Mouse – Secondary storage Output devices display results – Monitor – Printer – Secondary storage C++ Programming: Program Design Including Data Structures, Sixth Edition 26 Software Software: programs that do specific tasks System programs control the computer – Operating system monitors the overall activity of the computer and provides services such as: Memory management Input/output activities Storage management Application programs perform a specific task – Word processors – Spreadsheets – Games C++ Programming: Program Design Including Data Structures, Sixth Edition 27 The Language of a Computer Analog signals: continuous wave forms used to represent such things as sound. Digital signals: sequences of 0s and 1s, A 0 represents a low voltage, and a 1 represents a high voltage. Machine language: language of a computer; a sequence of 0s and 1s Binary digit (bit): the digit 0 or 1 Binary code (binary number): a sequence of 0s and 1s C++ Programming: Program Design Including Data Structures, Sixth Edition 28 The Language of a Computer (cont’d.) Byte: – A sequence of eight bits Kilobyte (KB): 210 bytes = 1024 bytes ASCII (American Standard Code for Information Interchange) – 128 characters – A is encoded as 1000001 (66th character) – 3 is encoded as 0110011 C++ Programming: Program Design Including Data Structures, Sixth Edition 29 The Language of a Computer (cont’d.) Bits are the building blocks of digital communication and data storage. Binary numbers are used to represent everything in a computer, from data to instructions. - For example, the binary code 1010 might represent the decimal number 10 or an instruction depending on its context. C++ Programming: Program Design Including Data Structures, Sixth Edition 30 C++ Programming: Program Design Including Data Structures, Sixth Edition 31 The Language of a Computer (cont’d.) EBCDIC (Extended Binary Coded Decimal Interchange Code): – Used by IBM – 256 characters Unicode – 65536 characters – Two bytes are needed to store a character C++ Programming: Program Design Including Data Structures, Sixth Edition 32 The Evolution of Programming Languages Early computers were programmed in machine language To calculate wages = rate * hours in machine language: 100100 010001 //Load 100110 010010 //Multiply 100010 010011 //Store C++ Programming: Program Design Including Data Structures, Sixth Edition 33 The Evolution of Programming Languages (cont’d.) Assembly language instructions are mnemonic Assembler: translates a program written in assembly language into machine language C++ Programming: Program Design Including Data Structures, Sixth Edition 34 The Evolution of Programming Languages (cont’d.) Using assembly language instructions, wages = rate hours can be written as: LOAD rate MULT hour STOR wages C++ Programming: Program Design Including Data Structures, Sixth Edition 35 Example code in Assembly C++ Programming: Program Design Including Data Structures, Sixth Edition 36 The Evolution of Programming Languages (cont’d.) High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java Compiler: translates a program written in a high-level language into machine language The equation wages = rate hours can be written in C++ as: wages = rate * hours; C++ Programming: Program Design Including Data Structures, Sixth Edition 37 Processing a C++ Program #include using namespace std; int main() { cout