(eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition instant download
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition instant download
https://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-through-objects-8th-edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-through-objects-brief-version-8th-
edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-objects-7th-edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-to-objects-9th-edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-data-structures-3rd-edition/
(eBook PDF) Starting Out with Java: From Control
Structures through Data Structures 4th Edition
http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-data-structures-4th-edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
early-objects-9th-edition/
http://ebooksecure.com/product/starting-out-with-c-early-
objects-9th-edition-by-tony-gaddis-ebook-pdf/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
early-objects-5th-edition/
http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
early-objects-5th-global-edition/
Contents
Preface xv
vii
viii Contents
CHAPTER 10 Characters, C-Strings, and More About the string Class 547
10.1 Character Testing 547
10.2 Character Case Conversion 551
10.3 C-Strings 554
10.4 Library Functions for Working with C-Strings 558
10.5 C-String/Numeric Conversion Functions 569
10.6 Focus on Software Engineering: Writing Your Own
C-String-Handling Functions 575
10.7 More About the C++ string Class 581
10.8 Focus on Problem Solving and Program Design: A Case Study 590
Welcome to Starting Out with C++: From Control Structures through Objects, 8th edition.
This book is intended for use in a two-semester C++ programming sequence, or an acceler-
ated one-semester course. Students new to programming, as well as those with prior course
work in other languages, will find this text beneficial. The fundamentals of programming
are covered for the novice, while the details, pitfalls, and nuances of the C++ language are
explored in-depth for both the beginner and more experienced student. The book is written
with clear, easy-to-understand language, and it covers all the necessary topics for an intro-
ductory programming course. This text is rich in example programs that are concise, practi-
cal, and real-world oriented, ensuring that the student not only learns how to implement the
features and constructs of C++, but why and when to use them.
xv
xvi Preface
● The range-based for loop is introduced in Chapter 7. This new looping mechanism
automatically iterates over each element of an array, vector, or other collection,
without the need of a counter variable or a subscript.
● Chapter 7 shows how a vector can be initialized with an initialization list.
● The nullptr key word is introduced as the standard way of representing a null
pointer.
● Smart pointers are introduced in Chapter 9, with an example of dynamic memory
allocation using unique_ptr.
● Chapter 10 discusses the new, overloaded to_string functions for converting numeric
values to string objects.
● The string class’s new back() and front() member functions are included in
Chapter 10’s overview of the string class.
● Strongly typed enums are discussed in Chapter 11.
● Chapter 13 shows how to use the smart pointer unique_ptr to dynamically allocate
an object.
● Chapter 15 discusses the override key word and demonstrates how it can help prevent
subtle overriding errors. The final key word is discussed as a way of preventing a virtual
member function from being overridden.
In addition to the C++11 topics, the following general improvements were made:
● Several new programming problems have been added to the text, and many of the
existing programming problems have been modified to make them unique from previ-
ous editions.
● The discussion of early, historic computers in Chapter 1 is expanded.
● The discussion of literal values in Chapter 2 is improved.
● The introduction of the char data type in Chapter 2 is reorganized to use character
literals in variable assignments before using ASCII values in variable assignments.
● The discussion of random numbers in Chapter 3 is expanded and improved, with the
addition of a new In the Spotlight section.
● A new Focus on Object-Oriented Programming section has been added to Chapter 13,
showing how to write a class that simulates dice.
● A new Focus on Object-Oriented Programming section has been added to Chapter 14,
showing an object-oriented program that simulates the game of Cho-Han. The program
uses objects for the dealer, two players, and a pair of dice.
Figure P-1
Chapter 1
Introduction
Chapters 2–7
Basic Language
Elements
*A few subtopics in
Chapter 12 require
Chapter 10 Chapters 9 and 11.
Characters, Strings, Chapter 11
and the string Class Structures
Chapter 13
Introduction to
Classes
Chapter 14
More About Classes
Chapter 15
Inheritance and
Polymorphism
Chapter 16
Exceptions,
Templates, and STL
Chapter 17
Linked Lists
Chapter 18 Chapter 19
Stacks and Queues Recursion
Chapter 20
Binary Trees
xviii Preface
Chapter 1 covers fundamental hardware, software, and programming concepts. You may
choose to skip this chapter if the class has already mastered those topics. Chapters 2 through
7 cover basic C++ syntax, data types, expressions, selection structures, repetition structures,
functions, and arrays. Each of these chapters builds on the previous chapter and should be
covered in the order presented.
After Chapter 7 has been covered, you may proceed to Chapter 8, or jump to either Chapter
9 or Chapter 12. (If you jump to Chapter 12 at this point, you will need to postpone sections
12.7, 12.8, and 12.10 until Chapters 9 and 11 have been covered.)
After Chapter 9 has been covered, either of Chapters 10 or 11 may be covered. After Chap-
ter 11, you may cover Chapters 13 through 17 in sequence. Next you can proceed to either
Chapter 18 or Chapter 19. Finally, Chapter 20 may be covered.
This text’s approach starts with a firm foundation in structured, procedural programming
before delving fully into object-oriented programming and advanced data structures.
Chapter 6: Functions
In this chapter the student learns how and why to modularize programs, using both void
and value returning functions. Argument passing is covered, with emphasis on when argu-
ments should be passed by value versus when they need to be passed by reference. Scope of
variables is covered, and sections are provided on local versus global variables and on static
local variables. Overloaded functions are also introduced and demonstrated.
Chapter 7: Arrays
In this chapter the student learns to create and work with single and multidimensional
arrays. Many examples of array processing are provided including examples illustrating
how to find the sum, average, highest, and lowest values in an array and how to sum the
rows, columns, and all elements of a two-dimensional array. Programming techniques using
parallel arrays are also demonstrated, and the student is shown how to use a data file as
an input source to populate an array. STL vectors are introduced and compared to arrays.
Chapter 9: Pointers
This chapter explains how to use pointers. Pointers are compared to and contrasted with
reference variables. Other topics include pointer arithmetic, initialization of pointers, rela-
tional comparison of pointers, pointers and arrays, pointers and functions, dynamic mem-
ory allocation, and more.
Chapter 10: Characters, C-strings, and More About the string Class
This chapter discusses various ways to process text at a detailed level. Library functions for
testing and manipulating characters are introduced. C-strings are discussed, and the tech-
nique of storing C-strings in char arrays is covered. An extensive discussion of the string
class methods is also given.
denominator (GCD), performing a binary search, and sorting (QuickSort). The classic Tow-
ers of Hanoi example is also presented. For students who need more challenge, there is a
section on exhaustive algorithms.
Appendix F: Namespaces
This appendix explains namespaces and their purpose. Examples showing how to define a
namespace and access its members are given.
Warnings Warnings are notes that caution the student about certain C++
features, programming techniques, or practices that can lead to
malfunctioning programs or lost data.
Case Studies Case studies that simulate real-world applications appear in
many chapters throughout the text. These case studies are de-
signed to highlight the major topics of the chapter in which they
appear.
Review Questions Each chapter presents a thorough and diverse set of review
and Exercises questions, such as fill-in-the-blank and short answer, that check
the student’s mastery of the basic material presented in the chap-
ter. These are followed by exercises requiring problem solving
and analysis, such as the Algorithm Workbench, Predict the Out-
put, and Find the Errors sections. Answers to the odd-numbered
review questions and review exercises can be downloaded from
the book’s Companion Web site at www.pearsonhighered.com/
gaddis.
Programming Each chapter offers a pool of programming exercises designed
Challenges to solidify the student’s knowledge of the topics currently being
studied. In most cases the assignments present real-world prob-
lems to be solved. When applicable, these exercises include input
validation rules.
Group Projects There are several group programming projects throughout the
text, intended to be constructed by a team of students. One
student might build the program’s user interface, while another
student writes the mathematical code, and another designs and
implements a class the program uses. This process is similar to
the way many professional programs are written and encourages
team work within the classroom.
Software Available for download from the book’s Companion Web site at
Development www.pearsonhighered.com/gaddis. This is an ongoing project
Project: that instructors can optionally assign to teams of students. It
Serendipity systematically develops a “real-world” software package: a
Booksellers point-of-sale program for the fictitious Serendipity Booksellers
organization. The Serendipity assignment for each chapter adds
more functionality to the software, using constructs and tech-
niques covered in that chapter. When complete, the program will
act as a cash register, manage an inventory database, and produce
a variety of reports.
C++ Quick For easy access, a quick reference guide to the C++ language is
Reference Guide printed on the last two pages of Appendix C in the book.
Supplements
Student Online Resources
Many student resources are available for this book from the publisher. The following items
are available on the Gaddis Series Companion Web site at www.pearsonhighered.com/gaddis:
● The source code for each example program in the book
● Access to the book’s companion VideoNotes
● A full set of appendices, including answers to the Checkpoint questions and answers
to the odd-numbered review questions
● A collection of valuable Case Studies
● The complete Serendipity Booksellers Project
Instructor Resources
The following supplements are available to qualified instructors only:
• Answers to all Review Questions in the text
• Solutions for all Programming Challenges in the text
• PowerPoint presentation slides for every chapter
• Computerized test bank
Another Random Scribd Document
with Unrelated Content
187 Pike, History of Crime in England, ii. 253. Blackstone,
Commentaries on the Laws of England, iv. 347, n. a.
194 Rüppell, Reise in Abyssinien, ii. 74, 81. von Heuglin, Reise
nach Abessinien, p. 213.
It has been said that the right of sanctuary bears testimony to the
power of certain places to transmit their virtues to those who
entered them.198 But we have no evidence that the fugitive is
supposed to partake of the sanctity of the place which shelters him.
In Morocco persons who are permanently attached to mosques or
the shrines of saints are generally regarded as more or less holy, but
this is never the case with casual visitors or suppliants; hence it is
hardly for fear of the refugee that his pursuer refrains from laying
hands on him. Professor Robertson Smith has stated part of the
truth in saying that “the assertion of a man’s undoubted rights as
against a fugitive at the sanctuary is regarded as an encroachment
on its holiness.”199 There is an almost instinctive fear not only of
shedding blood,200 but of disturbing the peace in a holy place; and if
it is improper to commit any act of violence in the house of another
man,201 it is naturally considered equally offensive, and also infinitely
more dangerous, to do so in the homestead of a supernatural being.
In the Tonga Islands, for instance, “it is forbidden to quarrel or fight
upon consecrated ground.”202 But this is only one aspect of the
matter; another, equally important, still calls for an explanation. Why
should the gods or saints themselves be so anxious to protect
criminals who have sought refuge in their sanctuaries? Why do they
not deliver them up to justice through their earthly representatives?
198 Granger, Worship of the Romans, p. 223 sq.
202 Mariner, Natives of the Tonga Islands, ii. 232. Cf. ibid. i. 227.
206 Krapf, Reisen in Ost-Afrika, ii. 132, n. * See also Schinz, op.
cit. p. 312 (Ovambo).
21 Ibid. p. 184.
24 Exodus, xx. 7.
25 Herzog-Plitt, Real-Encyklopädie für protestantische Theologie,
vi. 501 sq.
These taboos have sprung from fear. There is, first, something
uncanny in mentioning the name of a supernatural being, even apart
from any definite ideas connected with the act. But to do so is also
supposed to summon him or to attract his attention, and this may be
considered dangerous, especially if he is looked upon as malevolent
or irritable, as is generally the case with the Moorish jnûn. The
uncanny feeling or the notion of danger readily leads to the belief
that the supernatural being feels offended if his name is
pronounced; we have noticed a similar association of thought in
connection with the names of the dead. But a god may also have
good reason for wishing that his name should not be used lightly or
taken in vain. According to primitive ideas a person’s name is a part
of his personality, hence the holiness of a god may be polluted by his
name being mentioned in profane conversation. Moreover, it may be
of great importance for him to prevent his name from being
divulged, as magic may be wrought on a person through his name
just as easily as through any part of his body. In early civilisation
there is a common tendency to keep the real name of a human
individual secret so that sorcerers may not make an evil use of it;27
and it is similarly believed that gods must conceal their true names
lest other gods or men should be able to conjure with them.28 The
great Egyptian god Râ declared that the name which his father and
mother had given him remained hidden in his body since his birth,
so that no magician might have magic power over him.29 The list of
divine names possessed by the Roman pontiffs in their indigitamenta
was a magical instrument which laid at their mercy all the forces of
the spirit world;30 and we are told that the Romans kept the name of
their tutelary god secret in order to prevent their enemies from
drawing him away by pronouncing it.31 There is a Muhammedan
tradition that whosoever calls upon Allah by his “great name” will
obtain all his desires, being able merely by mentioning it to raise the
dead to life, to kill the living, in fact to perform any miracle he
pleases.32
27 Tylor, Early History of Mankind, p. 139 sqq. Andree,
Ethnographische Parallelen, p. 179 sqq. Frazer, Golden Bough, i.
403 sqq. Clodd, Tom Tit Tot, pp. 53–55, 81 sqq. Haddon, Magic
and Fetishism, p. 22 sq.
28 Tylor, op. cit. p. 124 sq. Frazer, op. cit. i. 443. Clodd, op. cit.
p. 173. Haddon, op. cit. p. 23 sqq.
39 Exodus, xx. 3, 5.
41 Exodus, xv. 3.
42 Koran, v. 73.
44 Niebuhr, Travels through Arabia, ii. 192, 189 sq. Cf. d’Arvieux,
Travels in Arabia the Desart, p. 123; Wallin, Notes taken during a
Journey through Northern Arabia, p. 21.
60 Lecky, op. cit. i. 408 sqq. Ramsay, The Church in the Roman
Empire, p. 346 sqq. See also supra, i. 345 sq.; ii. 178 sq.
65 Supra, i. 189.
66 Cf. Dorsey, ‘Omaha Sociology,’ in Ann. Rep. Bur. Ethn. iii. 364.
67 Rowley, Religion of the Africans, p. 125 sq. See also Kidd, The
Essential Kafir, p. 148.
73 Laws of Ḫammurabi, 1.
90 Supra, i. 52 sqq.
91 See Oldenberg, Die Religion des Veda, pp. 292, 296, 317 sq.
105 Oldenberg, op. cit. p. 311 sqq. Hopkins, op. cit. p. 149.
Roth, ‘Brahma und die Brahmanen,’ in Zeitschr. d. Deutschen
Morgenländischen Gesellsch. i. 67, 71. Darmesteter, Essais
orientaux, p. 132.
107 Roth, loc. cit. p. 66 sqq. Barth, op. cit. p. 38. Darmesteter,
Ormazd et Ahriman, p. 101.
115 Cf. von Lasaulx, Der Fluch bei Griechen und Römern, p. 6.
So also the Manx word gwee means both prayer and curse (Rhys,
Celtic Folklore, i. 349).