Home > Store

C++ Programmer's NoteBook, The: An Illustrated Quick Reference

Register your product to gain access to bonus material or receive a coupon.

C++ Programmer's NoteBook, The: An Illustrated Quick Reference

  • By
  • Published Oct 28, 1997 by Pearson.

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1998
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-525940-1
  • ISBN-13: 978-0-13-525940-5


52594-9

“Show me the code!” The easy, visual approach to C++.

Finally, there's a book that presents C++ the way you want to learn it --from real, working code! C++ Programmer's Notebook is so visual, so sensible, so convenient, you'll wonder why nobody thought of it before. See for yourself!

  • The code comes first! Start by looking at proven code samples you can just copy and run!
  • Everything's highlighted in boldface type, so you instantly see the basic C++ syntax, and what you have to add to it.
  • All the rules are neatly summarized in a convenient table!

And if you want to know more, it's right there for you on the adjacent left-hand page.

C++ Programmer's Notebook isn't just convenient: it's comprehensive. And it's carefully, logically organized to build your expertise one step at a time. It covers all the C++ concepts you need to know, including:

  • Variables
  • Arrays
  • Overloading
  • Files and Streams
  • Operators
  • Strings
  • Inheritance
  • Memory Management
  • Expressions
  • Program Control
  • Pointers
  • Storing/Searching for Data
  • Structures
  • Objects
  • Virtual Functions
  • Data Structures
  • Functions
  • Classes
  • I/O
  • Templates

There's even a programmer's checklist for writing efficient, reliable code.

It's a complete course in C++ without the pain! Whether you're a professional programmer learning C++, a C++ programmer needing a quick reference, or a student, this is the C++ book you'll use every day!

Sample Content

Table of Contents



Preface.


1. Working with Variables.

Naming Variables. Using Variables. Integer Variables. Character Variables. Escape Sequences. Floating-Point Variables. Inside Exponential Notation. Signed and Unsigned Variables. Data Type Conversion. Assigning Values to Variables. Local Variables. Global Variables. Local Variables vs. Global Variables. Storage Specifiers. static. Register. auto. Storage Specifier Rules.



2. Working with Operators and Expressions.

Expressions. Arithmetic Operators. The +=, -=, *=, /= Operators. The % Operator. The ++, -- Operators. Relational Operators. The <=, ==, != Operators. Logical Operators. Bitwise Operators. Bitwise AND. Bitwise OR. Bitwise XOR (exclusive OR). Bitwise NOT. The Shift Left Operator. The Shift Right Operator. The ? Operator (if...the...else). The & and * Pointer Operators. A Brief Look at Pointers. The Precedence Table. Working with Expressions.



3. Working with Arrays and Strings.

Arrays and Strings. Other Ways to Assign Values to an Array. Loop. Multidimensional Arrays. Other Ways to Assign Values to a Multidimenional Array. Loop. Strings. Copying a String to Another String scanf(). Reading a String from the Keyboard gets(). Another Way to Read a String from the Keyboard scanf(). Still Another Way to Read a String from the Keyboard with the Extraction Operator. Comparing Two Strings strcmp(). Displaying a String printf(). Another Way to Display a String puts(). Still Another Way to Display a String with the Insertion Operator. Concatenating Strings strcat(). Determining the Length of a String strlen(). Determining the Length of a Substring strcspn(). Another Way to Determine the Length of a Substring strspn(). Concatenating a Substring strncat(). Comparing Substrings strncmp(). Locating a Character within a String strpbrk(). Locating the First Occurrence of a Substring in a String strstr(). Dividing a String into Several Substrings strtok().



4. Working with Structures.

Structures. A Structure at Work. Running the Sample Program. Another Way to Declare an Instance. Assigning Values to Structure Members. Multiple Instances. Assigning Values to Multiple Instances. Structures within Structures. Passing Elements of a Structure to a Function. Passing by Address. Passing the Value of a Structure to a Function. Passing the Address of a Structure to a Function. Unions. Other Ways to Declare an Instance of a Union. Enumerations. Typedefine.



5. Working with Functions.

