ch01.pdf
Document Details
Full Transcript
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Objectives In this chapter, you will: Learn about different types of comp...
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Objectives In this chapter, you will: Learn about different types of computers Explore the hardware and software components of a computer system Learn about the language of a computer Learn about the evolution of programming languages Examine high-level programming languages C++ Programming: From Problem Analysis to Program Design, Fifth 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: From Problem Analysis to Program Design, Fifth Edition 3 Introduction Without software, the computer is useless Software developed with programming languages – C++ is a programming language C++ suited for a wide variety of programming tasks Before programming, it is useful to understand terminology and computer components C++ Programming: From Problem Analysis to Program Design, Fifth Edition 4 A Brief Overview of the History of Computers Early calculation devices – Abacus, Pascaline – Leibniz device – Babbage machines: difference and analytic engines – Hollerith machine C++ Programming: From Problem Analysis to Program Design, Fifth Edition 5 A Brief Overview of the History of Computers (cont'd.) Early computer-like machines – Mark I – ENIAC – Von Neumann architecture – UNIVAC – Transistors and microprocessors C++ Programming: From Problem Analysis to Program Design, Fifth Edition 6 A Brief Overview of the History of Computers (cont'd.) Categories of computers – Mainframe computers – Midsize computers – Micro computers (personal computers) C++ Programming: From Problem Analysis to Program Design, Fifth Edition 7 Elements of a Computer System Hardware CPU Main memory Secondary storage Input/Output devices Software C++ Programming: From Problem Analysis to Program Design, Fifth Edition 8 Hardware CPU Main memory: RAM Input/output devices Secondary storage C++ Programming: From Problem Analysis to Program Design, Fifth Edition 9 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: From Problem Analysis to Program Design, Fifth Edition 10 Central Processing Unit and Main Memory (cont'd.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition 11 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: From Problem Analysis to Program Design, Fifth Edition 12 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: From Problem Analysis to Program Design, Fifth Edition 13 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: From Problem Analysis to Program Design, Fifth Edition 14 Software Software: programs that do specific tasks System programs take control of the computer, such as an operating system Application programs perform a specific task – Word processors – Spreadsheets – Games C++ Programming: From Problem Analysis to Program Design, Fifth Edition 15 The Language of a Computer Digital signals: sequences of 0s and 1s Machine language: language of a computer Binary digit (bit): – The digit 0 or 1 Binary code: – A sequence of 0s and 1s Byte: – A sequence of eight bits C++ Programming: From Problem Analysis to Program Design, Fifth Edition 16 The Language of a Computer (cont’d.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition 17 The Language of a Computer (cont'd.) ASCII (American Standard Code for Information Interchange) – 128 characters – A is encoded as 1000001 (66th character) – 3 is encoded as 0110011 C++ Programming: From Problem Analysis to Program Design, Fifth Edition 18 The Language of a Computer (cont'd.) EBCDIC – Used by IBM – 256 characters Unicode – 65536 characters – Two bytes are needed to store a character C++ Programming: From Problem Analysis to Program Design, Fifth Edition 19 The Evolution of Programming Languages Early computers were programmed in machine language To calculate wages = rates * hours in machine language: 100100 010001 //Load 100110 010010 //Multiply 100010 010011 //Store C++ Programming: From Problem Analysis to Program Design, Fifth Edition 20 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: From Problem Analysis to Program Design, Fifth Edition 21 The Evolution of Programming Languages (cont'd.) Using assembly language instructions, wages = rates hours can be written as: LOAD rate MULT hour STOR wages C++ Programming: From Problem Analysis to Program Design, Fifth Edition 22 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 machine language The equation wages = rate hours can be written in C++ as: wages = rate * hours; C++ Programming: From Problem Analysis to Program Design, Fifth Edition 23 Processing a C++ Program #include using namespace std; int main() { cout