C++ For Dummies [NOOK Book]

Overview

This friendly guide is now updated to cover the latest ANSI C++ standard. Even if you're a programming newbie, you'll be building and debugging C++ programs, creating source code, developing C++ pointers, making programming easier with the exciting new Standard Template Library, and more -- all before you know it.
Read More Show Less
... See more details below
C++ For Dummies

Available on NOOK devices and apps  
  • Nook Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK Study
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$16.49
BN.com price
(Save 45%)$29.99 List Price
Note: This NOOK Book can be purchased in bulk. Please email us for more information.

Overview

This friendly guide is now updated to cover the latest ANSI C++ standard. Even if you're a programming newbie, you'll be building and debugging C++ programs, creating source code, developing C++ pointers, making programming easier with the exciting new Standard Template Library, and more -- all before you know it.
Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
Other languages get more ink nowadays. But C++ remains the workhorse in thousands (maybe millions) of programming shops. And it keeps getting better. One day, you will need to know it. Get ready, with C++ for Dummies, Fifth Edition.

Stephen Randy Davis assumes no prior knowledge -- of C++, C, or objects. He covers just about everything, from variables and math to memory management and stream I/O. All the book’s sample code is on CD-ROM, plus a complete C++ IDE.

Surprisingly, perhaps, this edition is nearly one-third new. You’ll find coverage of the new public domain C++ compiler, namespaces, and the latest updates to the ANSI and STL standards. The STL introduction will be invaluable to novice and experienced C++ programmers alike. Bill Camarda

Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2003 and Upgrading & Fixing Networks for Dummies, Second Edition.

Library Journal
C++ remains a strong contender among object-oriented programming languages (see Computer Media, LJ 6/1/03), and updated guides are always useful. C++ for Dummies assumes no previous programming experience, befitting the view of C++ as a foundational language. It includes source code, sample program, online help files, and the Dev-C++ compiler/editor on CD-ROM. Coverage ranges from how to enter, compile, and execute a program to using templates, while the "Part of Tens" sections at the end cover the most important optional features of Dev-C++ and ways to avoid adding bugs. A supplemental purchase to more thorough guides; for medium and larger libraries. Eschewing the basics, Art shows intermediate programmers the power of the language and how it applies to a range of programming tasks. Source code for sometimes extensive examples is available online. Extensive background and explanations-as well as an obvious enthusiasm for the language-make this a useful guide for those wanting to delve further. Recommended for larger libraries. Copyright 2004 Reed Business Information.
Read More Show Less

Product Details

  • ISBN-13: 9780470524121
  • Publisher: Wiley, John & Sons, Incorporated
  • Publication date: 4/20/2009
  • Series: For Dummies Series
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 6
  • Pages: 432
  • Sales rank: 117,053
  • File size: 2 MB

Meet the Author

Stephen R. Davis is the bestselling author of several books on C++, including previous editions of C++ For Dummies. He has been programming for more than 30 years and presently works for L-3 Communications in the area of Homeland Defense.
Read More Show Less

Read an Excerpt

Chapter 7
Object-Oriented Programming

In This Chapter

  • Making nachos
  • Overview of object-oriented programming
  • Introduction to abstraction and classification
  • Why is object-oriented programming important?

Okay, you've waited long enough. What, exactly, is object-oriented programming? Object-oriented programming, or OOP as those in the know prefer to call it, relies on two principles you learned before you ever got out of Pampers: abstraction and classification. To explain, let me tell you a little story.

Abstraction and Microwave Ovens

Sometimes when my son and I are watching football, I whip up a terribly unhealthy batch of nachos. I dump some chips on a plate, throw on some beans, cheese, and lots of jalapeños, and nuke the whole mess in the microwave oven for 5 minutes.

