©opyright 2001, 2002 By Neil C.
Obremski
This is an ongoing rough draft of an eventual book by Neil C. Obremski. All documents part of this draft should be considered work in progress and as such should be taken lightly, as it is unfinished and possibly not wholly accurate. By reading this you are acknowledging that I, Neil C. Obremski, am not liable for any damages incurred by this material.
All content contained therein is the property of myself, Neil C. Obremski, the copyright owner, and is under protection by common law copyright. I hereby give all persons the right to redistribute this draft in an electronic or hardcopy form so long as they are distributed in whole and not trimmed, maimed, "corrected", or otherwise mutilated in any way. Any recipients of the distribution must acknowledge Neil C. Obremski as the author, content creator, and copyright owner. Persons distributing drafts must notify recipients of these legalities and any new ones that should appear. This is to ensure credit where credit is due.
Hardcopies must begin with this document (Preface.doc) so that the legalities are easily visible to readers and recipients.
For the latest draft, information, and current legalities, please visit http://www.neilstuff.com/ or email webmaster@neilstuff.com .
I've written this book as a starting point for programming using the C++ language. You may reread key sections now and then to refresh your memory or even use it as a handy reference, but the primary goal is to bust open your brain and stuff the seeds of C++ into your consciousness.
It may take you a week to read this, if you finish it, or a year. Mastery of the C++ language does not come from any single source, be it book or tutor. It comes from years of experience, experimentation, and mingling with your programming brothers and sisters. Know ye that I thought to forsake this timeless advice and bound ahead with great strides. But lo! After starting to learn and use C++ in the fall of 1996 I am still discovering things. Do not be discouraged; expect neither too little nor too much, but be pleasantly surprised by both.
References in this genre of programming are plentiful and generally complete, but the city of building block books is sporadically filled with useful, useless, and flawed explanations. Authors have sown their work not only with knowledge, but with their self-same biases, prejudices, hyped enthusiasm, or lack thereof, and coding habits for good or ill. The blood and brains of scholars is fired and filled by the quirks of people they have never met in person.
Newbies, I have seen or talked to, wander lost among the maze of boundless and circular information. Prizes of cheese escape them beyond barriers unbroken, unexplained. I write this book to bring YOU to the cheese and send you home happy!
Because that's what this book is about; deal with it!
This book is for those who wish to learn the C++ language, but I’d be an Oz Wizard if I said that this book was for everyone with this goal. No book can hope to target that broad of an audience. It is written as plainly as possible and helps you up from no programming or computing experience. If you are struggling with, intimidated by, or wary of this subject then I suggest you give this book a go. I do not intend to make this book a full C++ reference (though that is what I intend for NeilStuff.com) nor do I expect experts to read this without cringing at the simplistic, ye almost human, explanations of their closely guarded secrets.
I do not provide inline notes for differences between C++ and other languages. If you are coming from a different programming language, you should recognize some things and be unfamiliar with others. But regardless you will see the differences yourselves.
This book is written with the beginner in mind. As such I’ve tried to organize this book so each new chapter is a slightly more advanced topic than the last. The first chapters will teach the most basic and fundamental concepts and as the book progresses the features of the language will shine through.
I’ve also tried to write this without comparison to other languages. That kind of thing, in my opinion, is best saved for a separate chapter or something. What you want to learn is C++, so that’s what I’m going to teach you. I won’t spend time comparing it to language ‘X’ because I can’t assume that you know that language or that you even care about it.
Part 1 is an introduction to the world of computers. It requires no computer to read through or do the exercises; it is all concepts. The part welcomes to the readers to the technobabble world of buzzwords, heaps of useless and redundant technology, and the diamonds in the rough waiting to be found out. Feel free to skip this if you have previous programming or computer operation experience.
Part 2 is a guide through the basics of the C++ language. This part will school you enough to get by with your programming.
Part 3 dives into advanced concepts for C++, but tries to maintain the thorough explanations. It also brings the reader up to date with newer additions like namespaces and the standard namespace; shining the light on "proper" C++ program structure.
Part 4 delves further into object-oriented and object-based programming with classes, polymorphism, abstraction, namespaces, static and dynamic libraries.
Part 5 is on the C++ Standard Template Library which is a collection of standard classes for common programming tasks.
I'd also like to include stub entries of things to set people on the path to GUI, multimedia, and low-level programming.
My opinions, when I choose to disclose them, are clearly marked throughout the book. I’ve tried to keep them separate from the text. Every one has their own opinions and I don’t want my personal ones interfering with your learning. You can choose to skip them if you wish. Concepts that I find silly or disgusting may or may not be marked. Please do not assume that everything I teach you in this book I particularly like. This book is for learning the language, not my personal preferences.
This is not intended
as a map of things that are already written, but a path of things to work on or
that I already have. It’s a huge task to
tackle a book and there’s a lot of stuff I want to cover. I even keep coming upon things I forgot to
mention in earlier chapters so first I make a change here before going back
(just in case I forget). In other words,
this is to keep my in line so I don’t ramble off into complete gibberish or
start writing about things out of there chapter context.
1. Machines: Input/Output, Storage, and Logic
a. Introduction
b. Digital Machines
c. The Three Parts of Computers
d. A Simple Example
e. Input/Output
f. Storage
g. Logic
h. Hardware
2. Logic and Languages
a. Software
b. Operating Systems
c. Languages
d. Machine Language
e. Assembly Language
f. High-Level Languages
g. Compiled Languages
h. Interpreted Languages
i. Methods of Programming
i. Procedural
ii. Object-Oriented
3. Numbering Systems
a. Introduction
b. The Decimal Numbering System
c. Bases Loaded
d. The Imaginary Numbering System (Fivemal)
e. Distinguishing Numbering Systems
f. Converting Between Numbering Systems
g. The Binary Numbering System (base 2)
h. The Hexadecimal Numbering System (base 16)
i. The Dead Numbering System (base 8)
4. Storage
a. Computers Use Binary
b. N-Bit CPU
c. Hexadecimal Saves Us
d. Multiple Byte Data Storage
5. The C++ Language ß Do I need this chapter? I want to remove it
a. Choosing a Language
b. History of C++
1. Preparation
a. What You Need
b. Text Editor
c. C++ Software
d. Command Console
2. Syntax and Expressions
a. Breaking into the Circle
b. The ‘Hello World’ Program
c. Syntax
d. My Dear Aunt Sally (operator precedence)
e. Outputting Numbers
f. Integers
g. Floating Point
h. Limits
i. White Space
j. Comments
3. Numbers and Values
a. What is a Variable
b. Data Types
c. Declaring a Variable
d. Declaring Multiple Variables
e. Identifiers
f. C++ Keywords
g. Literals
h. Constants
i. Assignment
j. Basic Arithmetic
k. Casting
l. Output
m. Input
n. Increment and Decrement
o. Land Plot Analogy
4. Blocks and Flow
a. Statement Blocks
b. Scope and Nesting
c. Locals
d. Globals
e. Namespaces
f. Flow Control
g. If
h. Relational and Equality
i. Logical Operators
j. Complex Conditions
k. Else
l. Looping
m. While
n. Do-While
o. For
p. Breaking and Continuing
5. References and Pointers
a. Introduction
b. Reference Variables
c. Memory Address
d. Pointers
e. Dereference
f. Pointer Types
g. Void Pointers
h. Null Pointers
6. Structures
a. Introduction
b. Structures
c. Struct
d. Creating Struct Variables
e. Initialize Struct Variables
f. Using Struct Variables
g. References and Structures
h. Pointers and Structures
i. Bit-Fields
j. Unions
k. Structure Padding
7. Functions
a. Introduction
b. Modularization
c. Prototyping and Definition
d. First Example
e. Return
f. Void
g. Correct
h. Parameters
i. Passing by Value
j. Passing by Reference
k. Constant Parameters
l. Scope
m. Call Stack
8. Arrays
a. Introduction
b. Array Declaration
c. Looping Subscripts
d. Initializing Arrays
e. Declaring Arrays without Size
f. Copying an Array
g. Arrays in Memory
h. Pointers to Arrays
i. Pointer Arithmetic
j. References to Arrays
k. Constant Arrays
l. Array Function Parameters
m. Passing Arrays to Functions
n. SizeOf Array
9. Strings
a. Text is Character Strings
b. Character Literals
c. ASCII and Assumptions
d. Char
e. Character Functions
f. String Literals and Constants
g. Variable Strings
h. Initializing Strings
i. Pointers to Strings
j. Cin and Strings
k. String Assignment
l. SizeOf String
m. Concatenation
n. Comparing Strings
o. Converting Strings to Numbers
p. Changing String Case
q. Unicode Strings
10. Pre-Processing
a. The “Other” Compiler
b. #include
c. Custom Headers
d. Macros
e. Destroying Macros
f. Flow Control
g. Existence Checking
h. Parenthesis Unnecessary
i. Raising Errors
j. Concise Types
11. Classes and Objects
a. Blobs with Class
b. Simple Declaration and Usage
c. Member Functions
d. Constructors and Destructors
e. Custom Constructors
f. Initializing Member Variables
g. Inheritance
h. Overloading
i. Class Namespaces
j. Static Members
k. Access Modifiers
l. Friends
m. This
n. Structures are Classes
12. Files and I/O
a. Console I/O (cout/cin)
b. Escape Characters
c. File I/O (ofstream/ifstream)
d. Binary Files
e.
Part 3: Glossary of Terms and Advanced Concepts
Some of the following things might never get included in the book, others will be absorbed by chapters already written. But the following is basically a structured brainstorm of things I had originally planned to cover. Why can’t I write about all of these? The book would be enormous (due to its “guiding” quality rather than being a “reference”) and it would cost you a lot more.
1. Memory
a. Stack Memory / Call Stack
b. Heap Memory
c. Allocating and Free Blocks
d. Allocating Object Instances
2. Name Spaces
a. Global
b. std
3. Advanced Flow Control
a. Switch
b. Else If
c. Comma Operator
d. Ternary Operator
4. Bit Manipulation
a. Bit Variables in Objects
b. Bitwise Operators
c. Shifting
d. Making Flags
e. Using Enum/Define for Flag Constants
5. Modularization
a. Header Files
b. Multiple Source Files
c. Static Code Libraries
d. Dynamic Code Libraries (DLL, SO)
e. extern Keyword
6. Recursion
a. Show Folder and all Sub-Folders
b. Towers
of
7. Advanced Functions
a. Variable Arguments
b. Pointers to Functions
c. Callbacks
d. Functions inside Functions
e. Templates
f. Function Overloading
g. Operator Overloading
Part 4: Object Orientation with Classes
1. Introduction to Classes
a. Versus struct
2. Member Functions
a. Pointers to
3. Protected, Private, and Public
4. Member Scope
5. Operator Overloading
a. making my string class act like a char*
Part 5: Performance and Tuning
1. Data Alignment
2. Cached and Volatile Variables
a. What is Caching?
b. Cached Variables: register
c. Non-Cached Variables: volatile
3. Outline and Inline Functions
4. Name Spaces
5. Unicode
6. Etiquette
a. Conventions
Part 6: Debugging
1. Tracing
2. Assertions
3. Using a Debugger
Part 7: Standard C++ and the STL
1. Correct C++
a. Default Name Space
b. A Politically Correct ‘Hello World’
2. Intro to STL
3. Vectors and Iterators
4. Strings
Part 8: Multi-Threading
1. Synchronization Nightmare