Computer Programming in C++

Chapter 1: Introduction to Computers and C++ Programming

1.1 Computer Systems

  • Computer Program: A set of instructions for a computer to follow.

  • Computer Software: The collection of programs used by a computer.

    • Includes editors, translators, and system managers.

Hardware
  • Three Main Classes of Computers:

    • PCs (Personal Computer): Relatively small, used by one person at a time.

    • Workstation: Larger and more powerful than a PC, typically for specialized tasks.

    • Mainframe: Still larger, requires support staff, and is shared by multiple users.

Networks
  • A number of computers connected to share resources.

  • Purpose: Share printers and other devices, share information.

Computer Organization
  • Five Main Components (Display 1.1):

    • Input devices: Allow communication to the computer (e.g., keyboard, mouse).

    • Output devices: Allow communication to the user (e.g., monitor, printer).

    • Processor (CPU): The central processing unit that executes instructions.

    • Main memory: Memory locations containing the running program; temporary storage.

    • Secondary memory: Permanent record of data, often stored on a disk.

Computer Memory
  • Main Memory:

    • A long list of memory locations.

    • Each location contains zeros and ones (binary digits).

    • Content can change during program execution.

  • Binary Digit or Bit: A digit that can only be 00 or 11.

  • Byte: Each memory location typically has eight bits.

  • Address: A number that uniquely identifies a memory location.

Larger Data Items
  • Some data (e.g., most integers and real numbers) is too large for a single byte.

  • The address refers to the first byte of a multi-byte data item.

  • The next few consecutive bytes store the additional bits for the larger data (Display 1.2).

Data or Code?
  • A sequence of bits like 0100000101000001 can represent different things (e.g., letter 'A', number 6565, or an instruction).

  • The computer's interpretation of a bit sequence depends on the current instruction being executed.

  • Programmers typically don't need to be concerned with this detail, as they reason as if memory locations contain letters and numbers.

Secondary Memory
  • Main memory: Stores instructions and data while a program is running.

  • Secondary memory: Stores instructions and data between sessions (non-volatile storage).

  • File: A collection of data or instructions stored in secondary memory.

Secondary Memory Media
  • Hard disk:

    • Fast access speed.

    • Fixed inside the computer and not normally removed.

  • Floppy disk:

    • Slow access speed.

    • Easily shared with other computers.

  • Compact disk (CD):

    • Slower than hard disks.

    • Easily shared with other computers.

    • Can be read-only (CD-ROM) or re-writable (CD-RW).

Memory Access
  • Random Access (RAM):

    • The computer can directly access any memory location instantaneously.

    • Usually called RAM.

  • Sequential Access:

    • Data is generally found by searching through other items first.

    • More common in secondary memory (e.g., magnetic tape, though less common today).

The Processor (CPU)
  • Central Processing Unit (CPU).

  • Follows program instructions.

  • Typical capabilities:

    • Basic arithmetic operations (add, subtract, multiply, divide).

    • Moving data from one location to another.

Computer Software: The Operating System
  • Allows users to communicate with the computer.

  • Is itself a program.

  • Allocates the computer's resources (e.g., CPU time, memory).

  • Responds to user requests to run other programs.

  • Common Operating Systems (OS) include UNIX, Linux, DOS, Windows, Macintosh, and VMS.

Computer Input
  • Computer input primarily consists of a program and some data (Display 1.3).

High-level Languages
  • Examples: C, C++, Java, Pascal, Visual Basic, FORTRAN, Perl, PHP, Lisp, Scheme, Ada, C#, Python.

  • Resemble human languages, making them easier to read and write.

  • Use more complicated instructions than the CPU can directly follow.

  • Must be translated into machine language (zeros and ones) for the CPU to execute a program.

Low-level Languages
  • Assembly Language:

    • A step above machine code but still hardware-specific.

    • Commands like ADD,X,Y,Z might mean