C++ for Everyone - Chapter One Introduction PDF

Summary

This document is a chapter on introduction and is part of a larger book titled C++ for Everyone written by Cay Horstmann from 2012 published by John Wiley & Sons. It's about the basics of computer programming and the C++ language. It explains programming, computer architecture, components of a computer, and the process of translating high-level languages to machine code.

Full Transcript

Chapter One: Introduction C++ for Everyone by Cay Horstmann Slides by Evan Gallagher Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Goals To learn about the architecture of computers To learn about machine languages a...

Chapter One: Introduction C++ for Everyone by Cay Horstmann Slides by Evan Gallagher Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Goals To learn about the architecture of computers To learn about machine languages and higher-level programming languages To become familiar with your compiler To compile and run your first C++ program To recognize compile-time and run-time errors To describe an algorithm with pseudocode To understand the activity of programming C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is Programming? You have probably used a computer for work or fun. Many people use computers for everyday tasks such as electronic banking or writing a term paper. Computers are good for such tasks. They can handle repetitive chores, such as totaling up numbers or placing words on a page, without getting bored or exhausted. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is Programming? Computers can carry out a wide range of tasks because they execute different programs, each of which directs the computer to work on a specific task. The computer itself is a machine that stores data (numbers, words, pictures), interacts with devices (the monitor, the sound system, the printer), and executes programs. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is Programming? A computer program tells a computer, in minute detail, the sequence of steps that are needed to fulfill a task. Hardware The physical computer and peripheral devices are collectively called the hardware. Software The programs the computer executes are called the software. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is Programming? Programming is the act of designing and implementing computer programs. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Anatomy of a Computer – The CPU The CPU (central processing unit) – heart of the computer – executes one operation at a time – performs program control and data processing C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Anatomy of a Computer – The CPU The CPU – carries out arithmetic operations such as addition, subtraction, multiplication, and division – fetches data from external memory or devices and stores data back. All data must travel through the CPU whenever it is moved from one location to another. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Anatomy of a Computer – The CPU The computer stores data and programs in memory – Primary memory - memory chips Random access memory (RAM) (read-write memory) Read-only memory (ROM) – Secondary storage devices disk drives CDs C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Anatomy of a Computer – Peripheral Devices The user is the human using a program that a programmer wrote. The computer transmits information (called output) to the user through a display screen, speakers, and printers. The user can enter information (called input) for the computer by using a keyboard or a pointing device such as a mouse. squeak? C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Anatomy of a Computer – Schematic Design C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is a Computer? Yes, ALL that is ONE computer! (except the people) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is a Computer? The Electronic Numerical Integrator And Computer (The ENIAC) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Machine Code and Programming Languages Computer programs are stored as machine instructions in a code that depends on the processor type. A typical sequence of machine instructions is – 1. Move the contents of memory location 40000 into the CPU. – 2. If that value is > 100, continue with the instruction that is stored in memory location 11280. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Machine Code and Programming Languages Machine instructions are encoded as numbers so that they can be stored in memory. On a Pentium processor, this sequence of instructions from the previous slide is encoded as the sequence of numbers 161 40000 45 100 127 11280 On a processor from a different manufacturer, the encoding would be different. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved High-Level Languages and the Compiler High-level languages like C++ are independent of the processor type and hardware. They will work equally well: – on an Intel Pentium and a processor – in a cell phone The compiler – a special computer program, that translates the higher-level description (a program) into machine instructions for a particular processor. Low-level language: the machine code for a specific CPU – the compiler-generated machine instructions are different, but the programmer who uses the compiler need not worry about these differences. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Evolution of C++ Ancient history (pre 1972) C (1972) ANSI Standard C (1989) Meanwhile, Bjarne Stroustrup of AT&T adds features of the language Simula (an object-oriented language designed for carrying out simulations) to C resulting in: C++ (1985) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Evolution of C++ Ancient history (pre 1972) C (1972) ANSI Standard C (1989) Meanwhile, Bjarne Stroustrup of AT&T adds features of the language Simula (an object-oriented language designed for carrying out simulations) to C resulting in: C++ (1985) ANSI Standard C++ (1998) ANSI Standard C++ [revised] (2003) The present C++ – a general-purpose language that is in widespread use for systems and embedded – the most commonly used language for developing system software such as databases and operating systems … the future: another Standard (2010?) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment You will need to know how to log in (if needed), and, how to start your C++ development environment. An IDE (integrated development environment) is where you will most likely work. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment You will become a typist because you will use an editor to type your C++ programs into the IDE. Your program is called a source file. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment You will need to learn how to compile and run your program in the IDE. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment There’s a lot going on behind the scenes in the IDE that you don’t normally see: C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment The compiler translates C++ programs into machine code. The linker combines machine code with library code into an executable program. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved The Edit-Compile-Run Loop This process reflects the way programmers work (shown as a flowchart) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment You will need to know your computer’s file system: files, folders, and extensions. C++ program files typically have the extension:.cpp (or.cc or.cxx or even.C). You should be organized by creating folders for organizing your files. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment and you MUST know: 1. HOW TO BACK UP YOUR WORK. 2. HOW TO SAVE YOUR WORK (same thing as backing up your work). 3. HOW TO SAVE YOUR WORK BY BACKING IT UP (repeated so you will know this is very important). C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment And, finally… C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Becoming Familiar with Your Programming Environment Back up your work C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Analyzing Your First Program C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Analyzing Your First Program At this point we will analyze the classic first program that everyone writes: Hello World! – (yes, everyone who is anyone started with this one) Its job is to write the words Hello World! on the screen. ch01/hello.cpp 1 #include 2 3 using namespace std; 4 5 int main() 6 { 7 cout

Use Quizgecko on...
Browser
Browser