[N.A.B.G. picture] [ABC cover]

This page contains information concerning a draft version of a book "A Beginners' C++"; this book is intended for "CS1, CS2" introductory Computer Science courses that use C++ as an implementation language.

Note: this text was completed in 1996. C++ has been revised quite a bit since then! When the examples were written, C++'s "namespace" feature had been defined but was not supported on available compilers; so the examples don't use namespace. (Of course, in modern C++ they should.)
Further, the iostream library has been updated. Some of the functions have changed their signatures; some features have been added, others removed.
So, be cautious with the code - it is well a little out of date.

A Beginners C++

The table of contents given below includes links to additional materials. Some complete chapters, and various subsections, are available either as Postscript files or directly readable "html" text. There are also links to a couple of files with example code. The code should be usable with the Borland development environment for the PC, or Symantec-8 for the Macintosh.

To save space and transmission time, many of the Postscript files have been compressed. The files were compressed using gzip on Unix. You have to uncompress them (gunzip) before viewing them with ghostview or sending to a printer. (If you go to Javaworld you will usually find that they have dowloadable copies of gzip utilities for both Mac and PC available on their page. The links are at the bottom after their stories about Java developments.) (If you need a viewer for postscript, try: University Wisconsin, ghostscript, ghostview, gs page )

The postscript files have been "distilled" into Adobe PDF files. This makes them smaller, and so easier to download; it should also make them easier to read on a variety of systems.


