Home Page

Chapter 1: Basic C++ Programming

Cell

The first digital computer, ENIAC, did not use any data structures to speak of. Its primary function was to quickly perform long sequences of mathematical calculations at speeds that were truly remarkable for its time. As important an achievement as this was, the major impact of ENIAC is not in the actual calculations it performed, but in the computational era it ushered in.

Computers are utilized today in myriad different ways. For consumers, computers provide real-time control of washing machines, automobiles, and ovens. For scientists and engineers, computers are used to design new airplanes, to model complex molecules, and to simulate galaxies. And computers are essential for modern-day commerce, as they are employed to perform most financial transactions and to facilitate a host of different modes of communication, including the Internet. Indeed, we have come a long way since 1945 when ENIAC was first built.

Modern computers routinely have memory capacities that are tens of millions of times larger than ENIAC ever had, and memory capacities continue to grow at astonishing rates. This growth in capacity has brought with it a new and exciting role for computers. Rather than simply being fast calculators, modern computers are information processors. They store, analyze, search, transfer, and update huge collections of complex data. Quickly performing these tasks requires that data be well organized and that the methods for accessing and maintaining data be fast and efficient. In short, modern computers need good data structures and algorithms.

Specifying these data structures and algorithms requires that we communicate instructions to a computer, and an excellent way to perform such communication is using a high-level computer language, such as C++, which is the programming language we use in this book. C++ evolved from the programming language C, and has, over time, undergone further evolution and development from its original definition. It has incorporated many features that were not part of C, such as symbolic constants, in-line function substitution, reference types, parametric polymorphism through templates, and exceptions (which will all be discussed later in the book). As a result, C++ has grown to be a complex programming language. Fortunately, we do not need to know every detail of the language in order to use it effectively. The specific topics of the C++ language we focus on in this chapter are those that are directly related to the implementation of data structures and algorithms, including the following:

  • Basic C++ Programming Elements, including
    • Fundamental Types
    • Pointers, Arrays, and Structures
    • Scope and Namespaces
  • Expressions and Casting
  • Control Flow
  • Functions
  • Classes, including
    • Class Structure
    • Constructors and Destructors
    • Classes and Memory Allocation
    • Class Friends and Class Members
    • The Standard Template Library
  • C++ Program and File Organization

Related topics including virtual functions, derived classes and inheritance, templates, and exceptions are covered in Chapter 2.