Register your product to gain access to bonus material or receive a coupon.
Extensively revised and updated, this proven book by noted C++/C expert Ira Pohl is written specifically for C programmers who are transitioning to C++. C++ For C Programmers, Third Edition takes an evolutionary teaching approach, using C as a starting point and C++ as a destination. This third edition reflects the new ANSI C++ Standard, and covers the latest language features--including detailed discussions of templates, STL, and exception handling. Each chapter contains a brief examination of Java that compares and contrasts it with C++, providing the C programmer with a more complete understanding of both C and C++ and their relationship to Java.
Highlights of C++ for C Programmers, Third Edition, include:
(Each chapter concludes with a Summary, Review Questions and Exercises.)
Preface.
1. An Overview of C++ and Object-Oriented Programming.
Object-Oriented Programming.
Why Learn C++?
C as a Starting Point.
Classes and Abstract Data Types.
Constructors and Destructors.
Overloading.
Dissection of the Operator+() Function.
Inheritance.
Moving from C++ to Java.
Dissection of the improved Program.
Benefits of Object-Oriented Programming.
Pragmatics.
Program Elements.
Comments.
Keywords.
Identifiers.
Literals.
Operators and Punctuators.
Input/Output.
Program Structure.
Simple Types.
Initialization.
The Traditional Conversions.
Enumeration Types.
Typedef Declarations.
Expressions.
Statements.
Assignment and Expressions.
The Compound Statement.
The if and if-else Statements.
The while Statement.
The for Statement.
The do Statement.
The break and continue Statements.
The switch Statement.
The goto Statement.
Pragmatics.
Moving from C++ to Java.
Dissection of the Moon Program.
Functions.
Function Invocation.
Function Definition.
The return Statement.
Function Prototypes.
Recursion.
Default Arguments.
Functions as Arguments.
Overloading Functions.
Inlining.
Scope and Storage Class.
The Storage Class auto.
The Storage Class extern.
The Storage Class register.
The Storage Class static.
Linkage Mysteries.
Namespaces.
Pointer Types.
Addressing and Dereferencing.
Pointer-Based Call-by-Reference.
Dissection of the order() Function.
Reference Declarations and Call-by-Reference.
The Uses of void.
Arrays and Pointers.
Subscripting.
Initialization.
The Relationship Between Arrays and Pointers.
Passing Arrays to Functions.
The char String: A Kernel Language ADT.
Multidimensional Arrays.
Assertions and Program Correctness.
Free-Store Operators new and delete.
Dissection of the dynarray Program.
Pragmatics.
Vector Instead of Array.
String Instead of char.
Moving from C++ to Java.
Dissection of the Sum Array Program.
The Aggregate Type Struct and class.
Structure Pointer Operator.
Member Functions.
Access: Private and Public.
Classes.
Class Scope.
Scope Resolution Operator.
Nested Classes.
An Example: Flushing.
static and const Members.
Dissection of the salary Program.
Mutable Members.
The this Pointer.
Unions.
Bit Fields.
A Container Class Example: ch_stack.
Pragmatics.
Moving from C++ to Java.
Classes with Constructors.
The Default Constructor.
Constructor Initializer.
Constructors as Conversions.
Improving the <CODE>point</CODE> Class.
Constructing a Dynamically Sized Stack.
The Copy Constructor.
Classes with Destructors.
An Example: Dynamically Allocated Strings.
Dissection of the my_string Class.
The Class dbl_vect.
dbl_vect as a Linear Vector Type.
Members That Are Class Types.
Example: A Singly Linked List.
Dissection of the print() and release() Functions.
Two-Dimensional Arrays.
Polynomials as a Linked List.
Strings Using Reference Semantics.
No Constructor, Copy Constructor, and Other Mysteries.
Destructor Details.
Pragmatics.
Moving from C++ to Java.
ADT Conversions.
Overloading and Function Selection.
Dissection of the rational Program.
Friend Functions.
Overloading Operators.
Unary Operator Overloading.
Binary Operator Overloading.
Overloading Assignment and Subscripting Operators.
Dissection of dbl_vect::operator=() Function.
Polynomial: Type and Language Expectations.
Overloading I/O Operators << and >>.
Overloading Operator () for Indexing.
Dissection of the Class matrix.
Overloading the Pointer Operator ->.
Overloading new and delete.
Pragmatics.
Signature Matching.
Moving from C++ to Java.
Template Class stack.
Function Templates.
Signature Matching and Overloading.
Class Templates.
Friends.
Static Members.
Class Template Arguments.
Default Template Arguments.
Member Templates.
Parameterizing the Class vector.
STL.
STL Example Code.
Containers.
Sequence Containers.
Dissection of the stl_vect Program.
Associative Containers.
Container Adapters.
Iterators.
The istream_iterator and ostream_iterator.
Iterator Adapters.
Algorithms.
Sorting Algorithms.
Nonmutating Sequence Algorithms.
Mutating Sequence Algorithms.
Numerical Algorithms.
Numerical Integration Made Easy.
Pragmatics.
Moving from C++ to Java.
A Derived Class.
Typing Conversions and Visibility.
Virtual Functions.
Abstract Base Classes.
Templates and Inheritance.
Multiple Inheritance.
Inheritance and Design.
Subtyping Form.
Code Reuse.
Runtime Type Identification.
Pragmatics.
Moving from C++ to Java.
Using the assert Library.
C++ Exceptions.
Throwing Exceptions.
Rethrown Exceptions.
Exception Expressions.
Try Blocks.
Handlers.
Exception Specification.
Terminate() and Unexpected().
Example Exception Code.
Standard Exceptions and Their Uses.
Pragmatics.
Moving from C++ to Java.
OOP Language Requirements.
ADTs: Encapsulation and Data Hiding.
Reuse and Inheritance.
Polymorphism.
OOP: The Dominant Programming Methodology.
Designing with OOP in Mind.
Class-Responsibility-Collaborator.
Design Patterns.
Moving from C++ to Java.
Program Structure.
Lexical Elements.
Comments.
Identifiers.
Keywords.
Constants.
Declarations and Scope Rules.
Namespaces.
Linkage Rules.
Types.
Conversion Rules and Casts.
Expressions and Operators.
sizeof Expressions.
Autoincrement and Autodecrement Expressions.
Arithmetic Expressions.
Relational, Equality, and Logical Expressions.
Assignment Expressions.
Comma Expressions.
Conditional Expressions.
Bit-Manipulation Expressions.
Address and Indirection Expressions.
new and delete Expressions.
Other Expressions.
Statements.
Expression Statements.
The Compound Statement.
The if and if-else Statements.
The while Statement.
The for Statement.
The do Statement.
The Break and Continue Statements.
The switch Statement.
The go to Statement.
The return Statement.
The Declaration Statement.
Functions.
Prototypes.
Call-by-Reference.
Inline Functions.
Default Arguments.
Overloading.
Type-Safe Linkage for Functions.
Classes.
Constructors and Destructors.
Member Functions.
Friend Functions.
The this Pointer.
Operator Overloading.
static and const Member Functions.
Mutable.
Inheritance.
Multiple Inheritance.
Constructor Invocation.
Abstract Base Classes.
Pointer to Class Member.
Runtime Type Identification.
Virtual Functions.
Templates.
Template Parameters.
Function Template.
Friends.
Static Members.
Specialization.
Exceptions.
Throwing Exceptions.
Try Blocks.
Handlers.
Exception Specification.
Terminate() and Unexpected().
Standard Library Exceptions.
Caution and Compatibility.
Nested Class Declarations.
Type Compatibilities.
Miscellaneous.
New Features in C++.
The Output Class ostream.
Formatted Output and iomanip.
User-Defined Types: Output.
The Input Class istream.
Files.
Using Strings as Streams.
The Functions and Macros in ctype.
Using Stream States.
Mixing I/O Libraries.
Containers.
Sequence Containers.
Associative Containers.
Container Adapters.
Iterators.
Iterator Categories.
Iterator Adapters.
Algorithms.
Sorting Algorithms.
Nonmutating Sequence Algorithms.
Mutating Sequence Algorithms.
Numerical Algorithms.
Functions.
Function Adapters.
Allocators.
String Library.
Constructors.
Member Functions.
Global Operators.
The book uses an evolutionary teaching process, with C as a starting point and C++ as a destination. It can also be used by those already familiar with other similar programming languages, such as Pascal, PL/1, or BASIC. The reader can stop and use the language facilities at various points in the text.
This book will get the C programmer up and running in C++ in the shortest possible time. The teaching-by-equivalency method used enables the C programmer to immediately convert existing code to C++. Working code is emphasized. A program particularly illustrative of the chapter's themes is analyzed by dissection, which is similar to a structured walk-through of the code. Dissection explains to the reader newly encountered programming elements and idioms.
C is a general-purpose programming language that was originally designed by Dennis Ritchie of Bell Laboratories and implemented there on a PDP-11 in 1972. C was first used as the systems language for the UNIX operating system. Ken Thompson, the developer of UNIX, had been using both an assembler and a language named B to produce initial versions of UNIX in 1970.
C++, invented at Bell Labs by Bjarne Stroustrup in the mid-1980s, is a powerful modern successor language to C. C++ adds to C the concept of class, a mechanism for providing user-defined types, also called abstract data types. C++ supports object-oriented programming by these means and by providing inheritance and runtime type binding. C++ is increasingly the choice of scientists and engineers in developing scientific software.
This book, intended for use in a first course in C++ programming, can be used as a supplementary text in an advanced programming, data structures, software methodology, comparative language, or other course in which the instructor wants C++ to be the language of choice. Each chapter presents a number of carefully explained programs.
All of the major pieces of code were tested. A consistent and proper coding style is adopted from the beginning and is one chosen by professionals in the C++ community. The code is available at the Addison Wesley Longman Web site (www.awl.com/cseng/titles/0-201-39519-3/).
For the programmer who wants C experience, this book could be used in conjunction with A Book on C, 4th ed., by Al Kelley and Ira Pohl (Addison-Wesley, 1998). As a package, the two books offer a unique, integrated treatment of the C and C++ programming languages and their use.
This book incorporates a number of important features.
My special thanks go to my wife, Debra Dolsberry, who encouraged me throughout this project. She acted as book designer and technical editor for this edition. She developed appropriate formats and style sheets in FrameMaker 5.5 and guided the transition process from my other books on C++. She also implemented and tested all major pieces of code.
This book was developed with the support of my editor, J. Carter Shanklin, and editorial assistant, Angela Buenning.
--Ira Pohl
University of California, Santa Cruz