92509656
92509656
com
https://ebooknice.com/product/readings-from-programming-
with-c-46254828
OR CLICK HERE
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
https://ebooknice.com/product/practical-pc-6th-edition-2338054
ebooknice.com
ebooknice.com
(Ebook) New Perspectives on Computer Concepts 2011:
Comprehensive by June Jamrich Parsons, Dan Oja ISBN
0538744812
https://ebooknice.com/product/new-perspectives-on-computer-
concepts-2011-comprehensive-2394278
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
Programming with
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Important Notice: Media content referenced within the product description or the product
text may not be available in the eBook version.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Readings from Programming with C++ © 2022 Cengage Learning, Inc.
Kyla McMullen, Elizabeth Matthews, WCN: 02-300
June Jamrich Parsons
Unless otherwise noted, all content is © Cengage.
SVP, Higher Education Product Management:
ALL RIGHTS RESERVED. No part of this work covered by the copyright herein
Erin Joyner
may be reproduced or distributed in any form or by any means, except as
VP, Product Management: Thais Alencar permitted by U.S. copyright law, without the prior written permission of the
copyright owner.
Product Team Manager: Kristin McNary
Associate Product Manager: Tran Pham For product information and technology assistance, contact us at
Cengage Customer & Sales Support, 1-800-354-9706
Product Assistant: Tom Benedetto
or support.cengage.com.
Learning Designer: Mary Convertino
Senior Content Manager: Maria Garguilo For permission to use material from this text or product, submit all requests
online at www.cengage.com/permissions.
Digital Delivery Lead: David O’Connor
Marketing Development Manager: Cengage is a leading provider of customized learning solutions with
Samantha Best employees residing in nearly 40 different countries and sales in more than
125 countries around the world. Find your local representative at
Product Specialist: Mackenzie Paine
www.cengage.com.
IP Analyst: Ashley Maynard
To learn more about Cengage platforms and services, register or access
IP Project Manager: Cassidie Parker your online learning solution, or purchase materials for your course, visit
www.cengage.com.
Production Service: SPi Global
Notice to the Reader
Designer: Erin Griffin Publisher does not warrant or guarantee any of the products described
Cover Image Source: echo3005/ShutterStock.com herein or perform any independent analysis in connection with any of the
product information contained herein. Publisher does not assume, and
expressly disclaims, any obligation to obtain and include information other
than that provided to it by the manufacturer. The reader is expressly warned
to consider and adopt all safety precautions that might be indicated by the
activities described herein and to avoid all potential hazards. By following
the instructions contained herein, the reader willingly assumes all risks in
connection with such instructions. The publisher makes no representations or
warranties of any kind, including but not limited to, the warranties of fitness
for particular purpose or merchantability, nor are any such representations
implied with respect to the material set forth herein, and the publisher takes
no responsibility with respect to such material. The publisher shall not be
liable for any special, consequential, or exemplary damages resulting, in
whole or part, from the readers’ use of, or reliance upon, this material.
Printed in Mexico
Print Number: 01 Print Year: 2020
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents
prefacexiii Module 17
Polymorphism 309
Module 1
Computational Thinking 1 Module 18
Templates 319
Module 2
Programming Tools 15 Module 19
Linked List Data Structures 333
Module 3
Literals, Variables, and Constants 35 Module 20
Stacks and Queues 353
Module 4
Numeric Data Types and Expressions 49 Module 21
Trees and Graphs 371
Module 5
Character and String Data Types 63 Module 22
Algorithm Complexity and Big-O Notation 395
Module 6
Decision Control Structures 83 Module 23
Search Algorithms 411
Module 7
Repetition Control Structures 103 Module 24
Sorting Algorithms 427
Module 8
Arrays 125 Module 25
Processor Architecture 455
Module 9
Functions 145 Module 26
Data Representation 469
Module 10
Recursion 165 Module 27
Programming Paradigms 491
Module 11
Exceptions 185 Module 28
User Interfaces 507
Module 12
File Operations 205 Module 29
Software Development Methodologies 525
Module 13
Classes and Objects 231 Module 30
Pseudocode, Flowcharts, and Decision Tables 541
Module 14
Methods 245 Module 31
Unified Modeling Language 557
Module 15
Encapsulation 271
GLOSSARY 569
Module 16 Index 583
Inheritance 291
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents v
Module 4 Module 6
Numeric Data Types and Decision Control
Expressions 49 Structures 83
Primitive Data Types 50 If-Then Control Structures 84
Data Types 50 Control Structures 84
Primitive Data Types 50 Decision Logic 85
Composite Data Types 51 If-Then Structures 85
Numeric Data Types 52 Relational Operators 87
Integer Data Types 52 The Equal Operator 87
Floating-Point Data Types 53 Using Relational Operators 88
Mathematical Expressions 54 Boolean Expressions and Data Types 89
Arithmetic Operators 54 Multiple Conditions 91
Order of Operations 56 If-Then-Else Structures 91
Compound Operators 56 Nested-If Structures 93
Numeric Data Type Conversion 58 Else If Structures 96
Convert Integers and Floating-Point Numbers 58 Fall Through 97
Rounding Quirks 59 Conditional Logical Operators 100
Formatting Output 60 The AND Operator 100
Formatted Output 60 The OR Operator 101
Formatting Parameters 60 Summary 102
Summary 62 Key Terms 102
Key Terms 62
Module 7
Module 5 Repetition Control
CHARACTER AND STRING DATA TYPES 63 Structures 103
Character Data Types 64 Count-Controlled Loops 104
Working with Character Data 64 Loop Basics 104
Character Memory Allocation 65 Control Statements 105
Digits 66 For-Loops 105
Character Output Format 67 User-Controlled Loops 108
Character Manipulation 68
Counters and Accumulators 109
String Data Types 69 Loops That Count 109
Working with String Data 69 Loops That Accumulate 111
Escape Characters 70
String Indexes 71
Nested Loops 112
Loops Within Loops 112
String Functions 72
Inner and Outer Loops 113
String Manipulation 72
String Length 72 Pre-Test Loops 116
Change Case 73 While-Loops 116
Find the Location of a Character 74 Infinite Loops 117
Retrieve a Substring 75 Breaking Out of Loops 118
Concatenation and Typecasting 76 Post-Test Loops 120
Concatenated Output 76 Do-Loops 120
Concatenated Variables 77 Test Conditions and Terminating
Coercion and Typecasting 78 Conditions 123
Summary 80 Summary 124
Key Terms 81 Key Terms 124
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
vi Programming with C++
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents vii
Reading from a File 216 Method Cascading and Method Chaining 263
Opening a File for Reading 216 Calling Multiple Methods on the Same Object 263
Reading from a File 218 Using Constructors 266
Closing a File 222 Specifying How to Construct an Object 266
Closing Files after Use 222 Constructing an Object from Another Object 268
Trying to Close a File 222 Summary 269
Creating and Writing New Files 222
Key Terms 269
Creating a File 222
Opening a File for Writing 223 Module 15
Writing to and Appending a File 224
Anticipating Exceptions 228 Encapsulation 271
Summary 229 Components of Class Structure 271
Key Terms 230 Data Hiding 271
Designing Objects 273
Self-Reference Scope 276
Module 13 Accessor and Mutator Context 277
Classes and Objects 231 Viewing Data from an Object 277
Classes in Object-Oriented Programming 232 Changing Data in an Object 278
Representing the Real World with Code 232 Using Constructors 280
Using Classes 232 Parameters and Arguments 280
Class Components 233 Default Parameters and Constructor
Using Objects 236 Overloading 281
Creating Objects 236 Encapsulation Enforcement
Objects as Variables 238 with Access Modifiers 283
Object-Oriented Features and Principles 238 Access Modifiers 283
Using Static Elements in a Class 239 Public Variables and Methods 283
Private Variables and Methods 284
Static Member Variables 239
Static Methods 240 Interfaces and Headers 286
Static Classes 241 Interfaces 286
Characteristics of Objects Programming an Interface 287
in Object-Oriented Programs 242 Summary 290
Object Identity 242 Key Terms 290
Object State 242
Object Behavior 243 Module 16
Summary 244 Inheritance 291
Key Terms 244 Using Inheritance 291
Creating Classes from Other Classes 291
Module 14 Family Trees in OOP 292
Methods 245 Levels of Access 295
Necessary Components for Inheritance 296
Using Methods 245
Defining a Parent Class 296
Why Use Methods? 245 Defining a Child Class 297
Anatomy of a Method 251
Creating a Child Class That Inherits
Using Methods 251
from a Parent Class 298
Changing the Default Behavior
Inheritance Syntax 298
of an Object 255 Customizing Behavior 301
Using Objects as Regular Variables 255
Overloading Methods 258 Summary 307
Setting One Object to Equal Another 262 Key Terms 307
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
viii Programming with C++
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents ix
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
x Programming with C++
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents xi
Module 31
Unified Modeling Language 557
Purpose of Unified Modeling
Language (UML) 557
Communicating Ideas to Other Programmers 557
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
About the Authors
Dr. Kyla McMullen is a tenure-track faculty member published research in the areas of procedural genera-
in the University of Florida’s Computer & Information tion, video game enjoyment factors, and freshwater
Sciences & Engineering Department, specializing in algae identification with HCI.
Human-Centered Computing. Her research interests June Jamrich Parsons is an educator, digital book
are in the perception, applications, and development pioneer, and co-author of Texty and McGuffey Award-
of 3D audio technologies. Dr. McMullen has authored winning textbooks. She co-developed the first com-
over 30 manuscripts in this line of research and is the mercially successful multimedia, interactive digital
primary investigator for over 2 million dollars’ worth textbook; one that set the bar for platforms now
of sponsored research projects. being developed by educational publishers. Her
Dr. Elizabeth A. Matthews is an Assistant Professor of career includes extensive classroom teaching, prod-
Computer Science at Washington and Lee University. uct design for eCourseware, textbook authoring for
She has taught computer science since 2013 and has Course Technology and Cengage, Creative Strategist
been an active researcher in human–computer inter- for MediaTechnics Corporation, and Director of Con-
action and human-centered computing. Matthews has tent for Veative Virtual Reality Labs.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Acknowledgments
The unique approach for this book required a seasoned friends who help me to remain sane, remind me of who
team. Our thanks to Maria Garguilo who ushered the I am, and never let me forget whose I am.
manuscripts through every iteration and kept tight Elizabeth Matthews: I want to thank my parents,
rein on the schedule; to Mary E. Convertino who sup- Drs. Geoff and Robin Matthews, for their support and
plied her expertise in learning design; to Lisa R
uffolo understanding in my journey. I would also like to thank
for her excellent developmental edit; to Courtney my advisor, Dr. Juan Gilbert, for seeing my dream to
Cozzy who coordinated the project; to Kristin McNary the end. Finally, I would like to thank my cats, Oreo
for her leadership in Cengage’s computing materials; and Laptop, who made sure that writing this book was
to Rajiv Malkan (Lone Star College) for his instruc- interrupted as often as possible.
tional input; to Wade Schofield (Liberty University) June Jamrich Parsons: Computer programming can
for his reviewing expertise; and to John Freitas for his be a truly satisfying experience. The reward when a
meticulous code review. It was a pleasure to be part program runs flawlessly has to bring a smile even
of this professional and talented team. We hope that to the most seasoned programmers. Working with
instructors and students will appreciate our efforts three programming languages for this project at the
to provide this unique approach to computer science same time was certainly challenging but provided
and programming. insights that can help students understand com-
Kyla McMullen: Above all things, I would like to thank putational thinking. I’ve thoroughly enjoyed work-
God for giving me the gifts and talents that were uti- ing with the team to create these versatile learning
lized to write this book. I would like to thank my amaz- resources and would like to dedicate my efforts to
ing husband Ade Kumuyi for always being my rock, my mom, who has been a steadfast cheerleader for
sounding board, and biggest cheerleader. I thank my me throughout my career. To the instructors and stu-
parents, Rita and James McMullen for all of their sacri- dents who use this book, my hope is that you enjoy
fices to raise me. Last but not least, I thank my spirited programming as much as I do.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
MODULE
1
COMPUTATIONAL
THINKING
LEARNING OBJECTIVES:
1.1 ALGORITHMS 1.2.3 Differentiate the concepts of algorithms and
decomposition.
1.1.1 Define the term “algorithm” as a series of steps for
solving a problem or carrying out a task. 1.2.4 Identify examples of structural decomposition.
1.1.2 State that algorithms are the underlying logic for 1.2.5 Identify examples of functional decomposition.
computer programs. 1.2.6 Identify examples of object-oriented decomposition.
1.1.3 Define the term “computer program.” 1.2.7 Provide examples of decomposition in technology
1.1.4 Provide examples of algorithms used in everyday applications.
technology applications. 1.2.8 Explain how dependencies and cohesion relate to
1.1.5 Confirm that there can be more than one algorithm decomposition.
for a task or problem and that some algorithms 1.3 PATTERN IDENTIFICATION
may be more efficient than others.
1.3.1 Define the term “pattern identification” as a technique
1.1.6 Explain why computer scientists are interested in for recognizing similarities or characteristics among
algorithm efficiency. the elements of a task or problem.
1.1.7 List the characteristics of an effective algorithm. 1.3.2 Identify examples of fill-in-the-blank patterns.
1.1.8 Write an algorithm for accomplishing a simple, 1.3.3 Identify examples of repetitive patterns.
everyday technology application.
1.3.4 Identify examples of classification patterns.
1.1.9 Write an alternate algorithm for an everyday
technology task. 1.3.5 Provide examples of pattern identification in the real
world and in technology applications.
1.1.10 Select the more efficient of the two algorithms you
have written. 1.4 ABSTRACTION
1.2 DECOMPOSITION 1.4.1 Define the term “abstraction” as a technique for
generalization and for simplifying levels of complexity.
1.2.1 Define the term “decomposition” as a technique for
dividing a complex problem or solution into smaller 1.4.2 Explain why abstraction is an important computer
parts. science concept.
1.2.2 Explain why decomposition is an important tool for 1.4.3 Provide an example illustrating how abstraction can
computer scientists. help identify variables.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
2 PROGRAMMING WITH C++
1.4.4 Provide examples of technology applications that 1.4.6 Explain how the black box concept is an
have abstracted or hidden details. implementation of abstraction.
1.4.5 Provide an example illustrating the use of a class as 1.4.7 Identify appropriate levels of abstraction.
an abstraction of a set of objects.
1.1 ALGORITHMS
Algorithm Basics (1.1.1, 1.1.4)
A password might not be enough to protect your online accounts. Two-factor authentication adds an extra layer
of protection. A common form of two-factor authentication sends a personal identification number (PIN) to your
cell phone. To log in, you perform the series of steps shown in Figure 1-1.
The procedure for two-factor authentication is an example of an algorithm. In a general sense, an algorithm
is a series of steps for solving a problem or carrying out a task.
Algorithms exist for everyday tasks and tasks that involve technology. Here are some examples:
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 3
Q Programming algorithms tell the computer what to do. Can you tell which of these algorithms
is a programming algorithm?
Algorithm 1: Algorithm 2:
Connect to the website’s login page. Prompt the user to enter a user ID.
Enter your user ID. Prompt the user to enter a password.
Enter your password. Make sure that the user ID and password match.
Wait for a text message containing a PIN to If the user ID and password match:
arrive on your smartphone. Generate a random PIN.
On the website’s login page, enter the PIN. Send the PIN to user’s phone.
Prompt the user to enter the PIN.
If the PIN is correct:
Allow access.
A Algorithm 1 is not a programming algorithm because it outlines instructions for the user.
Algorithm 2 is a programming algorithm because it specifies what the computer is supposed
to do. When you formulate a programming algorithm, the instructions should be for the
computer, not the user.
There can be more than one programming algorithm for solving a problem or performing a task, but some
algorithms are more efficient than others.
Q Here are two algorithms for summing the numbers from 1 to 10. Which algorithm is more
efficient?
Algorithm 1: Algorithm 2:
Add 1 1 2 to get a total. Get the last number in the series (10).
Repeat these steps nine times: Divide 10 by 2 to get a result.
Get the next number. Add 10 1 1 to get a sum.
Add this number to the total. Multiply the result by the sum.
A Both algorithms contain four instructions, but Algorithm 2 is more efficient. You can use it to
amaze your friends by quickly calculating the total in only four steps. Algorithm 1 is also four
lines long, but two of the instructions are repeated nine times. Counting the first step, that’s
19 steps to complete this task!
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4 PROGRAMMING WITH C++
When formulating an algorithm, you can easily check to make sure it satisfies all the criteria for a good algo-
rithm. You can see how these criteria apply to an algorithm in Figure 1-2.
1.2 DECOMPOSITION
Decomposition Basics (1.2.1)
A mobile banking app contains many components. It has to provide a secure login procedure, allow users to
manage preferences, display account balances, push out alerts, read checks for deposit, and perform other tasks
shown in Figure 1-3.
The algorithm for such an extensive app would be difficult to formulate without dividing it into smaller parts,
a process called decomposition. When devising an algorithm for a complex problem or task, decomposition can
help you deal with smaller, more manageable pieces of the puzzle.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 5
Fraud alerts
Change user
Secure login
preferences
iStock.com/vector.S
Pay bills Withdrawals
Transfer money
Mobile banking
Two-factor
Balances Bill pay
authentication
Direct Money
deposits transfers
Structural decomposition is a process that identifies a hierarchy of structural units. At the lowest levels
of the hierarchy are modules, indicated in yellow in Figure 1-4, that have a manageable scope for creating
algorithms.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6 PROGRAMMING WITH C++
• Use a top-down approach. The nodes at the top break down into component parts in the nodes below them.
• Label nodes with nouns and adjectives, rather than verbs. For example, “Account management” is the
correct noun phrase, rather than a verb phrase, such as “Manage accounts.”
• Don’t worry about sequencing. Except for the actual login process, the components in a mobile bank-
ing system could be accessed in any order. This is a key difference between an algorithm and decom-
position. An algorithm specifies an order of activities, whereas decomposition specifies the parts of
a task.
Validate Compare
Generate Send PIN
Prompt for Prompt for user ID and Prompt user user-entered Handle
one-time to
user ID password password for PIN PIN to mismatches
PIN mobile
match generated PIN
Nodes in yellow
require further
decomposition.
Notice how the levels of the functional decomposition diagram get more specific until the nodes in the lowest
levels begin to reveal instructions that should be incorporated in an algorithm.
Here are some tips for constructing functional decomposition diagrams and deriving algorithms from them:
• Label nodes with verb phrases. In contrast to the nodes of a structural decomposition diagram, the
nodes of a functional decomposition are labeled with verb phrases that indicate “what” is to be done.
• Sequence from left to right. Reading left to right on the diagram should correspond to the sequence in
which steps in the algorithm are performed.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 7
Each node
represents an
object.
PIN generator
Methods
Login screen Attribute: One-time PIN describe what an
object can do.
Attribute: Entered user ID Method: Generate random PIN
Attribute: Entered password Method: Send PIN to mobile
number
Method: Display login boxes
Method: Verify entered user ID
and password
Method: Verify PIN
Method: Handle mismatches
Valid user
An object-oriented decomposition does not produce a hierarchy. Instead it produces a collection of objects
that can represent people, places, or things.
Tips for object-oriented decomposition:
• Node titles are nouns. Each node in the object-oriented decomposition diagram is labeled with a noun.
• Attributes are nouns. A node can contain a list of attributes, which relate to the characteristics of an object.
• Methods are verb phrases. An object can also contain methods, which are actions that an object can
perform. You may need to devise an algorithm for each method.
• Sketch in connection arrows. Connection arrows help you visualize how objects share data.
• Minimize dependencies. Although input and output may flow between nodes, changing the instructions
in one module or object should not require changes to others.
• Maximize cohesion. Each object or module contains attributes, methods, or instructions that perform a
single logical task or represent a single entity.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
8 PROGRAMMING WITH C++
Now, what if the challenge is to add the numbers from 1 to 200? That algorithm looks like this:
Get the last number in the series (200).
Divide 200 by 2 to get a result.
Add 200 1 1 to get a sum.
Multiply the result by the sum.
Notice a pattern? This fill-in-the-blank algorithm works for any number:
Get the last number in the series (____________________).
Divide ____________________ by 2 to get a result.
Add ____________________ 1 1 to get a sum.
Multiply the result by the sum.
The process of finding similarities in procedures and tasks is called pattern identification. It is a useful com-
putational thinking technique for creating algorithms that can be used and reused on different data sets. By recog-
nizing the pattern in the Amaze-Your-Friends math trick, you can use the algorithm to find the total of any series
of numbers.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 9
Recognizing this repetition, you can streamline the algorithm like this:
Get a password.
Repeat three times:
If the password is correct, allow access.
If the password is not correct, get the password again.
If the password is correct, allow access.
If the password is not correct, lock the account.
1.4 ABSTRACTION
Abstraction Basics (1.4.1, 1.4.2, 1.4.3)
Think back to the Amaze-Your-Friends math trick. By identifying a pattern, you formulated a general algorithm
that works for a sequence of any length, whether it is a sequence of 1 to 10 or 1 to 200.
Get the last number in the series (____________________).
Divide ____________________ by 2 to get a result.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
10 PROGRAMMING WITH C++
Q Can you envision a class that’s an abstraction of the collection of objects shown in Figure 1-7?
Budnyi/Shutterstock.com
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 11
In concept, a black box is anything that accepts some type of input and performs a specific process to
produce output without requiring an understanding of its internal workings. See Figure 1-9.
Black box
The black-box concept of abstraction is a fundamental aspect of computer science. Think about it. C
omputer
programs are abstractions. For example, you can use a social media app without knowing anything about the
programming that makes it work. The icons that you touch on the screen abstract away the details of the under-
lying programming.
Programmers make extensive use of abstraction within programs by creating a set of instructions that func-
tions like a black box. For example, you could bundle the instructions that handle login attempts into a black
box like the one in Figure 1-10.
Programming languages also have built-in abstractions that perform standard tasks. For example, the built-in
random function generates a random number when given a range, such as 1–100. You can incorporate the random
function in a program without knowing how it works internally.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
12 PROGRAMMING WITH C++
Black box
With experience, you’ll be able to identify useful abstractions and gauge the correct level of abstraction
to use.
SUMMARY
• Computational thinking techniques help programmers define problems, find solutions, delineate tasks,
and devise algorithms.
• An algorithm is a series of steps for solving a problem or carrying out a task. Programming algorithms
are the blueprints for computer programs.
• Standard algorithms exist for many computing tasks. When an algorithm does not exist, you can step
through a process manually and record the steps, or apply computational thinking techniques, such as
decomposition, pattern identification, and abstraction.
• Decomposition divides a complex problem or task into manageable units.
• Pattern identification reveals sequences and repetitive tasks that can lead to algorithm efficiencies.
• Abstraction is a key computer science concept that suppresses details, substitutes a generalization for
something specific, and allows an algorithm to work for multiple inputs.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 13
Key Terms
abstraction computer program objects
algorithm decomposition object-oriented decomposition
attributes Functional decomposition pattern identification
classes level of abstraction programming algorithm
classification patterns methods Structural decomposition
Computational thinking modules
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
MODULE
2
PROGRAMMING TOOLS
LEARNING OBJECTIVES:
2.1 PROGRAMMING LANGUAGES 2.3.5 Explain the purpose of a linker.
2.1.1 Explain the significance of the Hello World! program. 2.3.6 Associate virtual machines with Java and
bytecode.
2.1.2 Reiterate that programming languages are used to
create software. 2.3.7 Explain how an interpreter works.
2.1.3 Name some popular programming languages. 2.3.8 Differentiate between source code, bytecode,
object code, and executable code.
2.1.4 Distinguish between syntax and semantics in the
context of programming languages.
2.4 DEBUGGING TOOLS
2.1.5 Identify the key characteristics common to
2.4.1 Explain the purpose of debugging.
programming languages.
2.4.2 List common syntax errors.
2.1.6 Explain options for accessing programming
language implementations. 2.4.3 List common runtime errors.
2.1.7 Identify programming tools. 2.4.4 List common logic errors.
2.4.5 Classify program errors as syntax errors, logic
2.2 CODING TOOLS
errors, or runtime errors.
2.2.1 Define a program editor as the tool used to enter
2.4.6 Classify a debugger as utility software that allows
program code.
programmers to walk through the code of a target
2.2.2 List the types of editors that can be used for program to find errors.
coding.
2.4.7 List handy features provided by a debugger.
2.2.3 List some handy features of code editors and
explain how they help programmers create 2.5 IDEs AND SDKs
clean code.
2.5.1 List the purpose and typical features of an
2.2.4 Identify the basic structure and syntactical integrated development environment (IDE).
elements for a program written in the
2.5.2 Explain how IDEs support visual programming.
programming language you use.
2.5.3 Confirm that some IDEs are installed locally, while
2.3 BUILD TOOLS other IDEs are accessed online.
2.3.1 Explain the purpose of build tools. 2.5.4 Identify popular IDEs.
2.3.2 Explain the difference between source code and 2.5.5 List the purpose and typical features of a software
object code. development kit (SDK).
2.3.3 Describe how a compiler works. 2.5.6 Provide examples of SDK functionality.
2.3.4 Explain the purpose of a preprocessor. 2.5.7 Identify popular SDKs.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
16 PROGRAMMING WITH C++
Q Take a look at the Hello World! programs in Figure 2-1. They are written in three popular
programming languages, C11, Java, and Python. What differences can you identify?
A lot of backstory is bundled into the Hello World! program that can be applied to learning a programming
language. Let’s unbundle this famous program to discover the basics about your programming language.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 2 Programming Tools 17
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
18 PROGRAMMING WITH C++
Keyword Purpose
int Define a value as an integer.
float Define a value as a floating-point number.
char Define something as a letter, numeral, punctuation mark, or symbol.
class Define the characteristics of a person, place, or thing.
new Create an object based on the characteristics of a class.
if Execute program statements when a condition is true.
then
else
case Specify several alternative conditions or decisions.
switch
for Begin a section of code that repeats one or more times.
while
do
return Bring a value back from a function.
import Incorporate a prewritten code module in a program.
try Catch errors and handle them gracefully.
Q Suppose you want to code a program to output “Hello World!” 10 times. What keyword could
you use?
A Figure 2-3 lists the for, while, and do keywords for specifying code that repeats one or
more times.
You’ll acquire a vocabulary of keywords for your programming language gradually. Language references
provide a list of keywords and examples of their use. You can find language references online. In fact, it is often
helpful to create or find a “cheat sheet” of keywords to keep beside your computer as you learn a new language.
The syntax of a programming language is equivalent to the grammar rules of a written language, such as
English or Cyrillic. Syntax defines the order of words and the punctuation you are required to use when compos-
ing statements.
Various programming languages use different punctuation syntax. One of the early steps in learning a
programming language is to get a handle on its syntax.
Remember the different use of punctuation in the C11, Java, and Python Hello World! programs? Take a closer
look in Figure 2-4 and notice how punctuation helps to separate and structure the statements in a C11 program.
C++ Program
Statements end with a
#include <iostream>
semicolon.
using namespace std;
int main()
{
Curly braces for (int i = 1; i <= 10, i++)
separate blocks of {
statements. These cout << "Hello World!" << endl;
braces set off the cout << "Hola Mundo!" << endl;
statements in the }
return 0; Statements between
main() function.
} braces are indented.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 2 Programming Tools 19
Like C11, Java also uses lots of punctuation. Figure 2-5 points out how the commonly used style for placing
curly braces in Java is slightly different from C11. However, either style works equally well as long as the braces
are paired. The key is consistency in the project you are working on.
Python uses quite a different approach to punctuation. See if you can spot the differences in Figure 2-6.
Python Program
The colon indicates
for count in range(0, 10): the beginning of a
print("Hello World!") block of statements.
print("Hola Mundo!") Python does not use
Statements
braces.
in a block
are indented.
Pressing Enter or
Return marks the end
of a statement.
In C11 and Java, statements are enclosed in a structure of curly braces and each statement ends with a semi-
colon. In contrast, Python uses indents to structure statements, and the linefeed that is generated when you press
the Enter key marks the end of a statement. Remember the punctuation style for the language that you are using.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
20 PROGRAMMING WITH C++
Programming tools are available as system utility software that can be installed on your computer. Another
option is to use an online programming app.
Your programming toolbox includes the following essentials:
Coding tools provide a way for you to codify an algorithm.
Build tools transform your code into a binary format that a computer can execute.
Debugging tools help you test programs and track down errors.
You can acquire these programming tools as individual components, or you can look for a comprehensive
development environment. Let’s explore these tools in more detail to find out how they can help you develop
brilliant programs.
Word processor: Despite the attraction of visual programming tools, you will likely end up typing
some if not all of the statements for your programs. For that task, you could use a word processor, but
it embeds all kinds of codes for formatting and font effects which can’t be included in your high-level
code.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 2 Programming Tools 21
Text editor: A text editor such as Windows Notepad can produce plain ASCII text, but offers no
features designed to help programmers. Using a generic text editor is a bare-bones approach. There
are much better coding tools.
Code editor: A code editor is a type of text editor specially designed for entering high-level
programming code. It can help you correctly use punctuation and indents, as well as remember
variable names and ensure that you use valid keywords. Some handy features of code editors are
highlighted in Figure 2-8.
Punctuation monitoring
ensures that the braces
are paired. Autocomplete displays a
list of keywords as you
begin to type.
When using a code editor, you can simply type your commands. As you type, pay attention to color coding,
autocomplete, and other helpful cues that the editor offers.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
22 PROGRAMMING WITH C++
Statements: Just as human-readable text is divided into sentences and paragraphs, your code should be
divided into statements and blocks. A program statement is similar to a sentence; it contains one instruction. In
languages such as C11 and Java, statements end with a semicolon. In Python, you end a statement by pressing
the Enter or Return key.
Code blocks: A code block is similar to a paragraph; it contains multiple statements that have a specific
purpose. In C++ and Java, you use braces (also known as curly brackets) to enclose code blocks. In Python, code
blocks are indented.
Q Take a look at Figure 2-9 and see if you can identify comments, directives, the main()
function, statements, and code blocks.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 2 Programming Tools 23
Before a program can run, your code has to be converted into machine code consisting of machine language
instructions. This executable code is stored in an executable file that can be run, processed, and executed by
the microprocessor. Build tools convert your code into a program that a computer can execute.
As a programmer, you’ll eventually want to package your programs and distribute them so that they can be
installed on a digital device and run with a click, just like the Hola Mundo! program in Figure 2-10.
Hola Mundo!
A little background about build tools can help you understand some of the weird statements, such as
#include<iostream>, that you have to include in programs. Also, a passing knowledge of build tools such as
compilers, preprocessors, linkers, virtual machines, and interpreters will help you hold your own at late-night
parties in Silicon Valley.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
24 PROGRAMMING WITH C++
Hello.cpp Hello.o
Figure 2-11 When the compiler creates machine code, the resulting file is
executable
Q If a compiler is converting C11 code into machine code, what is the source code and what is
the object code?
A The C11 code is the source code. The machine code is the object code.
• Several steps are required to convert your code into a file containing an executable program.
• You may have to include preprocessor directives in your code.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 2 Programming Tools 25
Hola.cpp
The compiler
converts the source
code to object code
Your source
code
Hola.cpp
Hola.exe
Figure 2-12 Preprocessing, compiling, and linking the Hola Mundo! program
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Discovering Diverse Content Through
Random Scribd Documents
containing nine elders, two priests, three teachers, three deacons, and 123
members.
Monday, 12.—I sat in the city council, and recommended the repeal of the
ordinances entitled "An extra ordinance for the extra case of Joseph Smith,"
"An ordinance to prevent unlawful search or seizure of persons or property,
by foreign[1] process, in the city of Nauvoo," and "An ordinance regulating
the currency;" and they were repealed accordingly. The Memorial to
Congress, passed December 21, 1843, was again read, and signed by the
councilors, aldermen, mayor, recorder, and marshal.
"You must go in for it. Go to John Quincy Adams and ask him to call the
delegates from Massachusetts separate from the Illinois delegation, and
demand the same. Go to Henry Clay and other prominent men. Call public
meetings in the city of Washington. Take the saloon, publish the admittance
so much per ticket, invite the members of both houses to come and hear
you, and roar upon them. You may take all my writings you think anything
of and read to them, &c., and you shall prosper in the name of God. Amen."
The recorder presented the report of the attendance of the city council, from
which it appears that I have sat with them eleven sessions, from the 14th of
October, 1843, to the 16th of January, 1844, inclusive.
Accept, dear sir, the warmest respects of myself and Mrs. Smith, and
please present the same to your lady. In the meantime I remain your
friend and brother,
JOSEPH SMITH.
Wednesday, 14.—At home through the day. In the evening the assembly
room was filled by the brethren, when my "Views of the Powers and Policy
of the Government of the United States" was again read. I afterwards spoke
on the same subject at a considerable length.
The President stands at the head of these United States, and is the
mouth-piece of this vast republic. If he be a man of an enlightened
mind and a capacious soul,—if he be a virtuous man, a statesman, a
patriot, and a man of unflinching integrity,—if he possess the same
spirit that fired the souls of our venerable sires, who founded this great
commonwealth, and wishes to promote the good of the whole republic,
he may indeed be made a blessing to the community.
There is perhaps no body of people in the United States who are at the
present time more interested about the issue of the presidential contest
than are the Latter-day Saints. And our situation in regard to the two
great political parties is a most novel one. It is a fact well understood
that we have suffered great injustice from the State of Missouri, that
we have petitioned to the authorities of that state for redress in vain,
that we have also memorialized Congress under the late
administration, and have obtained the heartless reply that "Congress
has no power to redress your grievances."
After having taken all the legal and constitutional steps that we can, we
are still groaning under accumulated wrongs. Is there no power
anywhere to redress our grievances? Missouri lacks the disposition and
Congress lacks both the disposition and power (?); and thus fifteen
thousand inhabitants of these United States can with impunity be
dispossessed of their property; have their houses burned, their property
confiscated, many of their numbers murdered, and the remainder
driven from their homes and left to wander as exiles in this boasted
land of freedom and equal rights; and after appealing again and again
to the legally-constituted authorities of our land for redress, we are
coolly told by our highest tribunals, "We can do nothing for you."
But did the matter rest here, it would not be so bad. He was in the
presidential chair at the time of our former difficulties. We appealed to
him on that occasion, but we appealed in vain, and his sentiments are
yet unchanged.
But all these things are tolerable in comparison to what we have yet to
state. We have been informed from a respectable source that there is an
understanding between Mr. Benton, of Missouri, and Mr. Van Buren,
and a conditional compact entered into, that if Mr. Benton will use his
influence to get Mr. Van Buren elected, Van Buren when elected, shall
use his executive influence to wipe away the stain from Missouri by a
further persecution of the "Mormons," and wreaking out vengeance on
their heads, either by extermination or by some other summary
process. We could scarcely credit the statement; and we hope yet, for
the sake of humanity, that the suggestion is false: but we have too good
reason to believe that we are correctly informed.
If, then, this is the case, can we conscientiously vote for a man of this
description, and put the weapons into his hands to cut our throat with?
We cannot. And however much we might wish to sustain the
Democratic nomination, we cannot—we will not vote for Van Buren.
Our interests, our property, our lives, and the lives of our families are
too dear to us to be sacrificed at the shrine of party spirit and to gratify
party feelings. We have been sold once in the State of Missouri, and
our liberties bartered away by political demagogues, through executive
intrigue, and we wish not to be betrayed again by Benton and Van
Buren.
One great reason that we have for pursuing our present course is, that
at every election we have been made a political target for the filthy
demagogues in the country to shoot their loathsome arrows at. And
every story has been put into requisition to blast our fame from the old
fabrication of "walk on the water" down to "the murder of ex-
Governor Boggs." The journals have teemed with this filthy trash, and
even men who ought to have more respect for themselves—men
contending for the gubernatorial chair have made use of terms so
degrading, so mean, so humiliating, that a Billingsgate fisherwoman
would have considered herself disgraced with. We refuse any longer to
be thus bedaubed for either party. We tell all such to let their filth flow
in its own legitimate channel, for we are sick of the loathsome smell.
Friday, 16.—At home. This evening I spent two hours in the office. Settled
with Brother Whitney; gave him deed of several town lots, and took his
receipt in full.
PACIFIC INUENDO.
The very candid, pacific, and highly creditable advice which Governor
Ford has done himself the honor to address to "the citizens of Hancock
county, Mormons and all," and which appears in the Warsaw Signal of
the 14th instant, is like the balm of Gilead, well calculated to ease the
pain which has troubled the heads and hearts of the Carthaginians,
Warsawvians, and other over-jealous bodies for weal and woe.
Such is what the Latter-day Saints have ever sought at the hands of
those in authority; and with an approving conscience clear as the
crystal spring, and with a laudable intention warm as the summer
zephyr, and with a charitable prayer mellow as the morning dew, it is
now our highest consolation to hope that all difficulties will cease, and
give way to reason, sense, peace, and goodwill.
The Saints, if they will be humble and wise, can now practice what
they preach, and soften by good examples, rather than harden by a
distant course of conduct, the hearts of the people.
For general information, it may be well to say that there has never
been any cause for alarm as to the Latter-day Saints. The legislature of
Illinois granted a liberal charter for the City of Nauvoo; and let every
honest man in the Union who has any knowledge of her say whether
she has not flourished beyond the most sanguine anticipations of all.
And while they witness her growing glory, let them solemnly testify
whether Nauvoo has willfully injured the country, county, or a single
individual one cent.
With the strictest scrutiny publish the facts, whether a particle of law
has been evaded or broken: virtue and innocence need no artificial
covering. Political views and party distinctions never should disturb
the harmony of society; and when the whole truth comes before a
virtuous people, we are willing to abide the issue.
We will here refer to the three last dismissals upon writs of habeas
corpus, of Joseph Smith, when arrested under the requisitions of
Missouri.
And the third, in July, 1843, was tried at the city of Nauvoo, before the
Municipal Court of said city; and as no exceptions to that discharge
have been taken, and as the governor says there is "evidence on the
other side to show that the sheriff of Lee county voluntarily carried Mr.
Reynolds (who had Mr. Smith in custody,) to the city of Nauvoo
without any coercion on the part of any one," it must be admitted that
that decision was just!
The Messrs. Averys, who were unlawfully transported out of this state,
have returned to their families in peace; and there seems to be no
ground for contention, no cause for jealousy, and no excuse for a
surmise that any man, woman, or child will suffer the least
inconvenience from General Smith, the charter of Nauvoo, the city of
Nauvoo, or even any of her citizens.
"A soft answer turneth away wrath," says the wise man; and it will be
greatly to the credit of the Latter-day Saints to show the love of God,
by now kindly treating those who may have, in an unconscious
moment, done wrong; for truly said Jesus, Pray for thine enemies.
His own good, his family's good, his neighbor's good, his country's
good, and all good seem to whisper to every person—The governor
has told you what to do. Now do it.
The constitution expects every man to do his duty; and when he fails
the law urges him; or should he do too much, the same master rebukes
him.
Should reason, liberty, law, light, and philanthropy now guide the
destinies of Hancock county with as much sincerity as has been
manifested for her notoriety or welfare, there can be no doubt that
peace, prosperity, and happiness will prevail, and that future
generations as well as the present one will call Governor Ford a
peacemaker. The Latter-day Saints will, at all events, and profit by the
instruction, and call upon honest men to help them cherish all the love,
all the friendship, all the courtesy, all the kindly feelings, and all the
generosity that ought to characterize clever people in a clever
neighborhood, and leave candid men to judge which tree exhibits the
best fruit—the one with the most clubs and sticks thrown into its
boughs and the grass trodden down under it, or the one with no sticks
in it, some dead limbs, and rank grass growing under it; for by their
signs ye can know their fruit, and by the fruit ye know the trees.
Our motto, then, is Peace with all! If we have joy in the love of God,
let us try to give a reason of that joy, which all the world cannot
gainsay or resist. And may be, like as when Paul started with
recommendations to Damascus to persecute the Saints, some one who
has raised his hand against us with letters to men in high places may
see a light at noonday, above the brightness of the sun, and hear the
voice of Jesus saying, "It is hard for thee to kick against the pricks."
The High Council met and settled several cases of difficulty betwixt
brethren.
A very large assembly of the Saints met at the stand, near the Temple, when
I preached a lengthy discourse.
Four p.m., went to my office with Hyrum and two gentlemen from St.
Louis. Heard Dr. Richards read my correspondence with Senator Calhoun,
and Phelps read my "Views of the Power and Policy of the General
Government."
Monday, 19.—At nine a.m. went to my office with Dr. Bernhisel, who
proposed some alterations in my views of the government. Phelps read the
same, and the doctor seemed better pleased with it than before.
If the editor breathes out that old sulphurous blast, let him go and
besmear his reputation and the reputation of those that uphold him
with soot and dirt, but as for us and all honest men, we will act well
our part, for there the honor lies.
Respectfully, I am
JOSEPH SMITH.
I told them to tell Brother Wight I had no counsel to give him on the
subject. He is there on his own ground and must act on his own
responsibility, and do what he thinks best in relation to the Indians,
understanding the laws and nature of the subject as well as I can here, and
he shall never be brought into difficulty about it by us.
Ice left the west bank of the river, opposite the lower brick house.
Very pleasant the past two weeks; the pleasantest February I ever saw.
Monday, 26.—At home. A cold wind from the north. Rainy, dull day.
Mailed my "Views of Powers and Policy," &c., to the President and cabinet,
supreme judges, senators, representatives, principal newspapers in the
United States, (all the German), and many postmasters and individuals.
At four, p.m., steamboat General Brooke passed up the river: first boat this
season. No ice in sight.
Having now raised the name of our General and Prophet to the head of
our columns, it becomes us, as Latter day Saints, to be prudent and
energetic in the cause that we pursue, and not let any secondary
influences control our minds or govern our proceedings.
The step that we have taken is a bold one, and requires our united
efforts, perseverance, and diligence; but important as it may be, it is no
greater than others have taken, and they have conceived that they had a
right, without molestation, to pursue that course, and to vote for that
man whose election they in their wisdom thought would be most
conducive to the public weal.
Some have nominated Henry Clay, some Colonel Johnson, others John
C. Calhoun, others Daniel Webster, and others Martin Van Buren.
Those several committees, unquestionably thought that they had each
of them made the wisest selection in naming the man of their choice.
They selected their several candidates because they thought they were
the wisest, the greatest statesmen, and the most competent to fill the
presidential chair, whilst they severally thought that the other
candidates were incompetent.
Moses Smith and Rufus Beach volunteered to join the Oregon exploring
expedition.
Letters from the elders show a rapid progress of the work of the Lord in
different parts of the Union. Elder John E. Page has gone to Washington for
the purpose of proclaiming to the rulers of our nation the principles of
eternal truth. By a letter received from him, we learn he has been preaching
and baptizing in Boston and vicinity.
We would remind our brethren, the elders, who have at sundry times
been sent forth as flaming heralds, messengers of the everlasting
Gospel, who proclaim a message of salvation to their fellow-men,
thereby gathering and bringing up to Zion the scattered elect of God, to
be taught more perfectly he principles of salvation; that whilst their
message is abroad we have had our mission to remain at Nauvoo and
to participate with the Saints in the blessing of poverty, if such it may
be called; amid sickness and distress, in the vexations and turmoils of
the unruly and ungodly, for which no man has paid us, for days, weeks,
months, and years; that our time has been spent in endeavoring to
settle difficulties, set in order the things needful to salvation; in trying
to reconcile and cement the feelings of our brethren to each other in
the spirit of the Gospel; whilst at times, circumstances of a more
painful nature have been presented.
We regret to have it to say that in some instances our efforts have been
fruitless; for after we have found in them an obstinate and unyielding
spirit to the principles of right, we have (reluctantly) been compelled
to sever them from the Church as withered branches.
We have to say that baptism in such cases is not valid and cannot
profit. We here continue to say; let such expelled person first be
reconciled to his injured brother, and bring forth fruit mete for
repentance; or, in case of dissatisfaction with our decision, take an
appeal and reverse it, if found wrong.
WILLIAM MARKS,
CHARLES C. RICH,
Presidents.
Counselors.
The Times and Seasons of March 1st presents my name to the public as
candidate for president of the United States.
Jonathan Dunham filed his bonds with the recorder, and took the oath of
office as wharf-master of the city of Nauvoo.
Elder Wilford Woodruff very sick; the 37th anniversary of his birthday.
George Coray came in, and said he was sent by Lyman Wight to get
sheep, &c, to carry to the Pine country, to receipt for them, or agree to
pay lumber.
President Joseph suggested that it was best to let the Nauvoo House
remain as it is until the temple is completed, as we need the temple
more than anything else.
Elder Haws said there was some dissatisfaction about being sent from
the Pinery without accounts, &c., and could not have credit on tithing,
and one month at the Pinery is only called fifteen days here.
President Joseph told them that they should have their number of days
in full. "We will let the Nauvoo house stand until the temple is done,
and we will put all our forces on the Temple, turn our lumber towards
the Temple, and cover it in this fall, and sell the remainder to get
blasting powder, fuse, rope, steel, &c."
And when the temple is completed, no man shall pass the threshold till
he has paid five dollars; and every stranger shall pay five dollars
towards liquidating the cash debts on the Temple, and I will not have
the house dirtied.
Let Woodworth go to the pinery, take the things wanted, and bring
back the lumber, and his wages go on as usual.
Let a special conference be called on the 6th of April, and all the elders
called home who can come. Let the people of this city come together
on Thursday, at nine o'clock in the morning. After two or three
lectures, we will call on the people to fill up the boxes with liberal
contributions, to procure cash materials for the temple.
I need not assert what the wisest of the wise admit without argument—
that General Smith is the greatest statesman of the 19th century. Then
why should not the nation secure to themselves his superior talents,
that they may rise higher and higher in the estimation of the crowned
heads of the nations and exalt themselves through his wisdom?
Brother Arlington, look well to "General Smith's Views," and his letter
to Calhoun, and comprehend him fully. Say to the New York Herald,
now is the time for your exaltation; raise your standard high, sound
your trumpet long and loud, support General Smith and myself at the
next election; and when we are exalted, you shall not be forgotten.
Hold forth no false shadows to honest men; yet though there is but one
best piece to the fatted calf, yet there are many good slices; therefore
you will not forget the "Advertiser," "Niles Register," "Globe," &c.,
&c.
Commence at your own mansion and stay not, only for electioneering
purposes, till by some popular route you reach Nauvoo; and if you
preach Mormonism it will help you. At every stage, tavern, boat and
company, expose the wickedness of Martinism in saying, if he is
elected President, he will annihilate the Mormons, and proclaim the
sycophancy of the candidates generally, and uphold Joseph against
every aspersion and you shall triumph gloriously.
We have many things to say to you, which we must keep till we see
you face to face.
My words are the words of your friends here—Come and see us.
Brother Joseph's, Young's, and Bernhisel's respects to you. Mrs.
Richards' kind respects with mine to yourself and love to all yours.
WILLARD RICHARDS.
Footnotes:
Tuesday, March 5, 1844.—I saw Hyrum Kimball at Bryant's store, and gave
him a lecture on his resisting the ordinances of the city, by telling the
captains of the steamboats they need not pay wharfage, &c.
At two, p.m., met with the City Council. I copy the minutes:—
Mayor stated that he had called the council, because that when the
wharf-master called on the steamboats for wharfage, the officers of the
boats declined paying, assigning as a reason that Hyrum Kimball and
— Morrison had told them that they owned the land, and they need
pay no wharfage to the city; and he called the council to know their
views on the subject, as he had told Hyrum Kimball that he should see
the ordinances executed; and if the boats did not pay, he should blow
them up and all those who upheld them in resisting the ordinances.
Every measure is taken to palsy the hands of the officers of the city;
and I want to know how to remedy the evil, or whether I shall abandon
the ordinances, &c.
Alderman Harris said that it was the mayor's duty to enforce the
ordinances of the city, and that no man has a right to build a wharf
without leave from the city council.
Councilor Phelps said, if Water street extended round the city, then
Kimball had been constructing a nuisance.
Mayor spoke in explanation, and said that Kimball said, if the city
would make a wharf, he would give up what he had done.
Councilor Orson Spencer said he wished the mayor to execute the law
of the city.
Councilor Taylor said, "I go in for executing the laws of the city."
Marshal stated that Morrison said he had a bond for a deed to low-
water mark, and the city could not take his personal rights, and he
objected to the boats paying wharfage.
Councilor Orson Pratt said, if Kimball or Morrison or any one else has
built wharves since that street was laid out, they could get no damages.
Moved by Brigham Young that the city council instruct the Mayor to
order the supervisor to open Water street from Joseph Smith's store
north to the north line of the city.
Councilor Warrington said the upper stone house was in the street.
Mayor said that was the greatest nuisance there was in the street.
Councilor Young thought they were aldermen all the time or none of
the time.
Mayor said he wanted all the aldermen to be added to the city council.
Mayor said if he had been elected alderman and filed his bonds, he
would act as councilor and magistrate.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com