(eBook PDF) Starting Out with C++: From Control
Structures through Objects 8th Edition install
download
https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from-
control-structures-through-objects-8th-edition/
Download more ebook from https://ebookluna.com
Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...
(eBook PDF) Starting Out with C++: From Control Structures
through Objects, Brief Version 8th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from-
control-structures-through-objects-brief-version-8th-edition/
ebookluna.com
(eBook PDF) Starting Out with Java: From Control
Structures through Objects, 7th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-objects-7th-edition/
ebookluna.com
(eBook PDF) Starting Out with C++ from Control Structures
to Objects 9th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from-
control-structures-to-objects-9th-edition/
ebookluna.com
(eBook PDF) Starting Out with Java: From Control
Structures through Data Structures 3rd Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/
ebookluna.com
(eBook PDF) Starting Out with Java: From Control
Structures through Data Structures 4th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-4th-edition/
ebookluna.com
(eBook PDF) Starting Out with C++: Early Objects 9th
Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-c-early-
objects-9th-edition/
ebookluna.com
Starting Out with C++: Early Objects 9th Edition by Tony
Gaddis (eBook PDF)
https://ebookluna.com/product/starting-out-with-c-early-objects-9th-
edition-by-tony-gaddis-ebook-pdf/
ebookluna.com
(eBook PDF) Starting Out with Java: Early Objects 5th
Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-5th-edition/
ebookluna.com
(eBook PDF) Starting Out with Java: Early Objects 5th
Global Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-5th-global-edition/
ebookluna.com
Preface xv
CHAPTER 1 Introduction to Computers and Programming 1
1.1 Why Program? 1
1.2 Computer Systems: Hardware and Software 2
1.3 Programs and Programming Languages 8
1.4 What Is a Program Made of? 14
1.5 Input, Processing, and Output 17
1.6 The Programming Process 18
1.7 Procedural and Object-Oriented Programming 22
CHAPTER 2 Introduction to C++ 27
2.1 The Parts of a C++ Program 27
2.2 The cout Object 31
2.3 The #include Directive 36
2.4 Variables and Literals 37
2.5 Identifiers 41
2.6 Integer Data Types 42
2.7 The char Data Type 48
2.8 The C++ string Class 52
2.9 Floating-Point Data Types 54
2.10 The bool Data Type 57
2.11 Determining the Size of a Data Type 58
2.12 Variable Assignments and Initialization 59
2.13 Scope 61
2.14 Arithmetic Operators 61
2.15 Comments 69
2.16 Named Constants 71
2.17 Programming Style 73
vii
Contents
viii Contents
CHAPTER 3 Expressions and Interactivity 83
3.1 The cin Object 83
3.2 Mathematical Expressions 89
3.3 When You Mix Apples and Oranges: Type Conversion 98
3.4 Overflow and Underflow 100
3.5 Type Casting 101
3.6 Multiple Assignment and Combined Assignment 104
3.7 Formatting Output 108
3.8 Working with Characters and string Objects 118
3.9 More Mathematical Library Functions 124
3.10 Focus on Debugging: Hand Tracing a Program 130
3.11 Focus on Problem Solving: A Case Study 132
CHAPTER 4 Making Decisions 149
4.1 Relational Operators 149
4.2 The if Statement 154
4.3 Expanding the if Statement 162
4.4 The if/else Statement 166
4.5 Nested if Statements 169
4.6 The if/else if Statement 176
4.7 Flags 181
4.8 Logical Operators 182
4.9 Checking Numeric Ranges with Logical Operators 189
4.10 Menus 190
4.11 Focus on Software Engineering: Validating User Input 193
4.12 Comparing Characters and Strings 195
4.13 The Conditional Operator 199
4.14 The switch Statement 202
4.15 More About Blocks and Variable Scope 211
CHAPTER 5 Loops and Files 227
5.1 The Increment and Decrement Operators 227
5.2 Introduction to Loops: The while Loop 232
5.3 Using the while Loop for Input Validation 239
5.4 Counters 241
5.5 The do-while Loop 242
5.6 The for Loop 247
5.7 Keeping a Running Total 257
5.8 Sentinels 260
5.9 Focus on Software Engineering: Deciding Which Loop to Use 261
5.10 Nested Loops 262
5.11 Using Files for Data Storage 265
5.12 Optional Topics: Breaking and Continuing a Loop 284
CHAPTER 6 Functions 299
6.1 Focus on Software Engineering: Modular Programming 299
6.2 Defining and Calling Functions 300
6.3 Function Prototypes 309
6.4 Sending Data into a Function 311
Contents ix
6.5 Passing Data by Value 316
6.6 Focus on Software Engineering: Using Functions in a
Menu-Driven Program 318
6.7 The return Statement 322
6.8 Returning a Value from a Function 324
6.9 Returning a Boolean Value 332
6.10 Local and Global Variables 334
6.11 Static Local Variables 342
6.12 Default Arguments 345
6.13 Using Reference Variables as Parameters 348
6.14 Overloading Functions 354
6.15 The exit() Function 358
6.16 Stubs and Drivers 361
CHAPTER 7 Arrays 375
7.1 Arrays Hold Multiple Values 375
7.2 Accessing Array Elements 377
7.3 No Bounds Checking in C++ 384
7.4 Array Initialization 387
7.5 The Range-Based for Loop 392
7.6 Processing Array Contents 396
7.7 Focus on Software Engineering: Using Parallel Arrays 404
7.8 Arrays as Function Arguments 407
7.9 Two-Dimensional Arrays 418
7.10 Arrays with Three or More Dimensions 425
7.11 Focus on Problem Solving and Program Design: A Case Study 427
7.12 If You Plan to Continue in Computer Science: Introduction to the
STL vector 429
CHAPTER 8 Searching and Sorting Arrays 457
8.1 Focus on Software Engineering: Introduction to Search Algorithms 457
8.2 Focus on Problem Solving and Program Design: A Case Study 463
8.3 Focus on Software Engineering: Introduction to Sorting Algorithms 470
8.4 Focus on Problem Solving and Program Design: A Case Study 477
8.5 If You Plan to Continue in Computer Science: Sorting and
Searching vectors 485
CHAPTER 9 Pointers 495
9.1 Getting the Address of a Variable 495
9.2 Pointer Variables 497
9.3 The Relationship Between Arrays and Pointers 504
9.4 Pointer Arithmetic 508
9.5 Initializing Pointers 510
9.6 Comparing Pointers 511
9.7 Pointers as Function Parameters 513
9.8 Focus on Software Engineering: Dynamic Memory Allocation 522
9.9 Focus on Software Engineering: Returning Pointers from Functions 526
9.10 Using Smart Pointers to Avoid Memory Leaks 533
9.11 Focus on Problem Solving and Program Design: A Case Study 536
x 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
CHAPTER 11 Structured Data 599
11.1 Abstract Data Types 599
11.2 Focus on Software Engineering: Combining Data into Structures 601
11.3 Accessing Structure Members 604
11.4 Initializing a Structure 608
11.5 Arrays of Structures 611
11.6 Focus on Software Engineering: Nested Structures 613
11.7 Structures as Function Arguments 617
11.8 Returning a Structure from a Function 620
11.9 Pointers to Structures 623
11.10 Focus on Software Engineering: When to Use ., When to Use ->,
and When to Use * 626
11.11 Unions 628
11.12 Enumerated Data Types 632
CHAPTER 12 Advanced File Operations 657
12.1 File Operations 657
12.2 File Output Formatting 663
12.3 Passing File Stream Objects to Functions 665
12.4 More Detailed Error Testing 667
12.5 Member Functions for Reading and Writing Files 670
12.6 Focus on Software Engineering: Working with Multiple Files 678
12.7 Binary Files 680
12.8 Creating Records with Structures 685
12.9 Random-Access Files 689
12.10 Opening a File for Both Input and Output 697
CHAPTER 13 Introduction to Classes 711
13.1 Procedural and Object-Oriented Programming 711
13.2 Introduction to Classes 718
13.3 Defining an Instance of a Class 723
13.4 Why Have Private Members? 736
13.5 Focus on Software Engineering: Separating Class Specification
from Implementation 737
13.6 Inline Member Functions 743
13.7 Constructors 746
13.8 Passing Arguments to Constructors 750
Contents xi
13.9 Destructors 758
13.10 Overloading Constructors 762
13.11 Private Member Functions 765
13.12 Arrays of Objects 767
13.13 Focus on Problem Solving and Program Design: An OOP Case Study 771
13.14 Focus on Object-Oriented Programming: Simulating Dice with Objects 778
13.15 Focus on Object-Oriented Programming: Creating an Abstract Array
Data Type 782
13.16 Focus on Object-Oriented Design: The Unified Modeling Language (UML) 785
13.17 Focus on Object-Oriented Design: Finding the Classes and Their
Responsibilities 788
CHAPTER 14 More About Classes 811
14.1 Instance and Static Members 811
14.2 Friends of Classes 819
14.3 Memberwise Assignment 824
14.4 Copy Constructors 825
14.5 Operator Overloading 831
14.6 Object Conversion 858
14.7 Aggregation 860
14.8 Focus on Object-Oriented Design: Class Collaborations 865
14.9 Focus on Object-Oriented Programming: Simulating the Game
of Cho-Han 869
CHAPTER 15 Inheritance, Polymorphism, and Virtual Functions 891
15.1 What Is Inheritance? 891
15.2 Protected Members and Class Access 900
15.3 Constructors and Destructors in Base and Derived Classes 906
15.4 Redefining Base Class Functions 918
15.5 Class Hierarchies 923
15.6 Polymorphism and Virtual Member Functions 929
15.7 Abstract Base Classes and Pure Virtual Functions 945
15.8 Multiple Inheritance 952
CHAPTER 16 Exceptions, Templates, and the Standard Template
Library (STL) 971
16.1 Exceptions 971
16.2 Function Templates 990
16.3 Focus on Software Engineering: Where to Start When Defining Templates 996
16.4 Class Templates 996
16.5 Introduction to the Standard Template Library (STL) 1005
CHAPTER 17 Linked Lists 1025
17.1 Introduction to the Linked List ADT 1025
17.2 Linked List Operations 1027
17.3 A Linked List Template 1043
17.4 Variations of the Linked List 1055
17.5 The STL list Container 1056
xii Contents
CHAPTER 18 Stacks and Queues 1063
18.1 Introduction to the Stack ADT 1063
18.2 Dynamic Stacks 1080
18.3 The STL stack Container 1091
18.4 Introduction to the Queue ADT 1093
18.5 Dynamic Queues 1105
18.6 The STL deque and queue Containers 1112
CHAPTER 19 Recursion 1121
19.1 Introduction to Recursion 1121
19.2 Solving Problems with Recursion 1125
19.3 Focus on Problem Solving and Program Design: The Recursive
gcd Function 1133
19.4 Focus on Problem Solving and Program Design: Solving Recursively
Defined Problems 1134
19.5 Focus on Problem Solving and Program Design: Recursive Linked List
Operations 1135
19.6 Focus on Problem Solving and Program Design: A Recursive Binary
Search Function 1139
19.7 The Towers of Hanoi 1141
19.8 Focus on Problem Solving and Program Design: The QuickSort Algorithm 1144
19.9 Exhaustive Algorithms 1148
19.10 Focus on Software Engineering: Recursion vs. Iteration 1151
CHAPTER 20 Binary Trees 1155
20.1 Definition and Applications of Binary Trees 1155
20.2 Binary Search Tree Operations 1158
20.3 Template Considerations for Binary Search Trees 1175
Appendix A: Getting Started with Alice 1185
Appendix B: The ASCII Character Set 1211
Appendix C: Operator Precedence and Associativity 1213
Quick References 1215
Index 1217
Credit 1237
Online The following appendices are available at www.pearsonhighered.com/gaddis.
Appendix D: Introduction to Flowcharting
Appendix E: Using UML in Class Design
Appendix F: Namespaces
Appendix G: Passing Command Line Arguments
Appendix H: Header File and Library Function Reference
Appendix I: Binary Numbers and Bitwise Operations
Appendix J: Multi-Source File Programs
Appendix K: Stream Member Functions for Formatting
Appendix L: Answers to Checkpoints
Appendix M: Solutions to Odd-Numbered Review Questions
LOCATION OF VIDEONOTES IN THE TEXT
Chapter 1 Introduction to Flowcharting, p. 20
Designing a Program with Pseudocode, p. 20
Designing the Account Balance Program, p. 25
Predicting the Result of Problem 33, p. 26
Chapter 2 Using cout, p. 31
Variabe Definitions, p. 37
Assignment Statements and Simple Math Expressions, p. 62
Solving the Restaurant Bill Problem, p. 80
Chapter 3 Reading Input with cin, p. 83
Formatting Numbers with setprecision, p. 111
Solving the Stadium Seating Problem, p. 142
Chapter 4 The if Statement, p. 154
The if/else statement, p. 166
The if/else if Statement, p. 176
Solving the Time Calculator Problem, p. 221
Chapter 5 The while Loop, p. 232
The for Loop, p. 247
Reading Data from a File, p. 274
Solving the Calories Burned Problem, p. 293
Chapter 6 Functions and Arguments, p. 311
Value-Returnlng Functions, p. 324
Solving the Markup Problem, p. 366
Chapter 7 Accessing Array Elements With a Loop, p. 380
Passing an Array to a Function, p. 407
Solving the Chips and Salsa Problem, p. 448
Chapter 8 The Binary Search, p. 460
The Selection Sort, p. 474
Solving the Charge Account Validation Modification Problem, p. 492
Chapter 9 Dynamically Allocating an Array, p. 523
Solving the Pointer Rewrite Problem, p. 545
Chapter 10 Writing a C-String-Handling Function, p. 575
More About the string Class, p. 581
Solving the Backward String Problem, p. 594
(continued on the next page)
LOCATION OF VIDEONOTES IN THE TEXT (continued)
Chapter 11 Creating a Structure, p. 601
Passing a Structure to a Function, p. 617
Solving the Weather Statistics Problem, p. 652
Chapter 12 Passing File Stream Objects to Functions, p. 665
Working with Multiple Files, p. 678
Solving the File Encryption Filter Problem, p. 708
Chapter 13 Writing a Class, p. 718
Defining an Instance of a Class, p. 723
Solving the Employee Class Problem, p. 802
Chapter 14 Operator Overloading, p. 831
Class Aggregation, p. 860
Solving the NumDays Problem, p. 885
Chapter 15 Redefining a Base Class Function in a Derived Class, p. 918
Polymorphism, p. 929
Solving the Employee and Production-Worker Classes Problem, p. 963
Chapter 16 Throwing an Exception, p. 972
Handling an Exception, p. 972
Writing a Function Template, p. 990
Storing Objects in a vector, p. 1010
Solving the Exception Project Problem, p. 1024
Chapter 17 Appending a Node to a Linked List, p. 1028
Inserting a Node in a Linked List, p. 1035
Deleting a Node from a Linked List, p. 1039
Solving the Member Insertion by Position Problem, p. 1061
Chapter 18 Storing Objects in an STL stack, p. 1091
Storing Objects in an STL queue, p. 1114
Solving the File Compare Problem, p. 1119
Chapter 19 Reducing a Problem with Recursion, p. 1126
Solving the Recursive Multiplication Problem, p. 1153
Chapter 20 Inserting a Node in a Binary Tree, p. 1160
Deleting a Node from a Binary Tree, p. 1166
Solving the Node Counter Problem, p. 1182
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.
Changes in the Eighth Edition
C++11 is the latest standard version of the C++ language. In previous years, while the stan-
dard was being developed, it was known as C++0x. In August 2011, it was approved by
the International Standards Organization (ISO), and the name of the standard was officially
changed to C++11. Most of the popular compilers now support the C++11 standard.
The new C++11 standard was the primary motivation behind this edition. Although this
edition introduces many of the new language features, a C++11 compiler is not strictly
required to use the book. As you progress through the book, you will see C++11 icons in the
margins, next to the new features that are introduced. Programs appearing in sections that
are not marked with this icon will still compile using an older compiler.
Here is a summary of the new C++11 topics that are introduced in this edition:
● The auto key word is introduced as a way to simplify complex variable definitions.
The auto key word causes the compiler to infer a variable’s data type from its initial-
ization value.
● The long long int and unsigned long long int data types, and the LL literal
suffix are introduced.
● Chapter 5 shows how to pass a string object directly to a file stream object’s open
member function, without the need to call the c_str() member function. (A discus-
sion of the c_str()function still exists for anyone using a legacy compiler.)
Preface
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.
Organization of the Text
This text teaches C++ in a step-by-step fashion. Each chapter covers a major set of topics
and builds knowledge as the student progresses through the book. Although the chapters
can be easily taught in their existing sequence, some flexibility is provided. The diagram
shown in Figure P-1 suggests possible sequences of instruction.
Preface xvii
Chapter 8
Searching and
Sorting Arrays
Chapter 9
Pointers
Chapter 10
Characters, Strings,
and the string Class
Chapter 12
Advanced File
Operations*
Chapter 20
Binary Trees
Chapters 2–7
Basic Language
Elements
Chapter 11
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
Stacks and Queues
Chapter 19
Recursion
*A few subtopics in
Chapter 12 require
Chapters 9 and 11.
Chapter 1
Introduction
Figure P-1
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.
Brief Overview of Each Chapter
Chapter 1: Introduction to Computers and Programming
This chapter provides an introduction to the field of computer science and covers the fun-
damentals of programming, problem solving, and software design. The components of pro-
grams, such as key words, variables, operators, and punctuation are covered. The tools of
the trade, such as pseudocode, flow charts, and hierarchy charts are also presented.
Chapter 2: Introduction to C++
This chapter gets the student started in C++ by introducing data types, identifiers, vari-
able declarations, constants, comments, program output, simple arithmetic operations, and
C-strings. Programming style conventions are introduced and good programming style
is modeled here, as it is throughout the text. An optional section explains the difference
between ANSI standard and pre-standard C++ programs.
Chapter 3: Expressions and Interactivity
In this chapter the student learns to write programs that input and handle numeric, char-
acter, and string data. The use of arithmetic operators and the creation of mathematical
expressions are covered in greater detail, with emphasis on operator precedence. Debug-
ging is introduced, with a section on hand tracing a program. Sections are also included on
simple output formatting, on data type conversion and type casting, and on using library
functions that work with numbers.
Chapter 4: Making Decisions
Here the student learns about relational operators, relational expressions and how to con-
trol the flow of a program with the if, if/else, and if/else if statements. The condi-
tional operator and the switch statement are also covered. Crucial applications of these
constructs are covered, such as menu-driven programs and the validation of input.
Preface xix
Chapter 5: Loops and Files
This chapter covers repetition control structures. The while loop, do-while loop, and for
loop are taught, along with common uses for these devices. Counters, accumulators, run-
ning totals, sentinels, and other application-related topics are discussed. Sequential file I/O
is also introduced. The student learns to read and write text files, and use loops to process
the data in a file.
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 8: Sorting and Searching Arrays
Here the student learns the basics of sorting arrays and searching for data stored in them.
The chapter covers the Bubble Sort, Selection Sort, Linear Search, and Binary Search algo-
rithms. There is also a section on sorting and searching STL vector objects.
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.
Chapter 11: Structured Data
The student is introduced to abstract data types and taught how to create them using struc-
tures, unions, and enumerated data types. Discussions and examples include using pointers
to structures, passing structures to functions, and returning structures from functions.
xx Preface
Chapter 12: Advanced File Operations
This chapter covers sequential access, random access, text, and binary files. The various
modes for opening files are discussed, as well as the many methods for reading and writing
file contents. Advanced output formatting is also covered.
Chapter 13: Introduction to Classes
The student now shifts focus to the object-oriented paradigm. This chapter covers the fun-
damental concepts of classes. Member variables and functions are discussed. The student
learns about private and public access specifications, and reasons to use each. The topics of
constructors, overloaded constructors, and destructors are also presented. The chapter pres-
ents a section modeling classes with UML and how to find the classes in a particular problem.
Chapter 14: More About Classes
This chapter continues the study of classes. Static members, friends, memberwise assign-
ment, and copy constructors are discussed. The chapter also includes in-depth sections on
operator overloading, object conversion, and object aggregation. There is also a section on
class collaborations and the use of CRC cards.
Chapter 15: Inheritance, Polymorphism, and Virtual Functions
The study of classes continues in this chapter with the subjects of inheritance, polymor-
phism, and virtual member functions. The topics covered include base and derived class con-
structors and destructors, virtual member functions, base class pointers, static and dynamic
binding, multiple inheritance, and class hierarchies.
Chapter 16: Exceptions, Templates, and the Standard
Template Library (STL)
The student learns to develop enhanced error trapping techniques using exceptions. Discus-
sion then turns to function and class templates as a method for reusing code. Finally, the
student is introduced to the containers, iterators, and algorithms offered by the Standard
Template Library (STL).
Chapter 17: Linked Lists
This chapter introduces concepts and techniques needed to work with lists. A linked list
ADT is developed and the student is taught to code operations such as creating a linked list,
appending a node, traversing the list, searching for a node, inserting a node, deleting a node,
and destroying a list. A linked list class template is also demonstrated.
Chapter 18: Stacks and Queues
In this chapter the student learns to create and use static and dynamic stacks and queues. The
operations of stacks and queues are defined, and templates for each ADT are demonstrated.
Chapter 19: Recursion
This chapter discusses recursion and its use in problem solving. A visual trace of recursive
calls is provided, and recursive applications are discussed. Many recursive algorithms are
presented, including recursive functions for finding factorials, finding a greatest common
Preface xxi
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.
Chapter 20: Binary Trees
This chapter covers the binary tree ADT and demonstrates many binary tree operations. The
student learns to traverse a tree, insert an element, delete an element, replace an element, test
for an element, and destroy a tree.
Appendix A: Getting Started with Alice
This appendix gives a quick introduction to Alice. Alice is free software that can be used to
teach fundamental programming concepts using 3D graphics.
Appendix B: ASCII Character Set
A list of the ASCII and Extended ASCII characters and their codes.
Appendix C: Operator Precedence and Associativity
A chart showing the C++ operators and their precedence.
The following appendices are available online at www.pearsonhighered.com/gaddis.
Appendix D: Introduction to Flowcharting
A brief introduction to flowcharting. This tutorial discusses sequence, selection, case, repeti-
tion, and module structures.
Appendix E: Using UML in Class Design
This appendix shows the student how to use the Unified Modeling Language to design
classes. Notation for showing access specification, data types, parameters, return values,
overloaded functions, composition, and inheritance are included.
Appendix F: Namespaces
This appendix explains namespaces and their purpose. Examples showing how to define a
namespace and access its members are given.
Appendix G: Passing Command Line Arguments
Teaches the student how to write a C++ program that accepts arguments from the command
line. This appendix will be useful to students working in a command line environment, such
as Unix, Linux, or the Windows command prompt.
Appendix H: Header File and Library Function Reference
This appendix provides a reference for the C++ library functions and header files discussed
in the book.
Appendix I: Binary Numbers and Bitwise Operations
A guide to the C++ bitwise operators, as well as a tutorial on the internal storage of integers.
xxii Preface
Appendix J: Multi-Source File Programs
Provides a tutorial on creating programs that consist of multiple source files. Function
header files, class specification files, and class implementation files are discussed.
Appendix K: Stream Member Functions for Formatting
Covers stream member functions for formatting such as setf.
Appendix L: Answers to Checkpoints
Students may test their own progress by comparing their answers to the checkpoint exer-
cises against this appendix. The answers to all Checkpoints are included.
Appendix M: Solutions to Odd-Numbered Review Questions
Another tool that students can use to gauge their progress.
Features of the Text
Concept Each major section of the text starts with a concept statement.
Statements This statement summarizes the ideas of the section.
Example Programs The text has hundreds of complete example programs, each
designed to highlight the topic currently being studied. In most
cases, these are practical, real-world examples. Source code for
these programs is provided so that students can run the programs
themselves.
Program Output After each example program there is a sample of its screen
output. This immediately shows the student how the program
should function.
In the Spotlight Each of these sections provides a programming problem and a
detailed, step-by-step analysis showing the student how to
solve it.
VideoNotes A series of online videos, developed specifically for this book, is
available for viewing at www.pearsonhighered.com/gaddis.
Icons appear throughout the text alerting the student to videos
about specific topics.
Checkpoints Checkpoints are questions placed throughout each chapter as
a self-test study aid. Answers for all Checkpoint questions can
be downloaded from the book’s Companion Web site at www.
pearsonhighered.com/gaddis. This allows students to check how
well they have learned a new topic.
Notes Notes appear at appropriate places throughout the text. They are
short explanations of interesting or often misunderstood points
relevant to the topic at hand.
Preface xxiii
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.
C++11 Throughout the text, new C++11 language features are
introduced. Look for the C++11 icon to find these new features.
11
11
xxiv Preface
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
Integrated Development Environment (IDE) Resource Kits
Professors who adopt this text can order it for students with a kit containing five popular
C++ IDEs (Microsoft® Visual Studio Express Edition, Dev C++, NetBeans, Eclipse, and
CodeLite) and access to a Web site containing written and video tutorials for getting started
in each IDE. For ordering information, please contact your campus Pearson Education rep-
resentative or visit www.pearsonhighered.com/cs.
Online Practice and Assessment with MyProgrammingLab
MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of pro-
gramming. Through practice exercises and immediate, personalized feedback, MyProgram-
mingLab improves the programming competence of beginning students who often struggle
with the basic concepts and paradigms of popular high-level programming languages.
A self-study and homework tool, a MyProgrammingLab course consists of hundreds of
small practice exercises organized around the structure of this textbook. For students, the
system automatically detects errors in the logic and syntax of their code submissions and
offers targeted hints that enable students to figure out what went wrong—and why. For
instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the
code inputted by students for review.
MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the
makers of the CodeLab interactive programming exercise system. For a full demonstration,
to see feedback from instructors and students, or to get started using MyProgrammingLab
in your course, visit www.myprogramminglab.com.
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
Other documents randomly have
different content
13. Give an account of the troubles with the Nez Percé
Indians.
14. Give the leading Congressional measures of these four
years.
15. Tell about General Grant's tour around the world.
CHAPTER LIII.
16. Give an account of the presidency and death of Garfield.
17. Outline the presidency of Arthur and the progress of
applied science during his term of office.
CHAPTER LIV.
18. State the general condition and trace the measures of
Cleveland's administration.
19. Tell about the Charleston earthquake.
20. What great leaders of the Civil War died during these four
years?
CHAPTER LV.
21. Give an account of the election of President Harrison, and
of his entrance upon office.
22. Summarize the leading events which have occurred during
his administration.
APPENDIX.
CONSTITUTION OF THE UNITED STATES.
We, the People of the United States, in order to form a more perfect
union, establish justice, insure domestic tranquillity, provide for the
common defense, promote the general welfare, and secure the
blessings of liberty to ourselves and our posterity, do ordain and
establish this Constitution for the United States of North America.
ARTICLE I.
Section 1.—All legislative powers herein granted shall be vested in a
Congress of the United States, which shall consist of a Senate and
House of Representatives.
Sec. 2.—The House of Representatives shall be composed of
members chosen every second year by the people of the several
States, and the electors in each State shall have the qualifications
requisite for electors of the most numerous branch of the State
legislature.
No person shall be a representative who shall not have attained to
the age of twenty-five years, and been seven years a citizen of the
United States, and who shall not, when elected, be an inhabitant of
that State in which he shall be chosen.
Representatives and direct taxes shall be apportioned among the
several States which may be included within this Union, according to
their respective numbers, which shall be determined by adding to
the whole number of free persons, including those bound to service
for a term of years, and excluding Indians not taxed, three fifths of
all other persons. The actual enumeration shall be made within three
years after the first meeting of the Congress of the United States,
and within every subsequent term of ten years, in such manner as
they shall by law direct. The number of representatives shall not
exceed one for every thirty thousand; but each State shall have at
least one representative; and until such enumeration shall be made,
the State of New Hampshire shall be entitled to choose three;
Massachusetts, eight; Rhode Island and Providence Plantations, one;
Connecticut, five; New York, six; New Jersey, four; Pennsylvania,
eight; Delaware, one; Maryland, six; Virginia, ten; North Carolina,
five; South Carolina, five; and Georgia, three.
When vacancies happen in the representation from any State, the
executive authority thereof shall issue writs of election to fill such
vacancies.
The House of Representatives shall choose their speaker and other
officers; and shall have the sole power of impeachment.
Sec. 3.—The Senate of the United States shall be composed of two
senators from each State, chosen by the legislature thereof, for six
years; and each senator shall have one vote.
Immediately after they shall be assembled in consequence of the
first election, they shall be divided, as equally as may be, into three
classes. The seats of the senators of the first class shall be vacated
at the expiration of the second year; of the second class, at the
expiration of the fourth year; and of the third class at the expiration
of the sixth year, so that one third may be chosen every second
year; and if vacancies happen, by resignation or otherwise, during
the recess of the legislature of any State, the executive thereof may
make temporary appointments until the next meeting of the
legislature which shall then fill such vacancies.
No person shall be a senator who shall not have attained to the age
of thirty years, and been nine years a citizen of the United States,
and who shall not, when elected, be an inhabitant of that State for
which he shall be chosen.
The Vice-president of the United States shall be president of the
Senate, but shall have no vote, unless they be equally divided.
The Senate shall choose their other officers, and also a president pro
tempore, in the absence of the Vice-president, or when he shall
exercise the office as President of the United States.
The Senate shall have the sole power to try all impeachments. When
sitting for that purpose, they shall be on oath or affirmation. When
the President of the United States is tried, the chief-justice shall
preside; and no person shall be convicted without the concurrence
of two thirds of the members present.
Judgment, in cases of impeachment, shall not extend further than to
removal from office, and disqualification to hold and enjoy any office
of honor, trust, or profit under the United States; but the party
convicted shall, nevertheless, be liable and subject to indictment,
trial, judgment, and punishment, according to law.
Sec. 4.—The times, places, and manner of holding elections for
senators and representatives shall be prescribed in each State by the
legislature thereof; but the Congress may, at any time, by law, make
or alter such regulations, except as to the places of choosing
senators.
The Congress shall assemble at least once in every year; and such
meeting shall be on the first Monday in December, unless they shall
by law appoint a different day.
Sec. 5.—Each house shall be the judge of the elections, returns, and
qualifications of its own members; and a majority of each shall
constitute a quorum to do business; but a smaller number may
adjourn from day to day, and may be authorized to compel the
attendance of absent members, in such manner and under such
penalties as each house may provide.
Each house may determine the rules of its proceedings, punish its
members for disorderly behavior, and, with the concurrence of two
thirds, expel a member.
Each house shall keep a journal of its proceedings, and from time to
time publish the same, excepting such parts as may in their
judgment require secrecy; and the yeas and nays of the members of
either house, on any question, shall, at the desire of one fifth of
those present, be entered on the journal.
Neither house, during the session of Congress, shall, without the
consent of the other, adjourn for more than three days, nor to any
other place than that in which the two houses shall be sitting.
Sec. 6.—The senators and representatives shall receive a
compensation for their services, to be ascertained by law, and paid
out of the treasury of the United States. They shall, in all cases
except treason, felony, and breach of the peace, be privileged from
arrest during their attendance on the session of their respective
houses, and in going to and returning from the same; and, for any
speech or debate in either house, they shall not be questioned in
any other place.
No senator or representative shall, during the time for which he was
elected, be appointed to any civil office under the authority of the
United States which shall have been created, or the emoluments
whereof shall have been increased, during such time; and no person
holding any office under the United States shall be a member of
either house during his continuance in office.
Sec. 7.—All bills for raising revenue shall originate in the House of
Representatives; but the Senate may propose or concur with
amendments, as on other bills.
Every bill which shall have passed the House of Representatives and
the Senate, shall, before it become a law, be presented to the
President of the United States; if he approve he shall sign it; but if
not, he shall return it, with his objections, to that house in which it
shall have originated, who shall enter the objections at large on their
journal, and proceed to reconsider it. If, after such reconsideration,
two thirds of that house shall agree to pass the bill, it shall be sent,
together with the objections, to the other house, by which it shall
likewise be reconsidered, and, if approved by two thirds of that
house, it shall become a law. But, in all such cases, the votes of both
houses shall be determined by yeas and nays; and the names of the
persons voting for and against the bill shall be entered on the
journal of each house respectively. If any bill shall not be returned
by the President within ten days (Sundays excepted) after it shall
have been presented to him, the same shall be a law in like manner
as if he had signed it, unless the Congress by their adjournment
prevent its return, in which case it shall not be a law.
Every order, resolution, or vote, to which the concurrence of the
Senate and House of Representatives may be necessary (except on
a question of adjournment), shall be presented to the President of
the United States; and, before the same shall take effect, shall be
approved by him, or, being disapproved by him, shall be repassed by
two thirds of the Senate and House of Representatives, according to
the rules and limitations prescribed in the case of a bill.
Sec. 8.—The Congress shall have power:—
To lay and collect taxes, duties, imposts, and excises, to pay the
debts, and provide for the common defense and general welfare, of
the United States; but all duties, imposts, and excises shall be
uniform throughout the United States:
To borrow money on the credit of the United States:
To regulate commerce with foreign nations, and among the several
States, and with the Indian tribes:
To establish a uniform rule of naturalization, and uniform laws on the
subject of bankruptcies throughout the United States:
To coin money, regulate the value thereof, and of foreign coin, and
fix the standard of weights and measures:
To provide for the punishment of counterfeiting the securities and
current coin of the United States:
To establish post-offices and post-roads:
To promote the progress of science and useful arts, by securing for
limited times, to authors and inventors, the exclusive right to their
respective writings and discoveries:
To constitute tribunals inferior to the Supreme Court:
To define and punish piracies and felonies committed on the high
seas, and offenses against the law of nations:
To declare war, grant letters of marque and reprisal, and make rules
concerning captures on land and water:
To raise and support armies; but no appropriation of money to that
use shall be for a longer term than two years:
To provide and maintain a navy:
To make rules for the government and regulation of the land and
naval forces:
To provide for calling forth the militia to execute the laws of the
Union, suppress insurrections, and repel invasions:
To provide for organizing, arming, and disciplining the militia, and for
governing such part of them as may be employed in the service of
the United States, reserving to the States respectively the
appointment of the officers, and the authority of training the militia
according to the discipline prescribed by Congress:
To exercise exclusive legislation, in all cases whatsoever, over such
district (not exceeding ten miles square) as may, by cession of
particular States, and the acceptance of Congress, become the seat
of government of the United States, and to exercise like authority
over all places purchased by the consent of the legislature of the
State in which the same shall be, for the erection of forts,
magazines, arsenals, dockyards, and other needful buildings:—And
To make all laws which shall be necessary and proper for carrying
into execution the foregoing powers, and all other powers vested by
this Constitution in the government of the United States, or in any
department or officer thereof.
Sec. 9.—The migration or importation of such persons, as any of the
States now existing shall think proper to admit, shall not be
prohibited by the Congress prior to the year one thousand eight
hundred and eight; but a tax, or duty, may be imposed on such
importation, not exceeding ten dollars for each person.
The privilege of the writ of habeas corpus shall not be suspended,
unless when in cases of rebellion or invasion the public safety may
require it.
No bill of attainder or ex post facto law shall be passed.
No capitation or other direct tax shall be laid, unless in proportion to
the census, or enumeration, hereinbefore directed to be taken.
No tax or duty shall be laid on articles exported from any State. No
preference shall be given by any regulation of commerce or revenue
to the ports of one State over those of another; nor shall vessels
bound to or from one State be obliged to enter, clear, or pay duties,
in another.
No money shall be drawn from the treasury but in consequence of
appropriations made by law; and a regular statement and account of
the receipts and expenditures of all public money shall be published
from time to time.
No title of nobility shall be granted by the United States; and no
person holding any office of profit or trust under them shall, without
the consent of the Congress, accept of any present, emolument,
office, or title of any kind whatever, from any king, prince, or foreign
state.
Sec. 10.—No state shall enter into any treaty, alliance, or
confederation; grant letters of marque and reprisal; coin money;
emit bills of credit; make any thing but gold and silver coin a tender
in payment of debts; pass any bill of attainder, ex post facto law, or
law impairing the obligation of contracts; or grant any title of
nobility.
No State shall, without the consent of the Congress, lay any imposts
or duties on imports or exports, except what may be absolutely
necessary for executing its inspection laws; and the net produce of
all duties and imposts laid by any State on imports or exports, shall
be for the use of the treasury of the United States; and all such laws
shall be subject to the revision and control of the Congress. No State
shall, without the consent of Congress, lay any duty of tonnage,
keep troops or ships of war in time of peace, enter into any
agreement or compact with another State or with a foreign power, or
engage in war, unless actually invaded, or in such imminent danger
as will not admit of delay.
ARTICLE II.
Section 1.—The executive power shall be vested in a President of the
United States of America. He shall hold his office during the term of
four years, and together with the Vice-president, chosen for the
same term, be elected as follows:—
Each State shall appoint, in such manner as the legislature thereof
may direct, a number of electors equal to the whole number of
senators and representatives to which the State may be entitled in
the Congress; but no senator or representative, or person holding an
office of trust or profit under the United States, shall be appointed
an elector.
The electors shall meet in their respective States, and vote by ballot
for two persons, of whom one, at least, shall not be an inhabitant of
the same State with themselves. And they shall make a list of all the
persons voted for, and of the number of votes for each; which list
they shall sign and certify, and transmit sealed to the seat of the
government of the United States, directed to the president of the
Senate. The president of the Senate shall, in the presence of the
Senate and House of Representatives, open all the certificates; and
the votes shall then be counted. The person having the greatest
number of votes shall be the President, if such number be a majority
of the whole number of electors appointed; and if there be more
than one who have such majority, and have an equal number of
votes, then the House of Representatives shall immediately choose,
by ballot, one of them for President; and if no person have a
majority, then, from the five highest on the list, the said house shall,
in like manner, choose the President. But, in choosing the President,
the votes shall be taken by States, the representation from each
State having one vote; a quorum for this purpose shall consist of a
member or members from two thirds of the States; and a majority of
all the States shall be necessary to a choice. In every case, after the
choice of the President, the person having the greatest number of
votes of the electors shall be Vice-president. But, if there should
remain two or more who have equal votes, the Senate shall choose
from them, by ballot, the Vice-president.
The Congress may determine the time of choosing the electors, and
the day on which they shall give their votes; which day shall be the
same throughout the United States.
No person except a natural born citizen, or a citizen of the United
States at the time of the adoption of this Constitution, shall be
eligible to the office of President; neither shall any person be eligible
to that office who shall not have attained to the age of thirty-five
years, and been fourteen years a resident within the United States.
In case of the removal of the President from office, or of his death,
resignation, or inability to discharge the powers or duties of the said
office, the same shall devolve on the Vice-president; and the
Congress may, by law, provide for the case of removal, death,
resignation, or inability, both of the President and Vice-president,
declaring what officer shall then act as President; and such officer
shall act accordingly, until the disability be removed, or a President
shall be elected.
The President shall, at stated times, receive for his services a
compensation, which shall neither be increased nor diminished
during the period for which he shall have been elected; and he shall
not receive within that period any other emolument from the United
States or any of them.
Before he enter on the execution of his office, he shall take the
following oath or affirmation:—
"I do solemnly swear (or affirm), that I will faithfully execute the
office of President of the United States, and will, to the best of my
ability, preserve, protect, and defend the Constitution of the United
States."
Sec. 2.—The President shall be commander-in-chief of the army and
navy of the United States, and of the militia of the several States,
when called into the actual service of the United States; he may
require the opinion, in writing, of the principal officer in each of the
executive departments, upon any subject relating to the duties of
their respective offices, and he shall have power to grant reprieves
and pardons for offenses against the United States, except in cases
of impeachment.
He shall have power, by and with the advice and consent of the
Senate, to make treaties, provided two thirds of the senators present
concur; and he shall nominate, and by and with the advice and
consent of the Senate, shall appoint, ambassadors, other public
ministers, and consuls, judges of the Supreme Court, and all other
officers of the United States, whose appointments are not herein
otherwise provided for, and which shall be established by law; but
the Congress may, by law, vest the appointment of such inferior
officers as they think proper, in the President alone, in the courts of
law, or in the heads of departments.
The President shall have power to fill up all vacancies that may
happen during the recess of the Senate, by granting commissions,
which shall expire at the end of their next session.
Sec. 3.—He shall, from time to time, give to the Congress
information of the state of the Union, and recommend to their
consideration such measures as he shall judge necessary and
expedient; he may, on extraordinary occasions, convene both
houses, or either of them, and, in case of disagreement between
them with respect to the time of adjournment, he may adjourn them
to such time as he shall think proper; he shall receive ambassadors
and other public ministers; he shall take care that the laws be
faithfully executed; and shall commission all the officers of the
United States.
Sec. 4.—The President, Vice-president, and all civil officers of the
United States, shall be removed from office on impeachment for and
conviction of treason, bribery, or other high crimes and
misdemeanors.
ARTICLE III.
Section 1.—The judicial power of the United States shall be vested in
a Supreme Court, and in such inferior courts as the Congress may
from time to time ordain and establish. The judges, both of the
supreme and inferior courts, shall hold their offices during good
behavior; and shall, at stated times, receive for their services a
compensation, which shall not be diminished during their
continuance in office.
Sec. 2.—The judicial power shall extend to all cases, in law and
equity, arising under this Constitution, the laws of the United States,
and treaties made, or which shall be made, under their authority; to
all cases affecting ambassadors, other public ministers, and consuls;
to all cases of admiralty and maritime jurisdiction; to controversies
to which the United States shall be a party; to controversies between
two or more States, between a State and citizens of another State,
between citizens of different States, between citizens of the same
State claiming lands under grants of different States, and between a
State, or the citizens thereof, and foreign States, citizens, or
subjects.
In all cases affecting ambassadors, other public ministers and
consuls, and those in which a State shall be a party, the Supreme
Court shall have original jurisdiction. In all the other cases before
mentioned, the Supreme Court shall have appellate jurisdiction both
as to law and fact, with such exceptions, and under such
regulations, as the Congress shall make.
The trial of all crimes, except in cases of impeachment, shall be by
jury; and such trial shall be held in the State where the said crimes
shall have been committed; but, when not committed within any
State, the trial shall be at such place or places as the Congress may
by law have directed.
Sec. 3.—Treason against the United States shall consist only in
levying war against them, or in adhering to their enemies, giving
them aid and comfort. No person shall be convicted of treason
unless on the testimony of two witnesses to the same overt act, or
on confession in open court.
The Congress shall have power to declare the punishment of
treason, but no attainder of treason shall work corruption of blood or
forfeiture, except during the life of the person attainted.
ARTICLE IV.
Section 1.—Full faith and credit shall be given in each State to the
public acts, records, and judicial proceedings of every other State.
And the Congress may by general laws prescribe the manner in
which such acts, records, and proceedings shall be proved, and the
effect thereof.
Sec. 2.—The citizens of each State shall be entitled to all privileges
and immunities of citizens in the several States.
A person charged in any State with treason, felony, or other crime,
who shall flee from justice, and be found in another State, shall, on
demand of the executive authority of the State from which he fled,
be delivered up, to be removed to the State having jurisdiction of
the crime.
No person held to service or labor in one State under the laws
thereof, escaping into another, shall, in consequence of any law or
regulation therein, be discharged from such service or labor, but
shall be delivered up on claim of the party to whom such service or
labor may be due.
Sec. 3.—New States may be admitted by the Congress into this
Union; but no new State shall be formed or erected within the
jurisdiction of any other State; nor any State be formed by the
junction of two or more States, or parts of States, without the
consent of the legislature of the States concerned, as well as of the
Congress.
The Congress shall have power to dispose of and make all needful
rules and regulations respecting the territory or other property
belonging to the United States; and nothing in this Constitution shall
be so construed as to prejudice any claims of the United States, or
of any particular State.
Sec. 4.—The United States shall guarantee to every State in this
Union a republican form of government, and shall protect each of
them against invasion; and on application of the legislature, or of the
executive (when the legislature can not be convened), against
domestic violence.
ARTICLE V.
The Congress, whenever two thirds of both houses shall deem it
necessary, shall propose amendments to this Constitution; or, on the
application of the legislatures of two thirds of the several States,
shall call a convention for proposing amendments, which, in either
case, shall be valid, to all intents and purposes, as part of this
Constitution, when ratified by the legislatures of three fourths of the
several States, or by conventions in three fourths thereof, as the one
or the other mode of ratification may be proposed by the Congress;
Provided, that no amendment, which may be made prior to the year
one thousand eight hundred and eight, shall in any manner affect
the first and fourth clauses in the ninth section of the first article;
and that no State, without its consent, shall be deprived of its equal
suffrage in the Senate.
ARTICLE VI.
All debts contracted, and engagements entered into, before the
adoption of this Constitution, shall be as valid against the United
States under this Constitution as under the Confederation.
This Constitution, and the laws of the United States which shall be
made in pursuance thereof, and all treaties made, or which shall be
made, under the authority of the United States, shall be the
supreme law of the land; and the judges in every State shall be
bound thereby, any thing in the constitution or laws of any State to
the contrary notwithstanding.
The senators and representatives before mentioned, and the
members of the several State legislatures, and all executive and
judicial officers, both of the United States and of the several States,
shall be bound by oath or affirmation to support this Constitution;
but no religious test shall ever be required as a qualification to any
office or public trust under the United States.
ARTICLE VII.
The ratification of the conventions of nine States shall be sufficient
for the establishment of this Constitution between the States so
ratifying the same.
Done in Convention by the unanimous consent of the States
present, the seventeenth day of September, in the year of our
Lord one thousand seven hundred and eighty-seven, and of the
Independence of the United States of America the twelfth. In
witness whereof we have hereunto subscribed our names.
George Washington, President,
and Deputy from Virginia.
New Hampshire.—John Langdon, Nicholas Gilman.
Massachusetts.—Nathaniel Gorham, Rufus King.
Connecticut.—William Samuel Johnson, Roger Sherman.
New York.—Alexander Hamilton.
New Jersey.—William Livingston, David Bearly, William Patterson,
Jonathan Dayton.
Pennsylvania.—Benjamin Franklin, Thomas Mifflin, Robert Morris,
George Clymer, Thomas Fitzsimons, Jared Ingersoll, James
Wilson, Gouverneur Morris.
Delaware.—George Read, Gunning Bedford, Jr., John Dickinson,
Richard Bassett, Jacob Broom.
Maryland.—James McHenry, Daniel of St. Thomas Jenifer, Daniel
Carroll.
Virginia.—John Blair, James Madison, Jr.
North Carolina.—William Blount, Richard Dobbs Spaight, Hugh
Williamson.
South Carolina.—John Rutledge, Charles Cotesworth Pinckney,
Charles Pinckney, Pierce Butler.
Georgia.—William Few, Abraham Baldwin.
Attest:
William Jackson, Secretary.
AMENDMENTS TO THE
CONSTITUTION.
ARTICLE I.
Congress shall make no law respecting an establishment of religion,
or prohibiting the free exercise thereof; or abridging the freedom of
speech or of the press; or the right of the people peaceably to
assemble, and to petition the government for a redress of
grievances.
ARTICLE II.
A well-regulated militia being necessary to the security of a free
State, the right of the people to keep and bear arms shall not be
infringed.
ARTICLE III.
No soldier shall, in time of peace, be quartered in any house without
the consent of the owner; nor in time of war, but in a manner to be
prescribed by law.
ARTICLE IV.
The right of the people to be secure in their persons, houses,
papers, and effects, against unreasonable searches and seizures,
shall not be violated; and no warrants shall issue but upon probable
cause, supported by oath or affirmation, and particularly describing
the place to be searched, and the person or things to be seized.
ARTICLE V.
No person shall be held to answer for a capital or otherwise
infamous crime, unless on a presentment or indictment of a grand
jury, except in cases arising in the land or naval forces, or in the
militia when in actual service in time of war or public danger; nor
shall any person be subject, for the same offense, to be twice put in
jeopardy of life or limb; nor shall be compelled, in any criminal case,
to be a witness against himself; nor be deprived of life, liberty, or
property, without due process of law; nor shall private property be
taken for public use without just compensation.
ARTICLE VI.
In all criminal prosecutions, the accused shall enjoy the right to a
speedy and public trial, by an impartial jury of the State and district
wherein the crime shall have been committed, which district shall
have been previously ascertained by law; and to be informed of the
nature and cause of the accusation; to be confronted with the
witnesses against him; to have compulsory process for obtaining
witnesses in his favor; and to have the assistance of counsel for his
defense.
ARTICLE VII.
In suits at common law, where the value in controversy shall exceed
twenty dollars, the right of trial by jury shall be preserved; and no
fact tried by a jury shall be otherwise reexamined in any court of the
United States than according to the rules of the common law.
ARTICLE VIII.
Excessive bail shall not be required, nor excessive fines imposed, nor
cruel and unusual punishments inflicted.
ARTICLE IX.
The enumeration in the Constitution of certain rights, shall not be
construed to deny or disparage others retained by the people.
ARTICLE X.
The powers not delegated to the United States by the Constitution,
nor prohibited by it to the States, are reserved to the States
respectively, or to the people.
ARTICLE XI.
The judicial power of the United States shall not be construed to
extend to any suit in law or equity, commenced or prosecuted
against one of the United States by citizens of another State, or by
citizens or subjects of any foreign State.
ARTICLE XII.
The electors shall meet in their respective States, and vote by ballot
for President and Vice-president, one of whom, at least, shall not be
an inhabitant of the same State with themselves; they shall name in
their ballots the person voted for as President, and in distinct ballots
the person voted for as Vice-president; and they shall make distinct
lists of all persons voted for as President, and of all persons voted
for as Vice-president, and of the number of votes for each, which
lists they shall sign and certify and transmit sealed to the seat of the
government of the United States, directed to the president of the
Senate; the president of the Senate shall, in the presence of the
Senate and House of Representatives, open all the certificates, and
the votes shall then be counted; the person having the greatest
number of votes for President shall be President, if such number be
a majority of the whole number of electors appointed; and if no
person have such majority, then from the persons having the highest
numbers, not exceeding three on the list of those voted for as
President, the House of Representatives shall choose immediately,
by ballot, the President. But, in choosing the President, the votes
shall be taken by States, the representation from each State having
one vote; a quorum for this purpose shall consist of a member or
members from two thirds of the States, and a majority of all the
States shall be necessary to a choice. And if the House of
Representatives shall not choose a President, whenever the right of
choice shall devolve upon them, before the fourth day of March next
following, then the Vice-president shall act as President, as in the
case of the death or other constitutional disability of the President.
The person having the greatest number of votes as Vice-president
shall be the Vice-president, if such number be a majority of the
whole number of electors appointed; and if no person have a
majority, then from the two highest numbers on the list, the Senate
shall choose the Vice-president; a quorum for the purpose shall
consist of two thirds of the whole number of senators, and a
majority of the whole number shall be necessary to a choice.
But no person constitutionally ineligible to the office of President
shall be eligible to that of Vice-president of the United States.
ARTICLE XIII.
Section 1.—Neither slavery nor voluntary servitude, except as a
punishment for crime, whereof the party shall have been duly
convicted, shall exist within the United States, or any place subject
to their jurisdiction.
Sec. 2.—Congress shall have power to enforce this Article by
appropriate legislation.
ARTICLE XIV.
Section 1.—All persons born or naturalized in the United States, and
subject to the jurisdiction thereof, are citizens of the United States
and of the State wherein they reside. No State shall make or enforce
any law which shall abridge the privileges or immunities of citizens
of the United States; nor shall any State deprive any person of life,
liberty, or property, without due process of law, nor deny to any
person within its jurisdiction the equal protection of the laws.
Sec. 2.—Representatives shall be apportioned among the several
States, according to their respective numbers, counting the whole
number of persons in each State, excluding Indians not taxed. But
when the right to vote at any election for choice of electors for
President and Vice-president of the United States, representatives in
Congress, the executive and judicial officers of a State, or the
members of the legislature thereof, is denied to any of the male
inhabitants of such State being twenty-one years of age, and citizens
of the United States, or in any way abridged, except for participation
in rebellion or other crime, the basis of representation therein shall
be reduced in the proportion which the number of such male citizens
shall bear to the whole number of male citizens twenty-one years of
age in such State.
Sec. 3.—No person shall be a senator, or representative in Congress,
or elector of President and Vice-president, or hold any office, civil or
military, under the United States, or under any State, who, having
previously taken an oath as a member of Congress, or as an officer
of the United States, or as a member of any State legislature, or as
an executive or judicial officer of any State, to support the
Constitution of the United States, shall have engaged in insurrection
or rebellion against the same, or given aid or comfort to the enemies
thereof; but Congress may, by a vote of two thirds of each house,
remove such disability.
Sec. 4.—The validity of the public debt of the United States
authorized by law, including debts incurred for payment of pensions,
and bounties for services in suppressing insurrection or rebellion,
shall not be questioned. But neither the United States, nor any
State, shall assume or pay any debt or obligation incurred in aid of
insurrection or rebellion against the United States, or any claim for
the loss or emancipation of any slave; but all such debts, obligations,
and claims shall be held illegal and void.
Sec. 5.—The Congress shall have power to enforce by appropriate
legislation the provisions of this Article.
ARTICLE XV.
Section 1.—The right of citizens of the United States to vote shall not
be denied or abridged by the United States, or by any State, on
account of race, color, or previous condition of servitude.
Sec. 2.—The Congress shall have power to enforce this Article by
appropriate legislation.
INDEX.
A
Abercrombie, General, defeat of, at Ticonderoga, 143.
Abraham, Plains of, battle of, 146.
Acadia, named, 39;
conquered by the English, 141.
Acadians, exile of the, 141.
Act, the Importation, 150;
the Stamp, 151;
the Embargo, 219;
the Conscription, 308;
the Resumption, 339.
Adams, John, predicts American Independence, 150;
nominates Washington, 161;
on Declaration Committee, 165;
Commissioner to Paris, 197;
elected first Vice-president, 202;
reelected Vice-president, 208;
elected President, 210;
administration of, 211-213;
death of, 249.
Adams, John Quincy, Secretary of State, 244;
elected President, 247;
sketch of, 248;
administration of, 248, 249.
Adams, Samuel, at Boston town-meeting, 150.
Agricultural Department, established, 360.
Aix-la-Chapelle, treaty of, 93.
Alabama, admission of, 246.
Alabama Claims, the, 330.
Alabama, depredations by the, 315.
Alaska, purchase of, 325.
Algiers, tribute paid to, 210;
subdued by Decatur, 242.
Alexander, Pope, gives New World to Spain, 43.
Algonquins, regions inhabited by the, 16.
Allen, Ethan, captures Fort Ticonderoga, 159.
America, discovery of, 25;
derivation of name, 26.
Amendments to the Constitution, fourteenth and fifteenth,
328.
Amherst, general-in-chief of American forces, 144.
Amnesty proclamation, the, 324.
Anarchists, the Chicago, 352.
Anderson, Robert, defends Fort Sumter, 282.
André, John, capture of, 191.
Andros, Sir Edmund, royal governor of New England, 86;
demands surrender of Connecticut charter, 87;
governor of New York, 101;
treaty of with the Iroquois, 102.
Antietam, battle of, 301.
Anti-Federalist party, the, 201.
Appomattox Courthouse, surrender at, 319.
Arctic expeditions, 272.
Argall, Samuel, abducts Pocahontas, 65;
expedition against Acadia, 65;
elected governor of Virginia, 67.
Arizona Territory, organization of, 325.
Arkansas, organization of Territory, 246;
admission of State, 253.
Arlington, Earl of, grant of Virginia to, 73;
surrenders claim to Culpepper, 75.
Arnold, Benedict, at Ticonderoga, 159;
expedition against Canada, 162;
at camp on Delaware, 172;
at Bemis's Heights, 174;
treason of, 190;
in British army, 192.
Arthur, Chester A., elected Vice-president, 341;
becomes President, 346;
sketch of, 346;
administration of, 346-349.
Atlanta, capture of, 312.
Aztecs, regions inhabited by the, 16.
B
Bacon, Nathaniel, rebellion led by, 74.
Balboa discovers the Pacific, 27.
Ball's Bluff, battle of, 291.
Baltimore, Lord, secures charter for New Maryland, 122.
Baltimore, siege of, 238;
mob at fire on Union soldiers, 282.
Bank of North America, organization of, 192.
Bank of the United States, organization of, 207;
rechartered, 242;
rechartering vetoed by Jackson, 250;
rechartering vetoed by Tyler, 258.
Banks, N. P., in West Virginia, 297;
at Cedar Mountain, 300;
captures Port Hudson, 304;
Red River expedition of, 310.
Barclay, Commodore, on Lake Erie, 229.
Battle of Antietam, 301;
Atlanta, 312;
Ball's Bluff, 291;
Bemis's Heights, 174;
Bennington, 173;
Brandywine, 175;
Brier Creek, 185;
Buena Vista, 264;
Bull Run, 289, 300;
Bunker Hill, 159;
Cerro Gordo, 264;
Champion Hills, 303;
Chancellorsville, 307;
Chapultepec, 267;
Chickamauga, 304;
Chippewa, 235;
Chrysler's Field, 232;
Churubusco, 266;
City of Mexico, 265;
Cold Harbor, 316;
Corinth, 297;
Cowpens, 193;
Eutaw Springs, 195;
Fair Oaks, 299;
Five Oaks, 319;
Fort Edward, 142;
Fort Meigs, 228;
Fort Stephenson, 229;
Fredericksburg, 301;
Frenchtown, 228;
Germantown, 176;
Gettysburg, 308;
Guilford Courthouse, 194;
Kenesaw Mountain, 311;
King's Mountain, 189;
Lake Erie, 229;
Long Island, 166;
Lookout Mountain, 305;
Lundy's Lane, 235;
Malvern Hill, 299;
Missionary Ridge, 305;
Monmouth, 180;
Monterey, 263;
Murfreesborough, 297;
Nashville, 312;
New Orleans, 241;
Palo Alto, 262;
Plains of Abraham, 145;
Plattsburgh, 237;
Princeton, 171;
Queenstown, 226;
Resaca de la Palma, 262;
Sag Harbor, 171;
Sander's Creek, 188;
San Gabriel, 264;
Saratoga, 174;
Savannah, 183;
Shiloh, 293;
Spottsylvania Courthouse, 316;
Talladega, 231;
Thames, 230;
Tippecanoe, 223;
Trenton, 169;
Vera Cruz, 264;
Vicksburg, 303;
White Plains, 168;
Wilson's Creek, 290;
Yorktown, 196.
Beecher, Henry Ward, death of, 357.
Bell, A. Graham, inventor of telephone, 357.
Bellomont, Earl of, governor of New York, 103.
Bemis's Heights, battle of, 174.
Bennington, battle of, 264.
Berkeley, Sir William, governor of Virginia, 71;
elected by burgesses, 72;
rebellion against, 74;
oppression by, 75;
grant of New Jersey to, 115;
sells interest, 116.
Beverley, Robert, royalist captain, 74.
Black Hawk War, the, 251.
Blaine, James G., Secretary of State under Garfield, 345;
nominated for President, 349;
Secretary of State under Harrison, 362.
Block, Adrian, explorations by, 55.
Body of Liberties, 82.
Boone, Daniel, colonizes Kentucky, 208.
Booth, John Wilkes, assassinates Lincoln, 321;
death of, 321.
Boston, founded, 79;
occupied by British, 154;
massacre at, 154;
tea party, 155;
Port Bill, 156;
siege of, 159-164;
fire in, 331.
Braddock, Edward, arrives in America, 139;
defeat and death of, 140.
Bradford, John, landing of, 51.
Bradford, William, governor of Massachusetts, 77.
Bragg, Braxton, at Murfreesborough, 297;
at Chickamauga, 304;
at Lookout Mountain and Missionary Ridge, 305.
Brandywine, battle of, 175.
Breckinridge, John C., elected Vice-president, 274;
commands Confederate cavalry, 317.
Breed's Hill, fortification of, 159.
Brier Creek, battle of, 185.
Brooklyn Bridge, construction of the, 347.
Brown, John, insurrection led by, 276.
Bryant, William Cullen, death of, 343.
Buchanan, James, Secretary of State, 261;
elected President, 274;
sketch of, 275;
administration of, 275-277.
Buckner, S. B., defends Fort Donelson, 293.
Buena Vista, battle of, 264.
Bull Run, battles of, 289, 300.
Bunker Hill, battle of, 159.
Burgesses, House of, organized, 67;
scene in, 152.
Burgoyne, Gen., campaign of, 172-175;
surrender of, 175.
Burnside, Ambrose E., takes command of Army of the
Potomac, 301;
at Fredericksburg, 301;
death of, 356.
Burr, Aaron, elected Vice-president, 213;
duel with Hamilton, 217;
schemes of, 217.
Butler, Benjamin F., at New Orleans, 296;
at Fort Fisher, 314;
joins Grant at Bermuda Hundred, 316;
nominated for presidency, 349.
C
Cabinet, the first, 205.
Cable, Atlantic, laying of the, 275, 325.
Cabot, John, voyage and discoveries of, 41.
Cabot, Sebastian, voyage and explorations of, 42.
Calhoun, John C., Secretary of War, 244;
elected Vice-president, 247;
for nullification, 251;
death of, 272.
California, conquest of, 264;
discovery of gold in, 267;
admission of, 268.
Californians, regions inhabited by the, 16.
Calvert, Sir Cecil, charter issued to, 123.
Calvert, Sir George, in Maryland, 122.
Cambridge, named, 81.
Canadian insurrection, the, 256.
Canonchet, King, violates treaty, 84;
death of, 85.
Canonicus, King of the Narragansetts, 107.
Capitol of the United States, location of the, 213.
Carolinas, history of the, 125-127;
separation of the, 127.
Caroline, firing of the, 256.
Carteret, Sir George, proprietor of New Jersey, 115.
Cartier, James, voyages of, 36, 37.
Carver, John, governor of the Pilgrims, 51;
death of, 76.
Census of 1790 and 1800, 213;
of 1810, 222;
of 1870, 329;
of 1880, 342;
of 1890, 366.
Centennial Exposition, the, 333.
Centennial of the Republic, the, 362.
Cerro Gordo, battle of, 264.
Champion Hills, battle of, 303.
Champlain, Lake, discovered, 40;
expedition to, 141;
abandoned by the French, 145.
Champlain, Samuel, voyages of, 39, 40;
founds Quebec, 39;
discovers Lake Champlain, 40;
governs New France, 40.
Chancellorsville, battle of, 307.
Chandler, Zackariah, death of, 343.
Chapultepec, battle of, 267.
Charlesbourg, Fort, settlement at, 47.
Charleston, founded, 128;
British repulsed at, 164;
taken by British, 187;
evacuated, 195;
taken by Sherman, 313.
Charleston earthquake, the, 353.
Charter Oak, the, 87.
Charter of New England, 78.
Chase, Salmon P., Secretary of the Treasury, 281;
as Chief-justice presides at impeachment trial of Andrew
Johnson, 327.
Chen Lan Pin, the Chinese Minister, 340.
Cherokees, regions inhabited by the, 16;
difficulties with the, 252.
Cherry Valley, massacre at, 181.
Chesapeake, the affair of the, 233.
Chesapeake Bay, explored, 61.
Chicago, the great fire in, 330;
the Anarchists in, 352.
Chickamauga, battle of, 304.
Chicora, first name of South Carolina, 29.
Chinese Embassy, establishment of the, 340.
Chippewa, battle of, 235.
Chrysler's Field, battle of, 232.
Churubusco, battle of, 266.
Circumnavigation of the globe, 28.
Civil Rights Bill, the, 326.

(eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition

  • 1.
    (eBook PDF) StartingOut with C++: From Control Structures through Objects 8th Edition install download https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from- control-structures-through-objects-8th-edition/ Download more ebook from https://ebookluna.com
  • 2.
    Instant digital products(PDF, ePub, MOBI) ready for you Download now and discover formats that fit your needs... (eBook PDF) Starting Out with C++: From Control Structures through Objects, Brief Version 8th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from- control-structures-through-objects-brief-version-8th-edition/ ebookluna.com (eBook PDF) Starting Out with Java: From Control Structures through Objects, 7th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from- control-structures-through-objects-7th-edition/ ebookluna.com (eBook PDF) Starting Out with C++ from Control Structures to Objects 9th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-c-from- control-structures-to-objects-9th-edition/ ebookluna.com (eBook PDF) Starting Out with Java: From Control Structures through Data Structures 3rd Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from- control-structures-through-data-structures-3rd-edition/ ebookluna.com
  • 3.
    (eBook PDF) StartingOut with Java: From Control Structures through Data Structures 4th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from- control-structures-through-data-structures-4th-edition/ ebookluna.com (eBook PDF) Starting Out with C++: Early Objects 9th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-c-early- objects-9th-edition/ ebookluna.com Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF) https://ebookluna.com/product/starting-out-with-c-early-objects-9th- edition-by-tony-gaddis-ebook-pdf/ ebookluna.com (eBook PDF) Starting Out with Java: Early Objects 5th Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early- objects-5th-edition/ ebookluna.com (eBook PDF) Starting Out with Java: Early Objects 5th Global Edition https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early- objects-5th-global-edition/ ebookluna.com
  • 6.
    Preface xv CHAPTER 1Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What Is a Program Made of? 14 1.5 Input, Processing, and Output 17 1.6 The Programming Process 18 1.7 Procedural and Object-Oriented Programming 22 CHAPTER 2 Introduction to C++ 27 2.1 The Parts of a C++ Program 27 2.2 The cout Object 31 2.3 The #include Directive 36 2.4 Variables and Literals 37 2.5 Identifiers 41 2.6 Integer Data Types 42 2.7 The char Data Type 48 2.8 The C++ string Class 52 2.9 Floating-Point Data Types 54 2.10 The bool Data Type 57 2.11 Determining the Size of a Data Type 58 2.12 Variable Assignments and Initialization 59 2.13 Scope 61 2.14 Arithmetic Operators 61 2.15 Comments 69 2.16 Named Constants 71 2.17 Programming Style 73 vii Contents
  • 7.
    viii Contents CHAPTER 3Expressions and Interactivity 83 3.1 The cin Object 83 3.2 Mathematical Expressions 89 3.3 When You Mix Apples and Oranges: Type Conversion 98 3.4 Overflow and Underflow 100 3.5 Type Casting 101 3.6 Multiple Assignment and Combined Assignment 104 3.7 Formatting Output 108 3.8 Working with Characters and string Objects 118 3.9 More Mathematical Library Functions 124 3.10 Focus on Debugging: Hand Tracing a Program 130 3.11 Focus on Problem Solving: A Case Study 132 CHAPTER 4 Making Decisions 149 4.1 Relational Operators 149 4.2 The if Statement 154 4.3 Expanding the if Statement 162 4.4 The if/else Statement 166 4.5 Nested if Statements 169 4.6 The if/else if Statement 176 4.7 Flags 181 4.8 Logical Operators 182 4.9 Checking Numeric Ranges with Logical Operators 189 4.10 Menus 190 4.11 Focus on Software Engineering: Validating User Input 193 4.12 Comparing Characters and Strings 195 4.13 The Conditional Operator 199 4.14 The switch Statement 202 4.15 More About Blocks and Variable Scope 211 CHAPTER 5 Loops and Files 227 5.1 The Increment and Decrement Operators 227 5.2 Introduction to Loops: The while Loop 232 5.3 Using the while Loop for Input Validation 239 5.4 Counters 241 5.5 The do-while Loop 242 5.6 The for Loop 247 5.7 Keeping a Running Total 257 5.8 Sentinels 260 5.9 Focus on Software Engineering: Deciding Which Loop to Use 261 5.10 Nested Loops 262 5.11 Using Files for Data Storage 265 5.12 Optional Topics: Breaking and Continuing a Loop 284 CHAPTER 6 Functions 299 6.1 Focus on Software Engineering: Modular Programming 299 6.2 Defining and Calling Functions 300 6.3 Function Prototypes 309 6.4 Sending Data into a Function 311
  • 8.
    Contents ix 6.5 PassingData by Value 316 6.6 Focus on Software Engineering: Using Functions in a Menu-Driven Program 318 6.7 The return Statement 322 6.8 Returning a Value from a Function 324 6.9 Returning a Boolean Value 332 6.10 Local and Global Variables 334 6.11 Static Local Variables 342 6.12 Default Arguments 345 6.13 Using Reference Variables as Parameters 348 6.14 Overloading Functions 354 6.15 The exit() Function 358 6.16 Stubs and Drivers 361 CHAPTER 7 Arrays 375 7.1 Arrays Hold Multiple Values 375 7.2 Accessing Array Elements 377 7.3 No Bounds Checking in C++ 384 7.4 Array Initialization 387 7.5 The Range-Based for Loop 392 7.6 Processing Array Contents 396 7.7 Focus on Software Engineering: Using Parallel Arrays 404 7.8 Arrays as Function Arguments 407 7.9 Two-Dimensional Arrays 418 7.10 Arrays with Three or More Dimensions 425 7.11 Focus on Problem Solving and Program Design: A Case Study 427 7.12 If You Plan to Continue in Computer Science: Introduction to the STL vector 429 CHAPTER 8 Searching and Sorting Arrays 457 8.1 Focus on Software Engineering: Introduction to Search Algorithms 457 8.2 Focus on Problem Solving and Program Design: A Case Study 463 8.3 Focus on Software Engineering: Introduction to Sorting Algorithms 470 8.4 Focus on Problem Solving and Program Design: A Case Study 477 8.5 If You Plan to Continue in Computer Science: Sorting and Searching vectors 485 CHAPTER 9 Pointers 495 9.1 Getting the Address of a Variable 495 9.2 Pointer Variables 497 9.3 The Relationship Between Arrays and Pointers 504 9.4 Pointer Arithmetic 508 9.5 Initializing Pointers 510 9.6 Comparing Pointers 511 9.7 Pointers as Function Parameters 513 9.8 Focus on Software Engineering: Dynamic Memory Allocation 522 9.9 Focus on Software Engineering: Returning Pointers from Functions 526 9.10 Using Smart Pointers to Avoid Memory Leaks 533 9.11 Focus on Problem Solving and Program Design: A Case Study 536
  • 9.
    x Contents CHAPTER 10Characters, 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 CHAPTER 11 Structured Data 599 11.1 Abstract Data Types 599 11.2 Focus on Software Engineering: Combining Data into Structures 601 11.3 Accessing Structure Members 604 11.4 Initializing a Structure 608 11.5 Arrays of Structures 611 11.6 Focus on Software Engineering: Nested Structures 613 11.7 Structures as Function Arguments 617 11.8 Returning a Structure from a Function 620 11.9 Pointers to Structures 623 11.10 Focus on Software Engineering: When to Use ., When to Use ->, and When to Use * 626 11.11 Unions 628 11.12 Enumerated Data Types 632 CHAPTER 12 Advanced File Operations 657 12.1 File Operations 657 12.2 File Output Formatting 663 12.3 Passing File Stream Objects to Functions 665 12.4 More Detailed Error Testing 667 12.5 Member Functions for Reading and Writing Files 670 12.6 Focus on Software Engineering: Working with Multiple Files 678 12.7 Binary Files 680 12.8 Creating Records with Structures 685 12.9 Random-Access Files 689 12.10 Opening a File for Both Input and Output 697 CHAPTER 13 Introduction to Classes 711 13.1 Procedural and Object-Oriented Programming 711 13.2 Introduction to Classes 718 13.3 Defining an Instance of a Class 723 13.4 Why Have Private Members? 736 13.5 Focus on Software Engineering: Separating Class Specification from Implementation 737 13.6 Inline Member Functions 743 13.7 Constructors 746 13.8 Passing Arguments to Constructors 750
  • 10.
    Contents xi 13.9 Destructors758 13.10 Overloading Constructors 762 13.11 Private Member Functions 765 13.12 Arrays of Objects 767 13.13 Focus on Problem Solving and Program Design: An OOP Case Study 771 13.14 Focus on Object-Oriented Programming: Simulating Dice with Objects 778 13.15 Focus on Object-Oriented Programming: Creating an Abstract Array Data Type 782 13.16 Focus on Object-Oriented Design: The Unified Modeling Language (UML) 785 13.17 Focus on Object-Oriented Design: Finding the Classes and Their Responsibilities 788 CHAPTER 14 More About Classes 811 14.1 Instance and Static Members 811 14.2 Friends of Classes 819 14.3 Memberwise Assignment 824 14.4 Copy Constructors 825 14.5 Operator Overloading 831 14.6 Object Conversion 858 14.7 Aggregation 860 14.8 Focus on Object-Oriented Design: Class Collaborations 865 14.9 Focus on Object-Oriented Programming: Simulating the Game of Cho-Han 869 CHAPTER 15 Inheritance, Polymorphism, and Virtual Functions 891 15.1 What Is Inheritance? 891 15.2 Protected Members and Class Access 900 15.3 Constructors and Destructors in Base and Derived Classes 906 15.4 Redefining Base Class Functions 918 15.5 Class Hierarchies 923 15.6 Polymorphism and Virtual Member Functions 929 15.7 Abstract Base Classes and Pure Virtual Functions 945 15.8 Multiple Inheritance 952 CHAPTER 16 Exceptions, Templates, and the Standard Template Library (STL) 971 16.1 Exceptions 971 16.2 Function Templates 990 16.3 Focus on Software Engineering: Where to Start When Defining Templates 996 16.4 Class Templates 996 16.5 Introduction to the Standard Template Library (STL) 1005 CHAPTER 17 Linked Lists 1025 17.1 Introduction to the Linked List ADT 1025 17.2 Linked List Operations 1027 17.3 A Linked List Template 1043 17.4 Variations of the Linked List 1055 17.5 The STL list Container 1056
  • 11.
    xii Contents CHAPTER 18Stacks and Queues 1063 18.1 Introduction to the Stack ADT 1063 18.2 Dynamic Stacks 1080 18.3 The STL stack Container 1091 18.4 Introduction to the Queue ADT 1093 18.5 Dynamic Queues 1105 18.6 The STL deque and queue Containers 1112 CHAPTER 19 Recursion 1121 19.1 Introduction to Recursion 1121 19.2 Solving Problems with Recursion 1125 19.3 Focus on Problem Solving and Program Design: The Recursive gcd Function 1133 19.4 Focus on Problem Solving and Program Design: Solving Recursively Defined Problems 1134 19.5 Focus on Problem Solving and Program Design: Recursive Linked List Operations 1135 19.6 Focus on Problem Solving and Program Design: A Recursive Binary Search Function 1139 19.7 The Towers of Hanoi 1141 19.8 Focus on Problem Solving and Program Design: The QuickSort Algorithm 1144 19.9 Exhaustive Algorithms 1148 19.10 Focus on Software Engineering: Recursion vs. Iteration 1151 CHAPTER 20 Binary Trees 1155 20.1 Definition and Applications of Binary Trees 1155 20.2 Binary Search Tree Operations 1158 20.3 Template Considerations for Binary Search Trees 1175 Appendix A: Getting Started with Alice 1185 Appendix B: The ASCII Character Set 1211 Appendix C: Operator Precedence and Associativity 1213 Quick References 1215 Index 1217 Credit 1237 Online The following appendices are available at www.pearsonhighered.com/gaddis. Appendix D: Introduction to Flowcharting Appendix E: Using UML in Class Design Appendix F: Namespaces Appendix G: Passing Command Line Arguments Appendix H: Header File and Library Function Reference Appendix I: Binary Numbers and Bitwise Operations Appendix J: Multi-Source File Programs Appendix K: Stream Member Functions for Formatting Appendix L: Answers to Checkpoints Appendix M: Solutions to Odd-Numbered Review Questions
  • 12.
    LOCATION OF VIDEONOTESIN THE TEXT Chapter 1 Introduction to Flowcharting, p. 20 Designing a Program with Pseudocode, p. 20 Designing the Account Balance Program, p. 25 Predicting the Result of Problem 33, p. 26 Chapter 2 Using cout, p. 31 Variabe Definitions, p. 37 Assignment Statements and Simple Math Expressions, p. 62 Solving the Restaurant Bill Problem, p. 80 Chapter 3 Reading Input with cin, p. 83 Formatting Numbers with setprecision, p. 111 Solving the Stadium Seating Problem, p. 142 Chapter 4 The if Statement, p. 154 The if/else statement, p. 166 The if/else if Statement, p. 176 Solving the Time Calculator Problem, p. 221 Chapter 5 The while Loop, p. 232 The for Loop, p. 247 Reading Data from a File, p. 274 Solving the Calories Burned Problem, p. 293 Chapter 6 Functions and Arguments, p. 311 Value-Returnlng Functions, p. 324 Solving the Markup Problem, p. 366 Chapter 7 Accessing Array Elements With a Loop, p. 380 Passing an Array to a Function, p. 407 Solving the Chips and Salsa Problem, p. 448 Chapter 8 The Binary Search, p. 460 The Selection Sort, p. 474 Solving the Charge Account Validation Modification Problem, p. 492 Chapter 9 Dynamically Allocating an Array, p. 523 Solving the Pointer Rewrite Problem, p. 545 Chapter 10 Writing a C-String-Handling Function, p. 575 More About the string Class, p. 581 Solving the Backward String Problem, p. 594 (continued on the next page)
  • 13.
    LOCATION OF VIDEONOTESIN THE TEXT (continued) Chapter 11 Creating a Structure, p. 601 Passing a Structure to a Function, p. 617 Solving the Weather Statistics Problem, p. 652 Chapter 12 Passing File Stream Objects to Functions, p. 665 Working with Multiple Files, p. 678 Solving the File Encryption Filter Problem, p. 708 Chapter 13 Writing a Class, p. 718 Defining an Instance of a Class, p. 723 Solving the Employee Class Problem, p. 802 Chapter 14 Operator Overloading, p. 831 Class Aggregation, p. 860 Solving the NumDays Problem, p. 885 Chapter 15 Redefining a Base Class Function in a Derived Class, p. 918 Polymorphism, p. 929 Solving the Employee and Production-Worker Classes Problem, p. 963 Chapter 16 Throwing an Exception, p. 972 Handling an Exception, p. 972 Writing a Function Template, p. 990 Storing Objects in a vector, p. 1010 Solving the Exception Project Problem, p. 1024 Chapter 17 Appending a Node to a Linked List, p. 1028 Inserting a Node in a Linked List, p. 1035 Deleting a Node from a Linked List, p. 1039 Solving the Member Insertion by Position Problem, p. 1061 Chapter 18 Storing Objects in an STL stack, p. 1091 Storing Objects in an STL queue, p. 1114 Solving the File Compare Problem, p. 1119 Chapter 19 Reducing a Problem with Recursion, p. 1126 Solving the Recursive Multiplication Problem, p. 1153 Chapter 20 Inserting a Node in a Binary Tree, p. 1160 Deleting a Node from a Binary Tree, p. 1166 Solving the Node Counter Problem, p. 1182
  • 14.
    Welcome to StartingOut 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. Changes in the Eighth Edition C++11 is the latest standard version of the C++ language. In previous years, while the stan- dard was being developed, it was known as C++0x. In August 2011, it was approved by the International Standards Organization (ISO), and the name of the standard was officially changed to C++11. Most of the popular compilers now support the C++11 standard. The new C++11 standard was the primary motivation behind this edition. Although this edition introduces many of the new language features, a C++11 compiler is not strictly required to use the book. As you progress through the book, you will see C++11 icons in the margins, next to the new features that are introduced. Programs appearing in sections that are not marked with this icon will still compile using an older compiler. Here is a summary of the new C++11 topics that are introduced in this edition: ● The auto key word is introduced as a way to simplify complex variable definitions. The auto key word causes the compiler to infer a variable’s data type from its initial- ization value. ● The long long int and unsigned long long int data types, and the LL literal suffix are introduced. ● Chapter 5 shows how to pass a string object directly to a file stream object’s open member function, without the need to call the c_str() member function. (A discus- sion of the c_str()function still exists for anyone using a legacy compiler.) Preface xv
  • 15.
    xvi Preface ● Therange-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. Organization of the Text This text teaches C++ in a step-by-step fashion. Each chapter covers a major set of topics and builds knowledge as the student progresses through the book. Although the chapters can be easily taught in their existing sequence, some flexibility is provided. The diagram shown in Figure P-1 suggests possible sequences of instruction.
  • 16.
    Preface xvii Chapter 8 Searchingand Sorting Arrays Chapter 9 Pointers Chapter 10 Characters, Strings, and the string Class Chapter 12 Advanced File Operations* Chapter 20 Binary Trees Chapters 2–7 Basic Language Elements Chapter 11 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 Stacks and Queues Chapter 19 Recursion *A few subtopics in Chapter 12 require Chapters 9 and 11. Chapter 1 Introduction Figure P-1
  • 17.
    xviii Preface Chapter 1covers 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. Brief Overview of Each Chapter Chapter 1: Introduction to Computers and Programming This chapter provides an introduction to the field of computer science and covers the fun- damentals of programming, problem solving, and software design. The components of pro- grams, such as key words, variables, operators, and punctuation are covered. The tools of the trade, such as pseudocode, flow charts, and hierarchy charts are also presented. Chapter 2: Introduction to C++ This chapter gets the student started in C++ by introducing data types, identifiers, vari- able declarations, constants, comments, program output, simple arithmetic operations, and C-strings. Programming style conventions are introduced and good programming style is modeled here, as it is throughout the text. An optional section explains the difference between ANSI standard and pre-standard C++ programs. Chapter 3: Expressions and Interactivity In this chapter the student learns to write programs that input and handle numeric, char- acter, and string data. The use of arithmetic operators and the creation of mathematical expressions are covered in greater detail, with emphasis on operator precedence. Debug- ging is introduced, with a section on hand tracing a program. Sections are also included on simple output formatting, on data type conversion and type casting, and on using library functions that work with numbers. Chapter 4: Making Decisions Here the student learns about relational operators, relational expressions and how to con- trol the flow of a program with the if, if/else, and if/else if statements. The condi- tional operator and the switch statement are also covered. Crucial applications of these constructs are covered, such as menu-driven programs and the validation of input.
  • 18.
    Preface xix Chapter 5:Loops and Files This chapter covers repetition control structures. The while loop, do-while loop, and for loop are taught, along with common uses for these devices. Counters, accumulators, run- ning totals, sentinels, and other application-related topics are discussed. Sequential file I/O is also introduced. The student learns to read and write text files, and use loops to process the data in a file. 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 8: Sorting and Searching Arrays Here the student learns the basics of sorting arrays and searching for data stored in them. The chapter covers the Bubble Sort, Selection Sort, Linear Search, and Binary Search algo- rithms. There is also a section on sorting and searching STL vector objects. 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. Chapter 11: Structured Data The student is introduced to abstract data types and taught how to create them using struc- tures, unions, and enumerated data types. Discussions and examples include using pointers to structures, passing structures to functions, and returning structures from functions.
  • 19.
    xx Preface Chapter 12:Advanced File Operations This chapter covers sequential access, random access, text, and binary files. The various modes for opening files are discussed, as well as the many methods for reading and writing file contents. Advanced output formatting is also covered. Chapter 13: Introduction to Classes The student now shifts focus to the object-oriented paradigm. This chapter covers the fun- damental concepts of classes. Member variables and functions are discussed. The student learns about private and public access specifications, and reasons to use each. The topics of constructors, overloaded constructors, and destructors are also presented. The chapter pres- ents a section modeling classes with UML and how to find the classes in a particular problem. Chapter 14: More About Classes This chapter continues the study of classes. Static members, friends, memberwise assign- ment, and copy constructors are discussed. The chapter also includes in-depth sections on operator overloading, object conversion, and object aggregation. There is also a section on class collaborations and the use of CRC cards. Chapter 15: Inheritance, Polymorphism, and Virtual Functions The study of classes continues in this chapter with the subjects of inheritance, polymor- phism, and virtual member functions. The topics covered include base and derived class con- structors and destructors, virtual member functions, base class pointers, static and dynamic binding, multiple inheritance, and class hierarchies. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL) The student learns to develop enhanced error trapping techniques using exceptions. Discus- sion then turns to function and class templates as a method for reusing code. Finally, the student is introduced to the containers, iterators, and algorithms offered by the Standard Template Library (STL). Chapter 17: Linked Lists This chapter introduces concepts and techniques needed to work with lists. A linked list ADT is developed and the student is taught to code operations such as creating a linked list, appending a node, traversing the list, searching for a node, inserting a node, deleting a node, and destroying a list. A linked list class template is also demonstrated. Chapter 18: Stacks and Queues In this chapter the student learns to create and use static and dynamic stacks and queues. The operations of stacks and queues are defined, and templates for each ADT are demonstrated. Chapter 19: Recursion This chapter discusses recursion and its use in problem solving. A visual trace of recursive calls is provided, and recursive applications are discussed. Many recursive algorithms are presented, including recursive functions for finding factorials, finding a greatest common
  • 20.
    Preface xxi 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. Chapter 20: Binary Trees This chapter covers the binary tree ADT and demonstrates many binary tree operations. The student learns to traverse a tree, insert an element, delete an element, replace an element, test for an element, and destroy a tree. Appendix A: Getting Started with Alice This appendix gives a quick introduction to Alice. Alice is free software that can be used to teach fundamental programming concepts using 3D graphics. Appendix B: ASCII Character Set A list of the ASCII and Extended ASCII characters and their codes. Appendix C: Operator Precedence and Associativity A chart showing the C++ operators and their precedence. The following appendices are available online at www.pearsonhighered.com/gaddis. Appendix D: Introduction to Flowcharting A brief introduction to flowcharting. This tutorial discusses sequence, selection, case, repeti- tion, and module structures. Appendix E: Using UML in Class Design This appendix shows the student how to use the Unified Modeling Language to design classes. Notation for showing access specification, data types, parameters, return values, overloaded functions, composition, and inheritance are included. Appendix F: Namespaces This appendix explains namespaces and their purpose. Examples showing how to define a namespace and access its members are given. Appendix G: Passing Command Line Arguments Teaches the student how to write a C++ program that accepts arguments from the command line. This appendix will be useful to students working in a command line environment, such as Unix, Linux, or the Windows command prompt. Appendix H: Header File and Library Function Reference This appendix provides a reference for the C++ library functions and header files discussed in the book. Appendix I: Binary Numbers and Bitwise Operations A guide to the C++ bitwise operators, as well as a tutorial on the internal storage of integers.
  • 21.
    xxii Preface Appendix J:Multi-Source File Programs Provides a tutorial on creating programs that consist of multiple source files. Function header files, class specification files, and class implementation files are discussed. Appendix K: Stream Member Functions for Formatting Covers stream member functions for formatting such as setf. Appendix L: Answers to Checkpoints Students may test their own progress by comparing their answers to the checkpoint exer- cises against this appendix. The answers to all Checkpoints are included. Appendix M: Solutions to Odd-Numbered Review Questions Another tool that students can use to gauge their progress. Features of the Text Concept Each major section of the text starts with a concept statement. Statements This statement summarizes the ideas of the section. Example Programs The text has hundreds of complete example programs, each designed to highlight the topic currently being studied. In most cases, these are practical, real-world examples. Source code for these programs is provided so that students can run the programs themselves. Program Output After each example program there is a sample of its screen output. This immediately shows the student how the program should function. In the Spotlight Each of these sections provides a programming problem and a detailed, step-by-step analysis showing the student how to solve it. VideoNotes A series of online videos, developed specifically for this book, is available for viewing at www.pearsonhighered.com/gaddis. Icons appear throughout the text alerting the student to videos about specific topics. Checkpoints Checkpoints are questions placed throughout each chapter as a self-test study aid. Answers for all Checkpoint questions can be downloaded from the book’s Companion Web site at www. pearsonhighered.com/gaddis. This allows students to check how well they have learned a new topic. Notes Notes appear at appropriate places throughout the text. They are short explanations of interesting or often misunderstood points relevant to the topic at hand.
  • 22.
    Preface xxiii Warnings Warningsare 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. C++11 Throughout the text, new C++11 language features are introduced. Look for the C++11 icon to find these new features. 11 11
  • 23.
    xxiv Preface Supplements Student OnlineResources 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 Integrated Development Environment (IDE) Resource Kits Professors who adopt this text can order it for students with a kit containing five popular C++ IDEs (Microsoft® Visual Studio Express Edition, Dev C++, NetBeans, Eclipse, and CodeLite) and access to a Web site containing written and video tutorials for getting started in each IDE. For ordering information, please contact your campus Pearson Education rep- resentative or visit www.pearsonhighered.com/cs. Online Practice and Assessment with MyProgrammingLab MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of pro- gramming. Through practice exercises and immediate, personalized feedback, MyProgram- mingLab improves the programming competence of beginning students who often struggle with the basic concepts and paradigms of popular high-level programming languages. A self-study and homework tool, a MyProgrammingLab course consists of hundreds of small practice exercises organized around the structure of this textbook. For students, the system automatically detects errors in the logic and syntax of their code submissions and offers targeted hints that enable students to figure out what went wrong—and why. For instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the code inputted by students for review. MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the makers of the CodeLab interactive programming exercise system. For a full demonstration, to see feedback from instructors and students, or to get started using MyProgrammingLab in your course, visit www.myprogramminglab.com. 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
  • 24.
    Other documents randomlyhave different content
  • 25.
    13. Give anaccount of the troubles with the Nez Percé Indians. 14. Give the leading Congressional measures of these four years. 15. Tell about General Grant's tour around the world. CHAPTER LIII. 16. Give an account of the presidency and death of Garfield. 17. Outline the presidency of Arthur and the progress of applied science during his term of office. CHAPTER LIV. 18. State the general condition and trace the measures of Cleveland's administration. 19. Tell about the Charleston earthquake. 20. What great leaders of the Civil War died during these four years? CHAPTER LV. 21. Give an account of the election of President Harrison, and of his entrance upon office. 22. Summarize the leading events which have occurred during his administration.
  • 26.
    APPENDIX. CONSTITUTION OF THEUNITED STATES. We, the People of the United States, in order to form a more perfect union, establish justice, insure domestic tranquillity, provide for the common defense, promote the general welfare, and secure the blessings of liberty to ourselves and our posterity, do ordain and establish this Constitution for the United States of North America. ARTICLE I. Section 1.—All legislative powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives. Sec. 2.—The House of Representatives shall be composed of members chosen every second year by the people of the several States, and the electors in each State shall have the qualifications requisite for electors of the most numerous branch of the State legislature. No person shall be a representative who shall not have attained to the age of twenty-five years, and been seven years a citizen of the United States, and who shall not, when elected, be an inhabitant of that State in which he shall be chosen. Representatives and direct taxes shall be apportioned among the several States which may be included within this Union, according to their respective numbers, which shall be determined by adding to the whole number of free persons, including those bound to service for a term of years, and excluding Indians not taxed, three fifths of all other persons. The actual enumeration shall be made within three years after the first meeting of the Congress of the United States, and within every subsequent term of ten years, in such manner as
  • 27.
    they shall bylaw direct. The number of representatives shall not exceed one for every thirty thousand; but each State shall have at least one representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to choose three; Massachusetts, eight; Rhode Island and Providence Plantations, one; Connecticut, five; New York, six; New Jersey, four; Pennsylvania, eight; Delaware, one; Maryland, six; Virginia, ten; North Carolina, five; South Carolina, five; and Georgia, three. When vacancies happen in the representation from any State, the executive authority thereof shall issue writs of election to fill such vacancies. The House of Representatives shall choose their speaker and other officers; and shall have the sole power of impeachment. Sec. 3.—The Senate of the United States shall be composed of two senators from each State, chosen by the legislature thereof, for six years; and each senator shall have one vote. Immediately after they shall be assembled in consequence of the first election, they shall be divided, as equally as may be, into three classes. The seats of the senators of the first class shall be vacated at the expiration of the second year; of the second class, at the expiration of the fourth year; and of the third class at the expiration of the sixth year, so that one third may be chosen every second year; and if vacancies happen, by resignation or otherwise, during the recess of the legislature of any State, the executive thereof may make temporary appointments until the next meeting of the legislature which shall then fill such vacancies. No person shall be a senator who shall not have attained to the age of thirty years, and been nine years a citizen of the United States, and who shall not, when elected, be an inhabitant of that State for which he shall be chosen. The Vice-president of the United States shall be president of the Senate, but shall have no vote, unless they be equally divided.
  • 28.
    The Senate shallchoose their other officers, and also a president pro tempore, in the absence of the Vice-president, or when he shall exercise the office as President of the United States. The Senate shall have the sole power to try all impeachments. When sitting for that purpose, they shall be on oath or affirmation. When the President of the United States is tried, the chief-justice shall preside; and no person shall be convicted without the concurrence of two thirds of the members present. Judgment, in cases of impeachment, shall not extend further than to removal from office, and disqualification to hold and enjoy any office of honor, trust, or profit under the United States; but the party convicted shall, nevertheless, be liable and subject to indictment, trial, judgment, and punishment, according to law. Sec. 4.—The times, places, and manner of holding elections for senators and representatives shall be prescribed in each State by the legislature thereof; but the Congress may, at any time, by law, make or alter such regulations, except as to the places of choosing senators. The Congress shall assemble at least once in every year; and such meeting shall be on the first Monday in December, unless they shall by law appoint a different day. Sec. 5.—Each house shall be the judge of the elections, returns, and qualifications of its own members; and a majority of each shall constitute a quorum to do business; but a smaller number may adjourn from day to day, and may be authorized to compel the attendance of absent members, in such manner and under such penalties as each house may provide. Each house may determine the rules of its proceedings, punish its members for disorderly behavior, and, with the concurrence of two thirds, expel a member. Each house shall keep a journal of its proceedings, and from time to time publish the same, excepting such parts as may in their judgment require secrecy; and the yeas and nays of the members of
  • 29.
    either house, onany question, shall, at the desire of one fifth of those present, be entered on the journal. Neither house, during the session of Congress, shall, without the consent of the other, adjourn for more than three days, nor to any other place than that in which the two houses shall be sitting. Sec. 6.—The senators and representatives shall receive a compensation for their services, to be ascertained by law, and paid out of the treasury of the United States. They shall, in all cases except treason, felony, and breach of the peace, be privileged from arrest during their attendance on the session of their respective houses, and in going to and returning from the same; and, for any speech or debate in either house, they shall not be questioned in any other place. No senator or representative shall, during the time for which he was elected, be appointed to any civil office under the authority of the United States which shall have been created, or the emoluments whereof shall have been increased, during such time; and no person holding any office under the United States shall be a member of either house during his continuance in office. Sec. 7.—All bills for raising revenue shall originate in the House of Representatives; but the Senate may propose or concur with amendments, as on other bills. Every bill which shall have passed the House of Representatives and the Senate, shall, before it become a law, be presented to the President of the United States; if he approve he shall sign it; but if not, he shall return it, with his objections, to that house in which it shall have originated, who shall enter the objections at large on their journal, and proceed to reconsider it. If, after such reconsideration, two thirds of that house shall agree to pass the bill, it shall be sent, together with the objections, to the other house, by which it shall likewise be reconsidered, and, if approved by two thirds of that house, it shall become a law. But, in all such cases, the votes of both houses shall be determined by yeas and nays; and the names of the
  • 30.
    persons voting forand against the bill shall be entered on the journal of each house respectively. If any bill shall not be returned by the President within ten days (Sundays excepted) after it shall have been presented to him, the same shall be a law in like manner as if he had signed it, unless the Congress by their adjournment prevent its return, in which case it shall not be a law. Every order, resolution, or vote, to which the concurrence of the Senate and House of Representatives may be necessary (except on a question of adjournment), shall be presented to the President of the United States; and, before the same shall take effect, shall be approved by him, or, being disapproved by him, shall be repassed by two thirds of the Senate and House of Representatives, according to the rules and limitations prescribed in the case of a bill. Sec. 8.—The Congress shall have power:— To lay and collect taxes, duties, imposts, and excises, to pay the debts, and provide for the common defense and general welfare, of the United States; but all duties, imposts, and excises shall be uniform throughout the United States: To borrow money on the credit of the United States: To regulate commerce with foreign nations, and among the several States, and with the Indian tribes: To establish a uniform rule of naturalization, and uniform laws on the subject of bankruptcies throughout the United States: To coin money, regulate the value thereof, and of foreign coin, and fix the standard of weights and measures: To provide for the punishment of counterfeiting the securities and current coin of the United States: To establish post-offices and post-roads: To promote the progress of science and useful arts, by securing for limited times, to authors and inventors, the exclusive right to their respective writings and discoveries:
  • 31.
    To constitute tribunalsinferior to the Supreme Court: To define and punish piracies and felonies committed on the high seas, and offenses against the law of nations: To declare war, grant letters of marque and reprisal, and make rules concerning captures on land and water: To raise and support armies; but no appropriation of money to that use shall be for a longer term than two years: To provide and maintain a navy: To make rules for the government and regulation of the land and naval forces: To provide for calling forth the militia to execute the laws of the Union, suppress insurrections, and repel invasions: To provide for organizing, arming, and disciplining the militia, and for governing such part of them as may be employed in the service of the United States, reserving to the States respectively the appointment of the officers, and the authority of training the militia according to the discipline prescribed by Congress: To exercise exclusive legislation, in all cases whatsoever, over such district (not exceeding ten miles square) as may, by cession of particular States, and the acceptance of Congress, become the seat of government of the United States, and to exercise like authority over all places purchased by the consent of the legislature of the State in which the same shall be, for the erection of forts, magazines, arsenals, dockyards, and other needful buildings:—And To make all laws which shall be necessary and proper for carrying into execution the foregoing powers, and all other powers vested by this Constitution in the government of the United States, or in any department or officer thereof. Sec. 9.—The migration or importation of such persons, as any of the States now existing shall think proper to admit, shall not be prohibited by the Congress prior to the year one thousand eight
  • 32.
    hundred and eight;but a tax, or duty, may be imposed on such importation, not exceeding ten dollars for each person. The privilege of the writ of habeas corpus shall not be suspended, unless when in cases of rebellion or invasion the public safety may require it. No bill of attainder or ex post facto law shall be passed. No capitation or other direct tax shall be laid, unless in proportion to the census, or enumeration, hereinbefore directed to be taken. No tax or duty shall be laid on articles exported from any State. No preference shall be given by any regulation of commerce or revenue to the ports of one State over those of another; nor shall vessels bound to or from one State be obliged to enter, clear, or pay duties, in another. No money shall be drawn from the treasury but in consequence of appropriations made by law; and a regular statement and account of the receipts and expenditures of all public money shall be published from time to time. No title of nobility shall be granted by the United States; and no person holding any office of profit or trust under them shall, without the consent of the Congress, accept of any present, emolument, office, or title of any kind whatever, from any king, prince, or foreign state. Sec. 10.—No state shall enter into any treaty, alliance, or confederation; grant letters of marque and reprisal; coin money; emit bills of credit; make any thing but gold and silver coin a tender in payment of debts; pass any bill of attainder, ex post facto law, or law impairing the obligation of contracts; or grant any title of nobility. No State shall, without the consent of the Congress, lay any imposts or duties on imports or exports, except what may be absolutely necessary for executing its inspection laws; and the net produce of all duties and imposts laid by any State on imports or exports, shall
  • 33.
    be for theuse of the treasury of the United States; and all such laws shall be subject to the revision and control of the Congress. No State shall, without the consent of Congress, lay any duty of tonnage, keep troops or ships of war in time of peace, enter into any agreement or compact with another State or with a foreign power, or engage in war, unless actually invaded, or in such imminent danger as will not admit of delay. ARTICLE II. Section 1.—The executive power shall be vested in a President of the United States of America. He shall hold his office during the term of four years, and together with the Vice-president, chosen for the same term, be elected as follows:— Each State shall appoint, in such manner as the legislature thereof may direct, a number of electors equal to the whole number of senators and representatives to which the State may be entitled in the Congress; but no senator or representative, or person holding an office of trust or profit under the United States, shall be appointed an elector. The electors shall meet in their respective States, and vote by ballot for two persons, of whom one, at least, shall not be an inhabitant of the same State with themselves. And they shall make a list of all the persons voted for, and of the number of votes for each; which list they shall sign and certify, and transmit sealed to the seat of the government of the United States, directed to the president of the Senate. The president of the Senate shall, in the presence of the Senate and House of Representatives, open all the certificates; and the votes shall then be counted. The person having the greatest number of votes shall be the President, if such number be a majority of the whole number of electors appointed; and if there be more than one who have such majority, and have an equal number of votes, then the House of Representatives shall immediately choose, by ballot, one of them for President; and if no person have a majority, then, from the five highest on the list, the said house shall, in like manner, choose the President. But, in choosing the President,
  • 34.
    the votes shallbe taken by States, the representation from each State having one vote; a quorum for this purpose shall consist of a member or members from two thirds of the States; and a majority of all the States shall be necessary to a choice. In every case, after the choice of the President, the person having the greatest number of votes of the electors shall be Vice-president. But, if there should remain two or more who have equal votes, the Senate shall choose from them, by ballot, the Vice-president. The Congress may determine the time of choosing the electors, and the day on which they shall give their votes; which day shall be the same throughout the United States. No person except a natural born citizen, or a citizen of the United States at the time of the adoption of this Constitution, shall be eligible to the office of President; neither shall any person be eligible to that office who shall not have attained to the age of thirty-five years, and been fourteen years a resident within the United States. In case of the removal of the President from office, or of his death, resignation, or inability to discharge the powers or duties of the said office, the same shall devolve on the Vice-president; and the Congress may, by law, provide for the case of removal, death, resignation, or inability, both of the President and Vice-president, declaring what officer shall then act as President; and such officer shall act accordingly, until the disability be removed, or a President shall be elected. The President shall, at stated times, receive for his services a compensation, which shall neither be increased nor diminished during the period for which he shall have been elected; and he shall not receive within that period any other emolument from the United States or any of them. Before he enter on the execution of his office, he shall take the following oath or affirmation:— "I do solemnly swear (or affirm), that I will faithfully execute the office of President of the United States, and will, to the best of my
  • 35.
    ability, preserve, protect,and defend the Constitution of the United States." Sec. 2.—The President shall be commander-in-chief of the army and navy of the United States, and of the militia of the several States, when called into the actual service of the United States; he may require the opinion, in writing, of the principal officer in each of the executive departments, upon any subject relating to the duties of their respective offices, and he shall have power to grant reprieves and pardons for offenses against the United States, except in cases of impeachment. He shall have power, by and with the advice and consent of the Senate, to make treaties, provided two thirds of the senators present concur; and he shall nominate, and by and with the advice and consent of the Senate, shall appoint, ambassadors, other public ministers, and consuls, judges of the Supreme Court, and all other officers of the United States, whose appointments are not herein otherwise provided for, and which shall be established by law; but the Congress may, by law, vest the appointment of such inferior officers as they think proper, in the President alone, in the courts of law, or in the heads of departments. The President shall have power to fill up all vacancies that may happen during the recess of the Senate, by granting commissions, which shall expire at the end of their next session. Sec. 3.—He shall, from time to time, give to the Congress information of the state of the Union, and recommend to their consideration such measures as he shall judge necessary and expedient; he may, on extraordinary occasions, convene both houses, or either of them, and, in case of disagreement between them with respect to the time of adjournment, he may adjourn them to such time as he shall think proper; he shall receive ambassadors and other public ministers; he shall take care that the laws be faithfully executed; and shall commission all the officers of the United States.
  • 36.
    Sec. 4.—The President,Vice-president, and all civil officers of the United States, shall be removed from office on impeachment for and conviction of treason, bribery, or other high crimes and misdemeanors. ARTICLE III. Section 1.—The judicial power of the United States shall be vested in a Supreme Court, and in such inferior courts as the Congress may from time to time ordain and establish. The judges, both of the supreme and inferior courts, shall hold their offices during good behavior; and shall, at stated times, receive for their services a compensation, which shall not be diminished during their continuance in office. Sec. 2.—The judicial power shall extend to all cases, in law and equity, arising under this Constitution, the laws of the United States, and treaties made, or which shall be made, under their authority; to all cases affecting ambassadors, other public ministers, and consuls; to all cases of admiralty and maritime jurisdiction; to controversies to which the United States shall be a party; to controversies between two or more States, between a State and citizens of another State, between citizens of different States, between citizens of the same State claiming lands under grants of different States, and between a State, or the citizens thereof, and foreign States, citizens, or subjects. In all cases affecting ambassadors, other public ministers and consuls, and those in which a State shall be a party, the Supreme Court shall have original jurisdiction. In all the other cases before mentioned, the Supreme Court shall have appellate jurisdiction both as to law and fact, with such exceptions, and under such regulations, as the Congress shall make. The trial of all crimes, except in cases of impeachment, shall be by jury; and such trial shall be held in the State where the said crimes shall have been committed; but, when not committed within any
  • 37.
    State, the trialshall be at such place or places as the Congress may by law have directed. Sec. 3.—Treason against the United States shall consist only in levying war against them, or in adhering to their enemies, giving them aid and comfort. No person shall be convicted of treason unless on the testimony of two witnesses to the same overt act, or on confession in open court. The Congress shall have power to declare the punishment of treason, but no attainder of treason shall work corruption of blood or forfeiture, except during the life of the person attainted. ARTICLE IV. Section 1.—Full faith and credit shall be given in each State to the public acts, records, and judicial proceedings of every other State. And the Congress may by general laws prescribe the manner in which such acts, records, and proceedings shall be proved, and the effect thereof. Sec. 2.—The citizens of each State shall be entitled to all privileges and immunities of citizens in the several States. A person charged in any State with treason, felony, or other crime, who shall flee from justice, and be found in another State, shall, on demand of the executive authority of the State from which he fled, be delivered up, to be removed to the State having jurisdiction of the crime. No person held to service or labor in one State under the laws thereof, escaping into another, shall, in consequence of any law or regulation therein, be discharged from such service or labor, but shall be delivered up on claim of the party to whom such service or labor may be due. Sec. 3.—New States may be admitted by the Congress into this Union; but no new State shall be formed or erected within the jurisdiction of any other State; nor any State be formed by the junction of two or more States, or parts of States, without the
  • 38.
    consent of thelegislature of the States concerned, as well as of the Congress. The Congress shall have power to dispose of and make all needful rules and regulations respecting the territory or other property belonging to the United States; and nothing in this Constitution shall be so construed as to prejudice any claims of the United States, or of any particular State. Sec. 4.—The United States shall guarantee to every State in this Union a republican form of government, and shall protect each of them against invasion; and on application of the legislature, or of the executive (when the legislature can not be convened), against domestic violence. ARTICLE V. The Congress, whenever two thirds of both houses shall deem it necessary, shall propose amendments to this Constitution; or, on the application of the legislatures of two thirds of the several States, shall call a convention for proposing amendments, which, in either case, shall be valid, to all intents and purposes, as part of this Constitution, when ratified by the legislatures of three fourths of the several States, or by conventions in three fourths thereof, as the one or the other mode of ratification may be proposed by the Congress; Provided, that no amendment, which may be made prior to the year one thousand eight hundred and eight, shall in any manner affect the first and fourth clauses in the ninth section of the first article; and that no State, without its consent, shall be deprived of its equal suffrage in the Senate. ARTICLE VI. All debts contracted, and engagements entered into, before the adoption of this Constitution, shall be as valid against the United States under this Constitution as under the Confederation. This Constitution, and the laws of the United States which shall be made in pursuance thereof, and all treaties made, or which shall be made, under the authority of the United States, shall be the
  • 39.
    supreme law ofthe land; and the judges in every State shall be bound thereby, any thing in the constitution or laws of any State to the contrary notwithstanding. The senators and representatives before mentioned, and the members of the several State legislatures, and all executive and judicial officers, both of the United States and of the several States, shall be bound by oath or affirmation to support this Constitution; but no religious test shall ever be required as a qualification to any office or public trust under the United States. ARTICLE VII. The ratification of the conventions of nine States shall be sufficient for the establishment of this Constitution between the States so ratifying the same. Done in Convention by the unanimous consent of the States present, the seventeenth day of September, in the year of our Lord one thousand seven hundred and eighty-seven, and of the Independence of the United States of America the twelfth. In witness whereof we have hereunto subscribed our names. George Washington, President, and Deputy from Virginia. New Hampshire.—John Langdon, Nicholas Gilman. Massachusetts.—Nathaniel Gorham, Rufus King. Connecticut.—William Samuel Johnson, Roger Sherman. New York.—Alexander Hamilton. New Jersey.—William Livingston, David Bearly, William Patterson, Jonathan Dayton. Pennsylvania.—Benjamin Franklin, Thomas Mifflin, Robert Morris, George Clymer, Thomas Fitzsimons, Jared Ingersoll, James Wilson, Gouverneur Morris.
  • 40.
    Delaware.—George Read, GunningBedford, Jr., John Dickinson, Richard Bassett, Jacob Broom. Maryland.—James McHenry, Daniel of St. Thomas Jenifer, Daniel Carroll. Virginia.—John Blair, James Madison, Jr. North Carolina.—William Blount, Richard Dobbs Spaight, Hugh Williamson. South Carolina.—John Rutledge, Charles Cotesworth Pinckney, Charles Pinckney, Pierce Butler. Georgia.—William Few, Abraham Baldwin. Attest: William Jackson, Secretary.
  • 41.
    AMENDMENTS TO THE CONSTITUTION. ARTICLEI. Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech or of the press; or the right of the people peaceably to assemble, and to petition the government for a redress of grievances. ARTICLE II. A well-regulated militia being necessary to the security of a free State, the right of the people to keep and bear arms shall not be infringed. ARTICLE III. No soldier shall, in time of peace, be quartered in any house without the consent of the owner; nor in time of war, but in a manner to be prescribed by law. ARTICLE IV. The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated; and no warrants shall issue but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the person or things to be seized. ARTICLE V.
  • 42.
    No person shallbe held to answer for a capital or otherwise infamous crime, unless on a presentment or indictment of a grand jury, except in cases arising in the land or naval forces, or in the militia when in actual service in time of war or public danger; nor shall any person be subject, for the same offense, to be twice put in jeopardy of life or limb; nor shall be compelled, in any criminal case, to be a witness against himself; nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use without just compensation. ARTICLE VI. In all criminal prosecutions, the accused shall enjoy the right to a speedy and public trial, by an impartial jury of the State and district wherein the crime shall have been committed, which district shall have been previously ascertained by law; and to be informed of the nature and cause of the accusation; to be confronted with the witnesses against him; to have compulsory process for obtaining witnesses in his favor; and to have the assistance of counsel for his defense. ARTICLE VII. In suits at common law, where the value in controversy shall exceed twenty dollars, the right of trial by jury shall be preserved; and no fact tried by a jury shall be otherwise reexamined in any court of the United States than according to the rules of the common law. ARTICLE VIII. Excessive bail shall not be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted. ARTICLE IX. The enumeration in the Constitution of certain rights, shall not be construed to deny or disparage others retained by the people. ARTICLE X.
  • 43.
    The powers notdelegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people. ARTICLE XI. The judicial power of the United States shall not be construed to extend to any suit in law or equity, commenced or prosecuted against one of the United States by citizens of another State, or by citizens or subjects of any foreign State. ARTICLE XII. The electors shall meet in their respective States, and vote by ballot for President and Vice-president, one of whom, at least, shall not be an inhabitant of the same State with themselves; they shall name in their ballots the person voted for as President, and in distinct ballots the person voted for as Vice-president; and they shall make distinct lists of all persons voted for as President, and of all persons voted for as Vice-president, and of the number of votes for each, which lists they shall sign and certify and transmit sealed to the seat of the government of the United States, directed to the president of the Senate; the president of the Senate shall, in the presence of the Senate and House of Representatives, open all the certificates, and the votes shall then be counted; the person having the greatest number of votes for President shall be President, if such number be a majority of the whole number of electors appointed; and if no person have such majority, then from the persons having the highest numbers, not exceeding three on the list of those voted for as President, the House of Representatives shall choose immediately, by ballot, the President. But, in choosing the President, the votes shall be taken by States, the representation from each State having one vote; a quorum for this purpose shall consist of a member or members from two thirds of the States, and a majority of all the States shall be necessary to a choice. And if the House of Representatives shall not choose a President, whenever the right of choice shall devolve upon them, before the fourth day of March next
  • 44.
    following, then theVice-president shall act as President, as in the case of the death or other constitutional disability of the President. The person having the greatest number of votes as Vice-president shall be the Vice-president, if such number be a majority of the whole number of electors appointed; and if no person have a majority, then from the two highest numbers on the list, the Senate shall choose the Vice-president; a quorum for the purpose shall consist of two thirds of the whole number of senators, and a majority of the whole number shall be necessary to a choice. But no person constitutionally ineligible to the office of President shall be eligible to that of Vice-president of the United States. ARTICLE XIII. Section 1.—Neither slavery nor voluntary servitude, except as a punishment for crime, whereof the party shall have been duly convicted, shall exist within the United States, or any place subject to their jurisdiction. Sec. 2.—Congress shall have power to enforce this Article by appropriate legislation. ARTICLE XIV. Section 1.—All persons born or naturalized in the United States, and subject to the jurisdiction thereof, are citizens of the United States and of the State wherein they reside. No State shall make or enforce any law which shall abridge the privileges or immunities of citizens of the United States; nor shall any State deprive any person of life, liberty, or property, without due process of law, nor deny to any person within its jurisdiction the equal protection of the laws. Sec. 2.—Representatives shall be apportioned among the several States, according to their respective numbers, counting the whole number of persons in each State, excluding Indians not taxed. But when the right to vote at any election for choice of electors for President and Vice-president of the United States, representatives in Congress, the executive and judicial officers of a State, or the
  • 45.
    members of thelegislature thereof, is denied to any of the male inhabitants of such State being twenty-one years of age, and citizens of the United States, or in any way abridged, except for participation in rebellion or other crime, the basis of representation therein shall be reduced in the proportion which the number of such male citizens shall bear to the whole number of male citizens twenty-one years of age in such State. Sec. 3.—No person shall be a senator, or representative in Congress, or elector of President and Vice-president, or hold any office, civil or military, under the United States, or under any State, who, having previously taken an oath as a member of Congress, or as an officer of the United States, or as a member of any State legislature, or as an executive or judicial officer of any State, to support the Constitution of the United States, shall have engaged in insurrection or rebellion against the same, or given aid or comfort to the enemies thereof; but Congress may, by a vote of two thirds of each house, remove such disability. Sec. 4.—The validity of the public debt of the United States authorized by law, including debts incurred for payment of pensions, and bounties for services in suppressing insurrection or rebellion, shall not be questioned. But neither the United States, nor any State, shall assume or pay any debt or obligation incurred in aid of insurrection or rebellion against the United States, or any claim for the loss or emancipation of any slave; but all such debts, obligations, and claims shall be held illegal and void. Sec. 5.—The Congress shall have power to enforce by appropriate legislation the provisions of this Article. ARTICLE XV. Section 1.—The right of citizens of the United States to vote shall not be denied or abridged by the United States, or by any State, on account of race, color, or previous condition of servitude. Sec. 2.—The Congress shall have power to enforce this Article by appropriate legislation.
  • 47.
    INDEX. A Abercrombie, General, defeatof, at Ticonderoga, 143. Abraham, Plains of, battle of, 146. Acadia, named, 39; conquered by the English, 141. Acadians, exile of the, 141. Act, the Importation, 150; the Stamp, 151; the Embargo, 219; the Conscription, 308; the Resumption, 339. Adams, John, predicts American Independence, 150; nominates Washington, 161; on Declaration Committee, 165; Commissioner to Paris, 197; elected first Vice-president, 202; reelected Vice-president, 208; elected President, 210; administration of, 211-213; death of, 249. Adams, John Quincy, Secretary of State, 244;
  • 48.
    elected President, 247; sketchof, 248; administration of, 248, 249. Adams, Samuel, at Boston town-meeting, 150. Agricultural Department, established, 360. Aix-la-Chapelle, treaty of, 93. Alabama, admission of, 246. Alabama Claims, the, 330. Alabama, depredations by the, 315. Alaska, purchase of, 325. Algiers, tribute paid to, 210; subdued by Decatur, 242. Alexander, Pope, gives New World to Spain, 43. Algonquins, regions inhabited by the, 16. Allen, Ethan, captures Fort Ticonderoga, 159. America, discovery of, 25; derivation of name, 26. Amendments to the Constitution, fourteenth and fifteenth, 328. Amherst, general-in-chief of American forces, 144. Amnesty proclamation, the, 324. Anarchists, the Chicago, 352. Anderson, Robert, defends Fort Sumter, 282. André, John, capture of, 191. Andros, Sir Edmund, royal governor of New England, 86; demands surrender of Connecticut charter, 87;
  • 49.
    governor of NewYork, 101; treaty of with the Iroquois, 102. Antietam, battle of, 301. Anti-Federalist party, the, 201. Appomattox Courthouse, surrender at, 319. Arctic expeditions, 272. Argall, Samuel, abducts Pocahontas, 65; expedition against Acadia, 65; elected governor of Virginia, 67. Arizona Territory, organization of, 325. Arkansas, organization of Territory, 246; admission of State, 253. Arlington, Earl of, grant of Virginia to, 73; surrenders claim to Culpepper, 75. Arnold, Benedict, at Ticonderoga, 159; expedition against Canada, 162; at camp on Delaware, 172; at Bemis's Heights, 174; treason of, 190; in British army, 192. Arthur, Chester A., elected Vice-president, 341; becomes President, 346; sketch of, 346; administration of, 346-349. Atlanta, capture of, 312.
  • 50.
    Aztecs, regions inhabitedby the, 16. B Bacon, Nathaniel, rebellion led by, 74. Balboa discovers the Pacific, 27. Ball's Bluff, battle of, 291. Baltimore, Lord, secures charter for New Maryland, 122. Baltimore, siege of, 238; mob at fire on Union soldiers, 282. Bank of North America, organization of, 192. Bank of the United States, organization of, 207; rechartered, 242; rechartering vetoed by Jackson, 250; rechartering vetoed by Tyler, 258. Banks, N. P., in West Virginia, 297; at Cedar Mountain, 300; captures Port Hudson, 304; Red River expedition of, 310. Barclay, Commodore, on Lake Erie, 229. Battle of Antietam, 301; Atlanta, 312; Ball's Bluff, 291; Bemis's Heights, 174; Bennington, 173; Brandywine, 175; Brier Creek, 185;
  • 51.
    Buena Vista, 264; BullRun, 289, 300; Bunker Hill, 159; Cerro Gordo, 264; Champion Hills, 303; Chancellorsville, 307; Chapultepec, 267; Chickamauga, 304; Chippewa, 235; Chrysler's Field, 232; Churubusco, 266; City of Mexico, 265; Cold Harbor, 316; Corinth, 297; Cowpens, 193; Eutaw Springs, 195; Fair Oaks, 299; Five Oaks, 319; Fort Edward, 142; Fort Meigs, 228; Fort Stephenson, 229; Fredericksburg, 301; Frenchtown, 228; Germantown, 176; Gettysburg, 308;
  • 52.
    Guilford Courthouse, 194; KenesawMountain, 311; King's Mountain, 189; Lake Erie, 229; Long Island, 166; Lookout Mountain, 305; Lundy's Lane, 235; Malvern Hill, 299; Missionary Ridge, 305; Monmouth, 180; Monterey, 263; Murfreesborough, 297; Nashville, 312; New Orleans, 241; Palo Alto, 262; Plains of Abraham, 145; Plattsburgh, 237; Princeton, 171; Queenstown, 226; Resaca de la Palma, 262; Sag Harbor, 171; Sander's Creek, 188; San Gabriel, 264; Saratoga, 174; Savannah, 183;
  • 53.
    Shiloh, 293; Spottsylvania Courthouse,316; Talladega, 231; Thames, 230; Tippecanoe, 223; Trenton, 169; Vera Cruz, 264; Vicksburg, 303; White Plains, 168; Wilson's Creek, 290; Yorktown, 196. Beecher, Henry Ward, death of, 357. Bell, A. Graham, inventor of telephone, 357. Bellomont, Earl of, governor of New York, 103. Bemis's Heights, battle of, 174. Bennington, battle of, 264. Berkeley, Sir William, governor of Virginia, 71; elected by burgesses, 72; rebellion against, 74; oppression by, 75; grant of New Jersey to, 115; sells interest, 116. Beverley, Robert, royalist captain, 74. Black Hawk War, the, 251. Blaine, James G., Secretary of State under Garfield, 345;
  • 54.
    nominated for President,349; Secretary of State under Harrison, 362. Block, Adrian, explorations by, 55. Body of Liberties, 82. Boone, Daniel, colonizes Kentucky, 208. Booth, John Wilkes, assassinates Lincoln, 321; death of, 321. Boston, founded, 79; occupied by British, 154; massacre at, 154; tea party, 155; Port Bill, 156; siege of, 159-164; fire in, 331. Braddock, Edward, arrives in America, 139; defeat and death of, 140. Bradford, John, landing of, 51. Bradford, William, governor of Massachusetts, 77. Bragg, Braxton, at Murfreesborough, 297; at Chickamauga, 304; at Lookout Mountain and Missionary Ridge, 305. Brandywine, battle of, 175. Breckinridge, John C., elected Vice-president, 274; commands Confederate cavalry, 317. Breed's Hill, fortification of, 159.
  • 55.
    Brier Creek, battleof, 185. Brooklyn Bridge, construction of the, 347. Brown, John, insurrection led by, 276. Bryant, William Cullen, death of, 343. Buchanan, James, Secretary of State, 261; elected President, 274; sketch of, 275; administration of, 275-277. Buckner, S. B., defends Fort Donelson, 293. Buena Vista, battle of, 264. Bull Run, battles of, 289, 300. Bunker Hill, battle of, 159. Burgesses, House of, organized, 67; scene in, 152. Burgoyne, Gen., campaign of, 172-175; surrender of, 175. Burnside, Ambrose E., takes command of Army of the Potomac, 301; at Fredericksburg, 301; death of, 356. Burr, Aaron, elected Vice-president, 213; duel with Hamilton, 217; schemes of, 217. Butler, Benjamin F., at New Orleans, 296; at Fort Fisher, 314; joins Grant at Bermuda Hundred, 316;
  • 56.
    nominated for presidency,349. C Cabinet, the first, 205. Cable, Atlantic, laying of the, 275, 325. Cabot, John, voyage and discoveries of, 41. Cabot, Sebastian, voyage and explorations of, 42. Calhoun, John C., Secretary of War, 244; elected Vice-president, 247; for nullification, 251; death of, 272. California, conquest of, 264; discovery of gold in, 267; admission of, 268. Californians, regions inhabited by the, 16. Calvert, Sir Cecil, charter issued to, 123. Calvert, Sir George, in Maryland, 122. Cambridge, named, 81. Canadian insurrection, the, 256. Canonchet, King, violates treaty, 84; death of, 85. Canonicus, King of the Narragansetts, 107. Capitol of the United States, location of the, 213. Carolinas, history of the, 125-127; separation of the, 127. Caroline, firing of the, 256.
  • 57.
    Carteret, Sir George,proprietor of New Jersey, 115. Cartier, James, voyages of, 36, 37. Carver, John, governor of the Pilgrims, 51; death of, 76. Census of 1790 and 1800, 213; of 1810, 222; of 1870, 329; of 1880, 342; of 1890, 366. Centennial Exposition, the, 333. Centennial of the Republic, the, 362. Cerro Gordo, battle of, 264. Champion Hills, battle of, 303. Champlain, Lake, discovered, 40; expedition to, 141; abandoned by the French, 145. Champlain, Samuel, voyages of, 39, 40; founds Quebec, 39; discovers Lake Champlain, 40; governs New France, 40. Chancellorsville, battle of, 307. Chandler, Zackariah, death of, 343. Chapultepec, battle of, 267. Charlesbourg, Fort, settlement at, 47. Charleston, founded, 128;
  • 58.
    British repulsed at,164; taken by British, 187; evacuated, 195; taken by Sherman, 313. Charleston earthquake, the, 353. Charter Oak, the, 87. Charter of New England, 78. Chase, Salmon P., Secretary of the Treasury, 281; as Chief-justice presides at impeachment trial of Andrew Johnson, 327. Chen Lan Pin, the Chinese Minister, 340. Cherokees, regions inhabited by the, 16; difficulties with the, 252. Cherry Valley, massacre at, 181. Chesapeake, the affair of the, 233. Chesapeake Bay, explored, 61. Chicago, the great fire in, 330; the Anarchists in, 352. Chickamauga, battle of, 304. Chicora, first name of South Carolina, 29. Chinese Embassy, establishment of the, 340. Chippewa, battle of, 235. Chrysler's Field, battle of, 232. Churubusco, battle of, 266. Circumnavigation of the globe, 28. Civil Rights Bill, the, 326.