(PDF of table of contents)

    Part 1 Introduction to Computers

  1. Computer Hardware
    (Postscript file of Computer Hardware Chapter)
    1. CPU and instructions
    2. Memory and Data
    3. Bus
    4. Peripherals
    5. Disks and tapes
    6. Other I/O devices
    (PDF of chapter 1)
  2. Programs: Instructions in the Computer
  3. (PDF of chapter)
    1. Programming with bits!
    2. Loaders
    3. Assemblers
    4. Coding in assembly language
    5. From Assembly Language to "High Level" languages
  4. Operating Systems
    (Postscript file of Operating Systems chapter)
    1. Origins of "Operating Systems"
    2. Development of Operating Systems: Multiprogramming* Timesharing* File Management* Virtual Memory* "Spooling"* Late 1960s early 1970s system* Networking*
    3. Modern systems: UNIX* Macintosh OS*
    (PDF of chapter)
  5. Why have "high-level" languages? (Postscript file of chapter)
    1. Limitations of Assembly Language and Origins of High Level Languages
    2. High level languages constructs: Statements* Data types and structures*
    3. Evolution of high level languages
    4. FORTRAN
    5. BASIC
    6. Lisp
    7. COBOL
    8. ALGOL
    9. The "Algol Family":AlgolW, Pascal, and Modula2* ADA* BCPL, C, and C++* Simula, SmallTalk, and Eiffel*
    (PDF of chapter)
  6. C++ development environment
  7. (Postscript file of chapter)
    1. Integrated Development Environment
    2. C++ input and output
    3. A simple example program in C++:Design* Implementation*
    (PDF of chapter)

    Part 2 Simple Programs

  8. Sequence (PDF of chapter)
    1. Overall structure and main() Function
    3. Variable definitions
    4. Statements
    5. Examples: "Exchange rates"* pH*
    6. Naming rules for variables
    7. Constants
    8. Initialization of Variables
    9. Converting data values
  9. Iteration (PDF of chapter)
    1. While loops
    2. Examples: Modelling the decay of CFC gases* Newton's method for finding a square root* Tabulating function values*
    3. Blocks
    4. "Boolean" variables and expressions True and False* Expressions using "AND"s and "OR"s*
    5. Short forms: C/C++ abbreviations
    6. Do ... while
    7. For loop
    8. Break and Continue statements
  10. Selection (PDF of chapter)
    1. Making choices
    2. A realistic program: Desk Calculator
    3. IF...
    4. Terminating a program
    5. Example Programs: Calculating some simple statistics* Newton's method for roots of polynomials*
    6. What is the Largest? What is the Smallest?
  11. Simple use of files
    1. Dealing with more data
    2. Defining filestream objects
    3. Using input and output filestreams
    4. Stream states
    5. Options when opening filestreams
    6. When to stop reading data?
    7. More Formatting options
    8. Example
    9. (html text of most of section on files) (PDF of chapter)

  12. Part 3 Functions and Data Aggregates

  13. Functions (PDF of chapter)
    1. Form of a function Definition
    2. Result types
    3. Function declarations
    4. Default argument values
    5. Type safe linkage, Overloading, and Name Mangling
    6. How functions work
    7. Inline functions
    8. A recursive function
    9. Examples of simple functions: GetIntegerInRange* Newton's square root algorithm as a function*
    10. The rand() function
    11. Examples: pi-Canon* (html text of section introducing coding example), (text file with all code for pi-cannon) Function plotter*
  14. Arrays (Postscript file of chapter)
    1. Defining one dimensional arrays
    2. Initializing one dimensional arrays
    3. Simple Examples Using One-Dimensional arrays: Histogram* Plotting once more*
    4. Arrays as arguments to functions
    5. Strings: Arrays of characters
    6. Multi-dimensional arrays: Definition and initialization* Accessing individual elements* As arguments to functions*
    7. Arrays of Fixed length Strings
    8. Examples using arrays: Letter Counts* Simple encryption* Simple image processing*
    (PDF of chapter)
  15. Programs with functions and arrays (postscript file of chapter with several examples using functions and arrays)
    1. Curses
    2. Heat diffusion
    3. Menu Selection
    4. Pick the keyword
    5. Hangman (html text of section introducing hangman problem), (text file with all hangman code)
    6. Life
    (PDF of chapter)
  16. Standard algorithms(Postscript text of chapter on standard searching and sorting functions)
    1. Finding the Right Element: Binary Search: An iterative binary search routine* Isn't it a recursive problem?* What was the cost?
    2. Establishing Order
    3. A simple sort of sort
    4. Quicksort: a better sort of sort: The algorithm* An implementation* An enhanced implementation* (html text of section on Quicksort) (PDF of chapter)
    5. Algorithms, Functions, and Subroutine Libraries
  17. Tools (html text chapter on support tools for program development),
    1. The "Code Coverage" Tool
    2. The Profiler
    (PDF of chapter)
  18. Design and documentation : 1
    1. Top down functional decomposition
    2. Documenting a design
    (PDF of chapter) (PDF of coding guidelines)
  19. Enum, Struct, and Union
    1. Enumerated types
    2. structs
    3. Unions(html text of section on C/C++ Unions)
    (PDF of chapter)
  20. Examples using structs
    1. Reordering the class list again
    2. Points and Rectangles
    3. File of Records
    (PDF for chapter)
  21. Bits and pieces(Postscript file for chapter explaining role of bit-level operations in C/C++)
    1. Bit manipulations
    2. Making a Hash of it: Example hashing function for a character string* A simple "hash table"* Example: identifying the commonly used words*
    3. Coding "Property Vectors"
    4. Pieces (Bit fields) (PDF of chapter)

  22. Part 4 A Touch of Class

  23. Beginners' Class
    1. Class declarations and definitions: Form of a class declaration* Defining the member functions* Using class instances* Initialization and "constructor" functions* const member functions* inline member functions*
    2. Example: Bitmaps (Sets)
    3. Numbers - a more complex form of data (details of a class for +, -, *, /, on 100 digit numbers; as a postscript file) code of multidigit arithmetic class
    4. A glance at the "iostream" classes
    (PDF of chapter)
  24. Dynamic data and pointers (Postscript file of chapter)
    1. The "Heap"
    2. Pointers: Some "pointer" basics* Using pointers* Strings and hash tables revisited*
    3. Example: "Air Traffic Controller"
    4. The "address of" operator
    5. Pointers and Arrays
    6. Building Networks
    (PDF of chapter)
  25. Collections of data (postscript file of chapter presenting several standard "collection class" abstract types)
    1. Class Queue
    2. Class PriorityQueue
    3. Class DynamicArray (code in C29 and C30 examples)
    4. Class List
    5. Class BinaryTree (code in C23 iterators example)
    6. Collection class Libraries
    (PDF of chapter)
  26. A World of Interacting Objects
    1. RefCards: Design* Implementation*
    2. InfoStore: Initial design outline for InfoStore* Design and Implementation of the Vocabulary class* Other classes in the InfoStore program* Final class design for the InfoStore program
    3. (Postscript file, long case studies suggesting how to identify and then characterize objects and their classes
    (PDF of chapter)
  27. Intermediate class
    1. Shared Class Properties
    2. Friends
    3. Iterators: ListIterator* TreeIterator*(html file on Iterators for collection classes), (example code with tree iterator)
    4. Operator functions: Defining operator functions* Operator functions and the iostream library*
    5. Resource Manager Classes and Destructors: Resource management* Destructor functions* The assignment operator and copy constructors*
    6. Inheritance: Discovering similarities among prototype classes* Defining Class Hierarchies in C++* But how does it work?!* Multiple Inheritance* Using Inheritance (html file of section introducing inheritance and C++ class hierarchies)
    (PDF of chapter)
  28. Two more "trees"(Postscript file of chapter on AVL trees and Btree storage structures)
    1. AVL Trees: What's wrong with binary trees?* Keeping your balance* An implementation* Testing!*(code for an AVL tree class)
    2. BTree: Multiway trees* A tree on a disk?* BTree: search, insertion, and deletion operations* An implementation* Testing* (code in C30 example)
    (PDF of chapter)
  29. Templates (Postscript file of Templates chapter)
    1. A general function and its specializations
    2. Language Extensions for Templates:Template declaration* Template instantiation*
    3. Specialized Instantiations of Template Code
    4. A Template Version of QuickSort
    5. The Template Class "Bounded Array"
    6. The Template Class Queue
    (PDF of chapter)
  30. Exceptions (Postscript file of Exceptions chapter)
    1. C++'s Exception Mechanism
    2. Example: Exceptions for class Number
    3. Identifying the Exceptions that you intend to throw
    (PDF of chapter)
  31. Example: Supermarket
    1. Background and Program Specification/li>
    2. Design: Design preliminaries* Scenarios: identifying objects, their classes, their responsibilities, their data* Filling out the definitions of the classes for a partial implementation*
    3. A partial implementation
    4. Finalising the Design: Histograms* Simulating the checkouts and their queues* Organizing the checkouts*
    (PDF of chapter)
  32. Design and documentation: 2
    1. Object-Based Design
    2. Documenting a design
    (PDF of chapter)

  33. Part 5 Object Oriented Programming

    (Paper describing approach to teaching OO)
  34. The Power of Inheritance and Polymorphism (postscript file, of chapter with example illustrating use of inheritance and polymorphism)
    1. The "Dungeon" Game
    2. Design: Preliminaries* WindowRep and Window classes* DungeonItem hierarchy*(html text of chapter with example illustraing inheritance)
    3. An implementation: Windows classes* Class Dungeon* DungeonItems*( html text of chapter with example illustraing inheritance), (the code for "dungeon game" example)
    (PDF of chapter)
  35. Reusable designs
    1. The RecordFile Framework: Concepts(html text)
    2. The Framework classes: Overview
    3. The Command Handler Classes: Class declarations* Interactions* Implementation Code*
    4. Collection Classes and their Adapters*
    5. Class Record
    6. The Windows Class Hierarchy: Class Responsibilities* Implementation Code* Using the concrete classes from a framework*
    7. Organizational Details
    8. (Student Rec application, example use of a framework) (code for a simplified framework class library and application) (PDF of chapter)
  36. Frameworks for understanding(Postscript file introducing standard framework class libraries)
    1. "Resources" and "Macros"
    2. Architects, Experts, and Wizards
    3. Graphics
    4. Persistent Data
    5. The Event Handlers
    6. The Same Patterns in the code
  37. (PDF of chapter)

(page index)
(Another document on use of frameworks.) (Postscript introduction to frameworks like ET++ and MacApp)

Java? Some teaching materials from an introductory course on Java and the Internet for those who have a little background in C++. CSCI213: Java and the Internet

Please email questions to nabg@cs.uow.edu.au