Anatomy of a C++ Function. The main( ) Functions. How to Use a function. Passing Arguments. Passing Multiple Arguments. Passing Arguments to the main( ) Function. Returning Values. Functions Calling Functions. Building a Program Using Functions. Program Statements. White Space Characters. Preprocessor Directives. More Preprocessor Directives. #define with Arguments. #if, #else, #elif, #endif. #ifdef, #ifndef, #undef. #line, #error and #pragma. Making a C++ Program.



6. Working with Program Control.

Program Control Statements. If. if ... else. The ? Operator. Nested if. if ... elseif. Multiple Conditions. switch ... case. Tricks of the Trade. for loop. Decrementing the for Loop Counter. Another Way to Use a for Loop. A Nested for Loop. An Infinite Loop. while Loop. do. . . . while Loop. Break. exit( ). Continue. Goto.



7. Working with Objects and Classes.

Classes. Declaring an Instance of a Class. Hiding Data Using the Access Specifier. The Constructor. Overloading the Constructor. The Destructor. Defining a Function Member Outside the Class Definition.



8. Working with Overloading.

Overloading. Overloading a Function Using Different Data Types. Overloading a Unary Operator. Overloading a Binary Operator. Operators that Can and Cannot be Overloaded.



9. Working with Inheritance.

Inheritance. Access Specifiers. More About Inheritance. Multiply Inheritance. Ambiguity in Multiple Inheritance. Containership Class. Levels of Inheritance.



10. Working with Pointers.

Pointers. Using Pointers in Expressions. Incrementing Pointers. Decrementing Pointers. Pointer Math. Tricks of the Trade. An Array of Pointers. Pointers-to-Pointers. A Pointer-to-a-Function. Tricks of the Trade.



11. Working with Virtual Functions.

Creating a Virtual Function. Without Redefining a Virtual Function. Creating a Pure Virtual Function. More about Virtual Functions. Friend Functions. Creating a Friend Function from a Function Member. Forward Reference of a Class.



12. Working with Keyboard Input—Screen Output.

Keyboard Input/Screen Output. Reading a Character from the Keyboard without Echo getch(). Display a Character on the Screen putchar(). Reading a String from the Keyboard with Less Overhead gets(). Reading a String from the Keyboard with Greater Control scanf(). Reading a String scanf(). Limiting the Number of Characters Read from the Keyboard. Receiving More than One Value at the Same Time. Creating Your Own Separator. Another Way to Create Your Own Separator. Displaying a String on the Screen with Less Overhead puts(). Displaying a String on the Screen with Greater Control printf(). Displaying a String printf(). Displaying an Integer printf(). Padding the Data with Spaces. Specifying the Minimum and Maximum Width of Data. Adding Padding to the End of the Data. Specifying the Number of Decimal Places. Displaying a String Constant in C++ cout<<. Displaying a String Variable Using cout. Displaying a Non-String Variable Using cout. Displaying Strings And Non-Strings Together Using cout. Reading a String from the Keyboard Using C++ cin>>. Manipulators.



13. Working with Files and Streams.

File Input/Output. Mode Specifiers for the fopen() Function. Closing a File. Writing a Character to a File putc(). Reading a Character from a File getc(). Tricks of the Trade. Writing a String to a File fputs(). Reading a String from a File fgets(). Writing an Integer to a File putw(). Reading an Integer from a File getw(). Writing a Block of Data to a File fwrite(). Reading a Block of Data from a File fread(). Creating a Database File. Reading a Record. Writing Various Data Types to a File fprintf(). Using the fprintf() Function. Reading Various Data Types from a File fscanf(). Using the fscanf() Function. Moving to Specific Locations in a File fseek(). Returning to the Beginning of a File rewind(). Deleting a File unlink(). Using a File in C++. Writing Information to a File Using C++. Reading a String from a File Using C++. Writing a Single Character to a File Using C++. Reading a Single Character from a File Using C++. Writing an Object to a File. Reading an Object from a File. Specifying the File Mode in C++.



14. Working with Memory Management.

Computer Memory. Storing Data on the Stack. Storing Data on the Heap. Storing an Array of Objects on the Heap. Reallocating Heap Memory. Another Way of Storing Data on the Heap. Using a Dynamic Array.



15. Working with Storing and Searching Data.

The Bubble Sort. Inside the Bubble Sort. The Linear Search. The Binary Search. A Close Look at the Binary Search Routine.



