9780201703535

Accelerated C++ Practical Programming by Example

by ;
  • ISBN13:

    9780201703535

  • ISBN10:

    020170353X

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2000-08-14
  • Publisher: Addison-Wesley Professional

Note: Supplemental materials are not guaranteed with Rental or Used book purchases.

Purchase Benefits

  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
  • Buyback Icon We Buy This Book Back!
    In-Store Credit: $2.11
    Check/Direct Deposit: $2.01
    PayPal: $2.01
List Price: $49.99 Save up to $24.99
  • Rent Book $25.00
    Add to Cart Free Shipping Icon Free Shipping

    TERM
    PRICE
    DUE
    USUALLY SHIPS IN 24-48 HOURS
    *This item is part of an exclusive publisher rental program and requires an additional convenience fee. This fee will be reflected in the shopping cart.

Supplemental Materials

What is included with this book?

Summary

A new approach to C++ programming

We assume that you want to learn quickly how to write useful C++ programs. Therefore, we start by explaining the most useful parts of C++. This strategy may seem obvious when we put it that way, but it has the radical implication that we do not begin by teaching C, even though C++ builds on C. Instead, we use high-level data structures from the start, explaining only later the foundations on which those data structures rest. This approach lets you to begin writing idiomatic C++ programs immediately.

Our approach is unusual in another way: We concentrate on solving problems, rather than on exploring language and library features. We explain the features, of course, but we do so in order to support the programs, rather than using the programs as an excuse to demonstrate the features.

Because this book teaches C++ programming, not just features, it is particularly useful for readers who already know some C++, and who want to use the language in a more natural, effective style. Too often, people new to C++ learn the language mechanics without learning how to apply the language to everyday problems.

Our approach works--for beginners and experienced programmers
We used to teach a week-long intensive C++ course every summer at Stanford University. We originally adopted a traditional approach to that course: Assuming that the students already knew C, we started by showing them how to define classes, and then moved systematically through the rest of the language. We found that our students would be confused and frustrated for about two days--until they had learned enough that they could start writing useful programs. Once they got to that point, they learned quickly.

When we got our hands on a C++ implementation that supported enough of what was then the brand-new standard library, we overhauled the course. The new course used the library right from the beginning, concentrated on writing useful programs, and went into details only after the students had learned enough to use those details productively.

The results were dramatic: After one day in the classroom, our students were able to write programs that had taken them most of the week in the old course. Moreover, their frustration vanished.

Abstraction
Our approach is possible only because C++, and our understanding of it, has had time to mature. That maturity has let us ignore many of the low-level ideas that were the mainstay of earlier C++ programs and programmers.

The ability to ignore details is characteristic of maturing technologies. For example, early automobiles broke down so often that every driver had to be an amateur mechanic. It would have been foolhardy to go for a drive without knowing how to get back home even if something went wrong. Today's drivers don't need detailed engineering knowledge in order to use a car for transportation. They may wish to learn the engineering details for other reasons, but that's another story entirely.

We define abstraction as selective ignorance--concentrating on the ideas that are relevant to the task at hand, and ignoring everything else--and we think that it is the most important idea in modern programming. The key to writing a successful program is knowing which parts of the problem to take into account, and which parts to ignore. Every programming langauge offers tools for creating useful abstractions, and every successful programmer knows how to use those tools.

We think abstractions are so useful that we've filled this book with them. Of course, we don't usually call them abstractions directly, because they come in so many forms. Instead, we refer to functions, data structures, classes, and inheritance--all of which are abstractions. Not only do we refer to them, but we use them throughout the book.

If abstractions are well designed and well chosen, we believe that we can use them even if we don't understand all the details of how they work. We do not need to be automotive engineers to drive a car, nor do we need to understand everything about how C++ works before we can use it.

Coverage
If you are serious about C++ programming, you need to know everything in this book--even though this book doesn't tell you everything you need to know.

This statement is not as paradoxical as it sounds. No book this size can contain everything you'll ever need to know about C++, because different programmers and applications require different knowledge. Therefore, any book that covers all of C++--such as Stroustrup's The C++ Programming Language (Addison-Wesley, 2000)--will inevitably tell you a lot that you don't need to know. Someone else will need it, even if you don't.