To use my microwave, I open the door, throw the stuff in, and punch a few buttons on the front. After a few minutes, the nachos are done. (I try not to stand in front of the microwave while it's working lest my eyes start glowing in the dark.)

Now think for a minute about all the things I don't do to use my microwave:

  • I don't rewire or change anything inside the microwave to get it to work. The microwave has an interface -- the front panel with all the buttons and the little time display -- that lets me do everything I need.
  • I don't have to reprogram the software used to drive the little processor inside my microwave, even if I cooked a different dish the last time I used the microwave.
  • I don't look inside the case of my microwave.
  • Even if I were a microwave designer and knew all about the inner workings of a microwave, including its software, I would still use it to heat my nachos without thinking about all that stuff.

These are not profound observations. You can think about only so much at one time. To reduce the number of things that you must deal with, you work at a certain level of detail. In object-oriented (OO) computerese, the level of detail at which you are working is called the level of abstraction. To introduce another OO term while I have the chance, I abstract away the details of the microwave's internals.

When I'm working on nachos, I view my microwave oven as a box. (As I'm trying to knock out a snack, I can't worry about the innards of the microwave oven and still follow the Cowboys on the tube.) As long as I use the microwave only through its interface (the keypad), there should be nothing I can do to cause the microwave to enter an inconsistent state and crash or, worse, turn my nachos into a blackened, flaming mass.

Functional nachos

Suppose I were to ask my son to write an algorithm for how Dad makes nachos. After he understood what I wanted, he would probably write "open a can of beans, grate some cheese, cut the jalapeños," and so on. When it came to the part about microwaving the concoction, he would write something like "cook in the microwave for 5 minutes."

That description is straightforward and complete. But it's not the way a functional programmer would code a program to make nachos. Functional programmers live in a world devoid of objects, such as microwave ovens and other appliances. They tend to worry about flow charts with their myriad functional paths. In a functional solution to the nachos problem, the flow of control would pass through my finger to the front panel and then to the internals of the microwave. Pretty soon, flow would be wiggling around through complex logic paths about how long to turn on the microwave tube and whether to sound the "come and get it" tone.

In a world like this, it's difficult to think in terms of levels of abstraction. There are no objects, no abstractions behind which to hide inherent complexity.

Object-oriented nachos

In an object-oriented approach to making nachos, I would first identify the types of objects in the problem: chips, beans, cheese, and an oven. Then I would begin the task of modeling these objects in software, without regard to the details of how they will be used in the final program.

While I am doing this, I'm said to be working (and thinking) at the level of the basic objects. I need to think about making a useful oven, but I don't have to think about the logical process of making nachos yet. After all, the microwave designers didn't think about the specific problem of my making a snack. Rather, they set about the problem of designing and building a useful microwave.

After the objects I need have been successfully coded and tested, I can ratchet up to the next level of abstraction. I can start thinking at the nacho-making level, rather than the microwave-making level. At this point, I can pretty much translate my son's instructions directly into C++ code.

Classification and Microwave Ovens

Critical to the concept of abstraction is that of classification. If I were to ask my son, "What's a microwave?" he would probably say, "It's an oven that...." If I then asked, "What's an oven?" he might reply, "It's a kitchen appliance that...." (If I then asked "What's a kitchen appliance?" he would probably say, "Why are you asking so many stupid questions?")

The answers my son gave in my example questioning stem from his understanding of our particular microwave as an example of the type of things called microwave ovens. In addition, my son sees microwave ovens as just a special type of oven, which is in turn a special type of kitchen appliance.

In object-oriented computerese, my microwave is an instance of the class microwave. The class microwave is a subclass of the class oven, and the class oven is a subclass of the class kitchen appliances.

Humans classify. Everything about our world is ordered into taxonomies. We do this to reduce the number of things we have to remember. Take, for example, the first time you saw a Saturn automobile. The advertisement called the Saturn "revolutionary, the likes of which have never been seen." But you and I know that that just isn't so. I like the looks of the Saturn, but hey, it's a car. As such, it shares all of (or at least most of) the properties of other cars. It has a steering wheel, seats, a motor, brakes, and so on. I bet I could even drive one without help.

I don't have to clutter my limited storage with all the things that a Saturn has in common with other cars. All I have to remember is "a Saturn is a car that..." and tack on those few things that are unique to a Saturn. I can go further. Cars are a subclass of wheeled vehicles, of which there are other members, such as trucks and pickups. Maybe wheeled vehicles are a subclass of vehicles, which include boats and planes. And on and on and on.

Why Classify?

True to form, one of the important questions I ask in this book is "Why?" Why do we want to classify? It sounds like a lot of trouble. (Besides, I've been programming the functional way for so long. Why do I need to change now?)

It may seem easier to design and build a microwave oven specifically for this one problem, rather than build a separate, more generic oven object. Suppose, for example, that I want to build a microwave to cook nachos and nachos only. There would be no need to put a front panel on it, other than a START button. I always cook nachos the same amount of time. I could dispense with all that DEFROST and TEMP COOK nonsense. It would need to hold only one flat little plate. Three cubic feet of space would be wasted on nachos.

For that matter, I can dispense with the concept of "microwave oven" altogether. All I really need is the guts of the oven. Then, in the recipe, I put the instructions to make it work: "Put nachos in the box. Connect the red wire to the black wire. Notice a slight hum. Try not to stand too close if you intend to have children." Stuff like that.

But the functional approach has some problems:

  • Too complex. I don't want the details of oven building mixed into the details of nacho building. If I can't define the objects and pull them out of the morass of details to deal with separately, I must deal with all the complexities of the problem at the same time.
  • Not flexible. Someday I may need to replace the microwave oven with some other type of oven. I should be able to do so as long as its interface is the same. Without being clearly delineated and developed separately, it becomes impossible to remove an object type cleanly and replace it with another.
  • Not reusable. Ovens are used to make lots of different dishes. I don't want to create a new oven every time I encounter a new recipe. Having solved a problem once, it would be nice to be able to reuse the solution in future programs.
Read More Show Less

Table of Contents

Introduction 1
Pt. I Introduction to C++ programming 7
Ch. 1 Writing your first C++ program 9
Ch. 2 Declaring variables constantly 27
Ch. 3 Performing mathematical operations 39
Ch. 4 Performing logical operations 47
Ch. 5 Controlling program flow 61
Pt. II Becoming a functional C++ programmer 77
Ch. 6 Creating functions 79
Ch. 7 Storing sequences in arrays 93
Ch. 8 Taking a first look at C++ pointers 109
Ch. 9 Taking a second look at C++ pointers 125
Ch. 10 Debugging C++ 139
Pt. III Introduction to classes 155
Ch. 11 Examining object-oriented programming 157
Ch. 12 Adding class to C++ 161
Ch. 13 Making classes work 167
Ch. 14 Point and stare at objects 183
Ch. 15 Protecting members : do not disturb 201
Ch. 16 "Why do you build me up, just to tear me down, baby?" 209
Ch. 17 Making constructive arguments 221
Ch. 18 Copying the copy copy copy constructor 239
Ch. 19 Static members : can fabric softener help? 251
Pt. IV Inheritance 259
Ch. 20 Inheriting a class 261
Ch. 21 Examining virtual member functions : are they for real? 269
Ch. 22 Factoring classes 279
Pt. V Optional features 303
Ch. 23 A new assignment operator, should you decide to accept it 305
Ch. 24 Using stream I/O 313
Ch. 25 Handling errors - exceptions 329
Ch. 26 Inheriting multiple inheritance 339
Ch. 27 Tempting C++ templates 351
Ch. 28 Standardizing on the standard template library 363
Pt. VI The part of Tens 375
Ch. 29 Ten ways to avoid adding bugs to your program 377
Ch. 30 The ten most important optional features of Dev-C++ 385
App: About the CD 393
Index 407
Read More Show Less

Customer Reviews

Average Rating 4
( 36 )
Rating Distribution

5 Star

(15)

4 Star

(11)

3 Star

(6)

2 Star

(1)

1 Star

(3)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
See All Sort by: Showing 1 – 20 of 36 Customer Reviews
  • Anonymous

    Posted September 26, 2009

    C++ with 2009 Standard

    C++ for Dummies is a needed volume. The impact of the 2009 Standard is covered in the book and is the prime reason I purchased the book. The standard offers some subtle changes. Various compilers purporting to provide 2009 Standard support do not supply enough information. This book does provide the information and ways to verify the Standard support is present. The rest of the book is C++ (not Candand as the request for review suggests) through and through with the author's insight into classes, inheritance and streaming I/O. I have not as yet tried all the examples on the CD but with the book and the compiler to use, I should have no problems. It has been a long time since the 5th edition came out and this book is a needed update. Hopefully the author will update his website to alert others to the presence of this book (the 6th edition). For the money, this book is a great value.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted April 6, 2012

    Not really helpful - Prefer a more advance book.

    This book does not give many examples and does a poor job showing getters and setters. If I could I would return the ebook and purchased a Deitel c++ book.

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 12, 2011

    Not bad

    I give it a C++

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 30, 2011

    Ok

    Its good but its sppose to have a CD that come whith it

    Was this review helpful? Yes  No   Report this review
  • Posted July 14, 2011

    A must have if...

    I'm in my repeat attempt at passing a class that teaches pseudo code and as a hidden benefit, we have to learn to translate it to C++. The text book doesn't teach C++, it teaches the aforementioned. This book came in so handy when I had to learn how to declare variables, how to start a program, how to assign values and so on. Yes, I'm at the basics.

    Never mind the title, the book is good!

    C

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted August 1, 2010

    Definitely for the C++ enthusiast

    If you're looking to dive into C++, this is the book for you. Stephen does a great job of elaborating and explaining why this happens when you do that, with a blissful amount of subtle humor.

    Awesomeness++;

    Was this review helpful? Yes  No   Report this review
  • Posted March 16, 2009

    more from this reviewer

    Both my teenage son and daughter enjoy this book.

    Both of my children enjoy this book and refer back to it when needed.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 2, 2009

    An incredible book for the beginning programmer.

    I've seen some bad reviews of this book, people saying that it's not a good starter, it's complex, it's only good for reference, etc, but I can't say I agree with these. I used this book to learn C++ as my first language, and I still say this is the best I've ever read. It's by no means an easy read, but it's definitely worth it. Since then, I've learned a few other languages (VB, VBA, Java, and Javascript) and the information and logic in this book has served me well through all of it. If you want to start programming and you're looking for a place to start, I can't think of anywhere but this book.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted August 27, 2007

    an okay reference

    I wouldn't recommend reading this book if you've never programmed before or you are searching for a primary readng book for learning C++. It's a good reference for C++ programmers but it is probably to hard for a beginner of programming to start with. Recommendeded ONLY if you need a reference. If you are new to programming, look up 'beginning programming' in the 'For dummies' series and Visual Basic 6 in the for dummies series as well, those are better starter books.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted August 25, 2006

    Covers Beginning Material, But Oh So Painfully

    This book covers the material it claims but there are multiple errors in the programs written in the book. This lack of attention to detail is found in the often confusing and imprecisely written explanations. I would recommend this book as a casual reference or supplimentary text but not as a primary source of studying C++.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 29, 2005

    AWESOME

    GOOD BOOK FOR BEGINNERS!!! BUY IT TO LEARN QUICK AND PAINLESSLY

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted September 25, 2004

    Not ANSI standards, don't waste your money

    This was the first C++ book I bought, and I regret it. The code is outdated, and not at standards for ANSI. Also, the author has a limited knowledge of C++ and there are several bits of false information. There are several useless lines of code in every program, and it's full of humorless jokes by the author. It's a poor guide, and should never be used to begin C++ programming. Do yourself and your wallet a favor: Buy something else.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 30, 2004

    Solid book - a great read

    I have had the opportunity to read a few books of this genre and this has been the best by far. As someone who formerly learned C++ a few years ago, but has not used it since, this book was the perfect review. It was light enough to be a good read (that in itself is hard to find in this genre), yet detailed enough to leave me confident as I take on a new adventure that assumes C++ knwoledge. I read the other reviews and agree that there are too many typos (in the text and the code samples alike) to give this book 5 stars. But I highly recommend this book for those who already know a language, e.g., C or Java, and therefore have enough of a coding base to recognize the typos and still get a lot out of the examples.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted July 19, 2003

    OK, but found a better book

    This book was OK. I had tried a few others, but all they did was cut-n- paste code examples and run the programs.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 21, 2003

    Good Book

    I had a little trouble when I started out in my C++ class our textbook wasn't very clear on many different topics, so I picked up this book and it helped me understand a lot of the topics much more clearer. Now programming with C++ is a breeze. I highly recomend this book.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted July 31, 2002

    Ok tutorial at best but has many bugs.

    Many better books out there. It leads you thru a bunch of programs while you try to learn C++. However, the book has many typos or bugs in the code which is terrible for a book of this sort.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 18, 2002

    Great Book

    I liked this book a lot. I had prior C knowledge, but I didn't know anything about more advanced topics, IE linked lists, polymorphism, and multiple inheritance. After reading this book it clearly taught me how to do all these things. Some of the code from the book didn't compile, which angered me, but Davis includes his email address in the book and he helped me on any question that I had. <p> The style of the book was also a good part of it. It wasn't boring or dull like so many computer manuals out there. This book is interesting and even made me laugh. <p> I suggest this book for anybody who wishes to program C++, no matter what your age is. It spells it out very easily.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 19, 2002

    Not very helpful

    I gave up halfway through the book. I got tired of all the errors and typos. The examples are not very good and the program code contains mistakes. Unfortunately most C++ books are like this.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 23, 2001

    Great book

    I thought this book was very helpfull. The way the author presents it makes it so almost any one can understand it. Although the directions for the compiler are a little sketchy. I managed on finding it and using it.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 22, 2001

    Getting an 'A'

    I purchased this book for my son who is a Junior in high school and taking C++ programming as an elective course. He was struggling with some of the concepts and I thought this book would augment his studies. Well, I'm happy to say that he has found this book to be a great companion to the course and he has brought a 'C' grade up to an 'A' grade. I cannot comment on the accompanying CD-ROM since we both have access to another development environment.

    Was this review helpful? Yes  No   Report this review
See All Sort by: Showing 1 – 20 of 36 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)