C++ Programmer's Notebook, 2nd edition
Authors: Jim Edward Keogh, John Shapley Gray
Venue:  (2001)

From the Book:PrefaceSoftware developers strive to build complex computer applications quickly, accurately, and at a reasonable expense. The methodology that is used by many developers is modular programming, a technique in which the developer divides the application into logical subcomponents called modules. Each module, which performs a specific task and contains its own set of instructions, is built independently and often can be reused in other applications.Frequently, when implemented as program code, these modules are referred to as subroutines, procedures, or functions, depending on which computer language is used. In the C++ programming language, as well as in C, these modules are called functions. Using this approach, an application consists of a variety of modules, including a main module that executes the other modules. Regardless of the name, however, modules are limited. The modular programming approach (sometimes called functional design) for application development at times makes modeling a real-life problem into a computer application a difficult task. A real-life problem involves real objects. For example, tracking college registration requires that a registration form be used. This registration form is a real object with specific attributes. In fact, the form is most likely composed of other objects, such as text that provides instructions to the applicant and places to enter specific types ofdata.A real object has both data (attributes, information, and properties) and a set of associated operations. For example, a single copy (called an instance) of a registration form may have the student's name, course information, and other data that is directly related to the copy of the form. There are also the steps that are required to enter data onto the form and the instructions for how to process the form once it is completed (for example, where the form must be submitted). When attempting to translate a real-life problem into a computer application, traditional modular programming does not easily lend itself to the incorporation of objects. However, a different approach called object-oriented design does. Object-oriented design requires software developers to visualize an application as a collection of objects, not just as a set of functions. Further, it asks the developer to envision objects that have object-specific data that can carry on object-specific behavior/operations and that interact with other objects in a clearly defined manner. Object-oriented programs are collections of interrelated and interdependent objects. It is important to realize that when using this approach, objects that are more concrete, with easily identifiable attributes (such as a single registration form), are much easier to design than more abstract objects (such as a complete college course registration system). As with a modular program, a main module is still used to initiate the execution of the program.The C programming language provided flexibility for developers. They could write low and mid-level applications, such as an operating system using C. However, C could not properly handle an object-oriented design specification of an application. In the early 1980s at Bell Laboratories, the birthplace of the C programming language, Bjarne Stroustrup created an enhancement of C first called "C with Classes," which by the mid 1980s evolved into C++. Stroustrup set out to give the C language the capability of using code to better represent a real-life object. He transformed the C programming language from a procedural language into an object-oriented language. C++ is a superset of C. That is, C++ has all the capabilities of C plus more features. A Touch of ClassAs noted, a real-life object has both data and procedures that are associated with it. This association is represented in C++ code by using a class. A class defines a real life object as having a set of data (called data members) and procedures (called function members).A copy of the class is created by the software developer, using the name of the class to declare an instance of the class. In C++ parlance, this process is called instantiation. The instance is given a unique name. This technique is illustrated in Chapter 7 of this book. The instance of the class has its own copy of data and functions.Stroustrup also gave C++ inheritance, the capability to share class data and methods. This enables software developers to use previously defined classes (base classes) to build new classes (derived classes) and generate a hierarchy of classes. The derived classes may add or modify the functionality inherited from their base class ancestor.Return to the example of the registration form. The form is an object that is composed of various data entry fields and text. Each data entry field can be considered an edit object. Each edit object contains data and the function members to enter, edit, and validate the data. For discussion, we will call the text a label object. A label object stores the actual text (e.g., form directions), and may have font-specific information and methods that control the display of text on the output device. Therefore, when the software developer needs to build a form, such as a student registration form, the developer can create an instance of the form and populate it with edit and label objects. All basic data entry capabilities can be inherited from the base edit object, and all basic text capabilities can be inherited from the base label object. Should additional functionality be needed for a given data entry or label object, it can be added in the derived class.The Picture Book ApproachC++, as any computer language, is complex and has many rules that must be followed. Learning those rules can be time-consuming, especially for readers who already know how to program in a language other than C++. Those readers may want to jump into the language and begin writing simple code almost immediately.Many programmers who learn C++ as their second language have their own philosophy about learning the language: "Show me sample code and I'll figure out the rest." This is a basic tenet for the picture book organization of this text. The picture book concept places the focus of the book on a diagram of the code. Around this diagram are callouts that describe important statements and concepts. The rules are presented in tables that are positioned near the code. Furthermore, where appropriate there is a picture for each variation of the topic that is discussed in the chapter.A reader who wants to jump into C++ can study the diagram, copy the code into a compiler, and make the executable program without having to sift through pages of text. The rules can be referenced later, when the reader needs to expand this use of the routine.This approach is not intended to circumvent a thorough presentation of the C++ language. In fact, this book presents C++ in its completion. Instead, the picture book approach presents materials in the way programmers want to learn a new computer language. Navigating This BookThis book is organized into traditional chapters using a picture book approach. Each chapter covers a topic of C++ in a logical progression. If you are not familiar with the basics of C++, begin with the first chapter and continue through each chapter in progression. By the end of the last chapter, you will have a good foundation in C++.However, these chapters can be used also for quick reference. Jump to the chapter that discusses the topic that you want to review. Within the chapter, every topic is presented in its entirety with a focus on examples of code.Each chapter is further divided into sections, with each section being a two-page spread. Careful attention is given to the relationship between the left and right pages. The left page contains text that describes the topic illustrated on the right page. The right page focuses on C++ code and contains numerous callouts that further describe each facet of the code example.The most efficient way to use a two-page spread is to first study the example on the right page. If you understand the function of each statement in the example, you can continue and write your own program. However, if a concept, statement or keyword is confusing, then read the callout that describes the item. Still confused? Read the text on the left page.All code in this book can be found at the following FTP site: ftp://ftp.prenhall.com/pub/ptr/professional_computer_science.w-022/c++prog/