On the other hand, many parts of C++ are so universally important that it is hard to be productive without understanding them. We have concentrated on those parts. It is possible to write a wide variety of useful programs using only the information in this book. Indeed, one of our reviewers, who is the lead programmer for a substantial commercial system written in C++, told us that this book covers essentially all of the facilities that he uses in his work.

Using these facilities, you can write true C++ programs--not C++ programs in the style of C, or any other language. Once you have mastered the material in this book, you will know enough to figure out what else you want to learn, and how to go about it. Amateur telescope makers have a saying that it is easier to make a 3-inch mirror and then to make a 6-inch mirror than to make a 6-inch mirror from scratch.

We cover only standard C++, and ignore proprietary extensions. This approach has the advantage that the programs that we teach you to write will work just about anywhere. However, it also implies that we do not talk about how to write programs that run in windowing environments, because such programs are invariably tied to a specific environment, and often to a specific vendor. If you want to write programs that will work only in a particular environment, you will have to turn elsewhere to learn how to do so--but don't put this book down quite yet! Because our approach is universal, you will be able to use everything that you learn here in whatever environments you use in the future. By all means, go ahead and read that book about GUI applications that you were considering--but please read this one first.

A note to experienced C and C++ programmers
When you learn a new programming language, you may be tempted to write programs in a style that is familiar from the languages that you already know. Our approach seeks to avoid that temptation by using high-level abstractions from the C++ standard library right from the start. If you are already an experienced C or C++ programmer, this approach contains some good news and some bad news--and it's the same news. The news is that you are likely to be surprised at how little of your knowledge will help you understand C++ as we present it. You will have more to learn at first than you might expect (which is bad), but you will learn more quickly than you might expect (which is good). In particular, if you already know C++, you probably learned first how to program in C,

Author Biography

Andrew Koenig is a member of the Large-Scale Programming Research Department at AT&T's Shannon Laboratory, and the Project Editor of the C++ standards committee. A programmer for more than 30 years, 15 of them in C++, he has published more than 150 articles about C++, and speaks on the topic worldwide.

Barbara E. Moo is an independent consultant with 20 years' experience in the software field. During her nearly 15 years at AT&T, she worked on one of the first commercial products ever written in C++, managed the company's first C++ compiler project, and directed the development of AT&T's award-winning WorldNet Internet service business.



0

Table of Contents

Preface xi
Getting started
1(8)
Comments
1(1)
#include
2(1)
The main function
2(1)
Curly braces
2(1)
Using the standard library for output
3(1)
The return statement
3(1)
A slightly deeper look
4(1)
Details
5(4)
Working with strings
9(8)
Input
9(2)
Framing a name
11(3)
Details
14(3)
Looping and counting
17(18)
The problem
17(1)
Overall structure
18(1)
Writing an unknown number of rows
18(4)
Writing a row
22(5)
The complete framing program
27(3)
Counting
30(1)
Details
31(4)
Working with batches of data
35(16)
Computing student grades
35(6)
Using medians instead of averages
41(7)
Details
48(3)
Organizing programs and data
51(24)
Organizing computations
51(10)
Organizing data
61(5)
Putting it all together
66(2)
Partitioning the grading program
68(2)
The revised grading program
70(1)
Details
71(4)
Using sequential containers and analyzing strings
75(26)
Separating students into categories
75(4)
Iterators
79(3)
Using iterators instead of indices
82(2)
Rethinking our data structure for better performance
84(1)
The list type
85(2)
Taking strings apart
87(3)
Testing our split function
90(1)
Putting strings together
91(5)
Details
96(5)
Using library algorithms
101(22)
Analyzing strings
101(9)
Comparing grading schemes
110(6)
Classifying students, revisited
116(4)
Algorithms, containers, and iterators
120(1)
Details
121(2)
Using associative containers
123(16)
Containers that support efficient look-up
123(1)
Counting words
124(2)
Generating a cross-reference table
126(3)
Generating sentences
129(7)
A note on performance
136(1)
Details
137(2)
Writing generic functions
139(16)
What is a generic function?
139(4)
Data-structure independence
143(7)
Input and output iterators
150(2)
Using iterators for flexibility
152(1)
Details
153(2)
Defining new types
155(14)
Student__info revisited
155(1)
Class types
156(4)
Protection
160(3)
The Student__info class
163(1)
Constructors
164(2)
Using the Student__info class
166(1)
Details
167(2)
Managing memory and low-level data structures
169(18)
Pointers and arrays
169(7)
String literals revisited
176(1)
Initializing arrays of character pointers
177(2)
Arguments to main
179(1)
Reading and writing files
180(2)
Three kinds of memory management
182(3)
Details
185(2)
Defining abstract data types
187(24)
The Vec class
187(1)
Implementing the Vec class
188(7)
Copy control
195(7)
Dynamic Vecs
202(1)
Flexible memory management
203(6)
Details
209(2)
Making class objects act like values
211(16)
A simple string class
212(1)
Automatic conversions
213(1)
Str operations
214(7)
Some conversions are hazardous
221(1)
Conversion operators
222(1)
Conversions and memory management
223(2)
Details
225(2)
Using inheritance and dynamic binding
227(26)
Inheritance
227(5)
Polymorphism and virtual functions
232(5)
Using inheritance to solve our problem
237(6)
A simple handle class
243(4)
Using the handle class
247(1)
Subtleties
248(2)
Details
250(3)
Managing memory (almost) automatically
253(16)
Handles that copy their objects
254(5)
Reference-counted handles
259(4)
Handles that let you decide when to share data
263(1)
An improvement on controllable handles
264(4)
Details
268(1)
Revisiting character pictures
269(22)
Design
269(9)
Implementation
278(10)
Details
288(3)
Where do we go from here?
291(4)
Use the abstractions you have
291(2)
Learn more
293(2)
Appendix A Language details 295(16)
A.1 Declarations
295(4)
A.2 Types
299(6)
A.3 Expressions
305(3)
A.4 Statements
308(3)
Appendix B Library summary 311(14)
B.1 Input--output
311(3)
B.2 Containers and iterators
314(7)
B.3 Algorithms
321(4)
Index 325