16. Working with Data Structures.

Linked Lists. Adding a Node to a Linked List. A Closer Look at Adding a Node. Deleting a Node from a Linked List. A Closer Look at Deleting a Node. Stacks. A Closer Look at the push() Function. The pop() Function. A Closer Look at the pop() Function. Queues. A Closer Look at the enterqueue() Function. The exitqueue() Function. A Closer Look at the exitqueue() Function.



17. Working with Templates.

Templates. Templates with Multiple Parameters. Class Template.



Programmer's Checklist.

General. Keywords, Variables, Arrays, and Constants. Expressions and Operators. Program Control. Functions. Classes. Input/Output.



Index.

Preface

Preface

Software 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. This is a technique where the developer divides the application into logical components, each of which can be built independently and reused in other applications.

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. Regardless of the name, however, modules are limited. The modular programming approach to software design, at times, makes modeling into computer code a real life problem and 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 an object. In fact, the form is actually composed of many objects, such as places to enter data and text that provides instructions to the applicant. A real object has both data and procedures associated with an object. For example, a single copy (called an instance) of the registration has the student's name, course information, and other data that is directly related to only that copy of the form. Also associated with the form are the steps that are required to enter data onto the form and to process that copy of the form.

Traditional modularity does not lend itself to using an object-oriented design approach when translating a real life problem into a computer application. Object-oriented design requires software developers to visualize a real life object as an object and not as a set of procedures. For example, a college registration form is a physical object that is composed of other objects, such as a place to enter data and labels that provide directions for completing the form.

The C programming language provided flexibility for developers. They could write low-level applications, such as an operating system using C. C was also a language that could be used to create a simple business application. 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 called 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 as C plus more features.



A Touch of Class

A real life object has both data and procedures associated with the object. This association is represented in C++ code through the use of 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 by using the name of the class to declare an instance of the class. The instance is given a unique name. This technique is illustrated later in this book. The instance of the class has its own copy of data and functions. Stroustrup also gave C++ the capability to share classes (called inheritance). This enables software developers to use other classes (called base classes) to build new classes (called derived classes). Return to the example of the registration form. The form is a new object that is composed of data (called an edit object) and text (called label objects). An edit object relates the data and the function members to accept, edit, and validate the data. A label object can store text used in the label and has function members that handle fonts, and other characteristics that can be used for the label. Therefore, when the software developer needs to build a form, such as the student registration form, the developer can create instances of the edit and label objects. All of the text editing capabilities (i.e., insertion and deletion of characters) are inherited.



The Picture Book Approach

C++, as any computer language, is complex and has many rules that must be obeyed. Learning those rules can be time-consuming, especially for readers who already know how to program in a language other than C++. Those readers 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," is a statement that summarizes their approach. And that's what I do in this book.

The picture book concept places the focus of the book on a picture of the code. Around this picture are callouts that describe each keyword and statement. The rules are presented in tables that are positioned near the picture. Furthermore, 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 picture, then 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 material in the way programmers want to learn a new computer language.



Navigating This Book

I organized this book into traditional chapters. Each chapter covers a topic of C++ in a logical progression. So, if you are not familiar with the basics of C++, then begin with the first chapter and continue through each chapter in progression. At 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. The topic within the chapter is presented in its entirety with a focus on examples of code.

Each chapter is further divided into two-page spreads. That is, careful attention is given to the relationship between the left and right pages. The left page contains text that describes the topic that is illustrated on the right page. The right page focuses on C++ code that contains callouts describing 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, then you can continue and write your own program. However, if a statement or keyword is confusing, then read the callout that describes the item. Still confused? Read the text on the left page.

Careful attention is given to clarity of the code example, the right page. You will notice that the syntax of the C++ code is shown in color. Parts of the statements that are not colored are pieces that the programmer creates. For example, the statement char code; declares a character variable. char and the semicolon (;) are colored. They are part of the syntax of C++. The word code, however, is the name of a variable that can be any name that complies with the rules of C++. This style is similar to the concept used with Integrated Development Environments (IDE) such as used in Borland C++ and Microsoft Visual C++.



All code in this book can be found at the following FTP site:

/ftp/pub/ptr/professional_computer_science.w.-022/keogh/c++_notebook.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020