Excerpts

A new approach to C++ programming We assume that you want to learn quickly how to write useful C++ programs. Therefore, we start by explaining the most useful parts of C++. This strategy may seem obvious when we put it that way, but it has the radical implication that we do not begin by teaching C, even though C++ builds on C. Instead, we use high-level data structures from the start, explaining only later the foundations on which those data structures rest. This approach lets you to begin writing idiomatic C++ programs immediately.Our approach is unusual in another way: We concentrate on solving problems, rather than on exploring language and library features. We explain the features, of course, but we do so in order to support the programs, rather than using the programs as an excuse to demonstrate the features. Because this book teaches C++ programming, not just features, it is particularly useful for readers who already know some C++, and who want to use the language in a more natural, effective style. Too often, people new to C++ learn the language mechanics without learning how to apply the language to everyday problems. Our approach works--for beginners and experienced programmers We used to teach a week-long intensive C++ course every summer at Stanford University. We originally adopted a traditional approach to that course: Assuming that the students already knew C, we started by showing them how to define classes, and then moved systematically through the rest of the language. We found that our students would be confused and frustrated for about two days--until they had learned enough that they could start writing useful programs. Once they got to that point, they learned quickly. When we got our hands on a C++ implementation that supported enough of what was then the brand-new standard library, we overhauled the course. The new course used the library right from the beginning, concentrated on writing useful programs, and went into details only after the students had learned enough to use those details productively. The results were dramatic: After one day in the classroom, our students were able to write programs that had taken them most of the week in the old course. Moreover, their frustration vanished. Abstraction Our approach is possible only because C++, and our understanding of it, has had time to mature. That maturity has let us ignore many of the low-level ideas that were the mainstay of earlier C++ programs and programmers. The ability to ignore details is characteristic of maturing technologies. For example, early automobiles broke down so often that every driver had to be an amateur mechanic. It would have been foolhardy to go for a drive without knowing how to get back home even if something went wrong. Today's drivers don't need detailed engineering knowledge in order to use a car for transportation. They may wish to learn the engineering details for other reasons, but that's another story entirely. We define abstraction as selective ignorance--concentrating on the ideas that are relevant to the task at hand, and ignoring everything else--and we think that it is the most important idea in modern programming. The key to writing a successful program is knowing which parts of the problem to take into account, and which parts to ignore. Every programming langauge offers tools for creating useful abstractions, and every successful programmer knows how to use those tools. We think abstractions are so useful that we've filled this book with them. Of course, we don't usually call them abstractions directly, because they come

Rewards Program

Reviews for Accelerated C++ Practical Programming by Example (9780201703535)