(eBook PDF) Brief C++: Late Objects, 3rd Edition
download
https://ebooksecure.com/product/ebook-pdf-brief-c-late-
objects-3rd-edition/
Download full version ebook from https://ebooksecure.com
We believe these products will be a great fit for you. Click
the link to download now, or visit ebooksecure.com
to discover even more!
(eBook PDF) Big C++: Late Objects 3rd Edition
http://ebooksecure.com/product/ebook-pdf-big-c-late-objects-3rd-
edition/
(eBook PDF) Java Concepts: Late Objects, 3rd Edition
http://ebooksecure.com/product/ebook-pdf-java-concepts-late-
objects-3rd-edition/
(eBook PDF) Big Java Late Objects 2nd Edition
http://ebooksecure.com/product/ebook-pdf-big-java-late-
objects-2nd-edition/
(eBook PDF) Starting Out with C++: From Control
Structures through Objects, Brief Version 8th Edition
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-through-objects-brief-version-8th-
edition/
(eBook PDF) Java How to Program, Late Objects Global
Edition 11th Edition
http://ebooksecure.com/product/ebook-pdf-java-how-to-program-
late-objects-global-edition-11th-edition/
(eBook PDF) Starting Out with C++: Early Objects 9th
Edition
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
early-objects-9th-edition/
C++ How to Program Early Objects Version 9th Edition
(eBook PDF)
http://ebooksecure.com/product/c-how-to-program-early-objects-
version-9th-edition-ebook-pdf/
Starting Out with C++: Early Objects 9th Edition by
Tony Gaddis (eBook PDF)
http://ebooksecure.com/product/starting-out-with-c-early-
objects-9th-edition-by-tony-gaddis-ebook-pdf/
(eBook PDF) Starting Out with C++ from Control
Structures to Objects 9th Edition
http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-to-objects-9th-edition/
BriefC++
Cay Horstmann
Late Objects
3/e
vi Preface
• Selecting Test Cases
• Hand-Tracing
• Storyboards
• Solve a Simpler Problem First
• Reusable Functions
• Stepwise Refinement
• Adapting Algorithms
• Discovering Algorithms by Manipulating Physical Objects
• Draw a Picture (pointer diagrams)
• Tracing Objects (identifying state and behavior)
• Discovering Classes
A visual approach motivates the reader and eases navigation.
Photographs present visual analogies that explain
the nature and behavior of computer concepts.
Step-by-step figures illustrate complex program
operations. Syntax boxes and example tables pres-
ent a variety of typical and special cases in a com-
pact format. It is easy to get the “lay of the land” by
browsing the visuals, before focusing on the textual
material.
Focus on the essentials while being
© Terraxplorer/iStockphoto.
technically accurate.
An encyclopedic coverage is not helpful for a Visual features help the reader
beginning programmer, but neither is the oppo- with navigation.
site—reducing the material to a list of simplistic
bullet points. In this book, the essentials are presented in digestible chunks, with sep-
arate notes that go deeper into good practices or language features when the reader is
ready for the additional information. You will not find artificial over-simplifications
that give an illusion of knowledge.
Reinforce sound engineering practices.
A multitude of useful tips on software quality and common errors encourage the
development of good programming habits. The focus is on test-driven development,
encouraging students to test their programs systematically.
Engage with optional engineering and business exercises.
End-of-chapter exercises are enhanced with problems from scientific and business
domains. Designed to engage students, the exercises illustrate the value of program-
ming in applied fields.
Preface vii
New to This Edition
Updated for Modern Versions of C++
A number of features of the C++ 2011 and C++ 2014 standards are described either as
recommended “best practice” or as Special Topics.
New and Reorganized Topics
The book now supports two pathways into object-oriented programming and inher-
itance. Pointers and structures can be covered before introducing classes. Alterna-
tively, pointers can be deferred until after the implementation of classes.
A sequence of Worked Examples and exercises introduces “media computa-
tion”—generating and modifying images, sounds, and animations.
Lower-Cost, Interactive Format
This third edition is published as a lower-cost Enhanced E-Text that supports active
learning through a wealth of interactive activities. These activities engage and prepare
students for independent programming and the Review Exercises, Practice Exercises,
and Programming Projects at the end of each E-Text chapter. The Enhanced E-Text
may also be bundled with an Abridged Print Companion, which is a bound book that
contains the entire text for reference, but without exercises or practice material.
Interactive learning solutions are expanding every day, so to learn more about
these options or to explore other options to suit your needs, please contact your
Wiley account manager (www.wiley.com/go/whosmyrep) or visit the product information
page for this text on wiley.com (http://wiley.com/college/sc/horstmann).
The Enhanced E-Text is designed to enable student practice without the instructor
assigning the interactivities or recording their scores. If you are interested in assign-
ing and grading students’ work on them, ask your Wiley Account Manager about the
online course option implemented in the Engage Learning Management System. The
Engage course supports the assignment and automatic grading of the interactivities.
Engage access includes access to the Enhanced E-Text.
Features in the Enhanced E-Text
The interactive Enhanced E-Text guides students from the basics to writing complex
programs. After they read a bit, they can try all of the interactive exercises for that
section. Active reading is an engaging way for students to ensure that students are
prepared before going to class.
There five types of interactivities:
Code Walkthrough Code Walkthrough activities ask students to trace through a
segment of code, choosing which line will be executed next and entering the new
values of variables changed by the code’s execution. This activity simulates the hand-
tracing problem solving technique taught in Chapters 3 and 4—but with immediate
feedback.
viii Preface
Example Table Example table activities make the student the active participant in
building up tables of code examples similar to those found in the book. The tables
come in many different forms. Some tables ask the student to determine the output of
a line of code, or the value of an expression, or to provide code for certain tasks. This
activity helps students assess their understanding of the reading—while it is easy to
go back and review.
Algorithm Animation An algorithm animation shows the essential steps of an
algorithm. However, instead of passively watching, students get to predict each step.
When finished, students can start over with a different set of inputs. This is a surpris-
ingly effective way of learning and remembering algorithms.
Rearrange Code Rearrange code activities ask the student to arrange lines of code
by dragging them from the list on the right to the area at left so that the resulting code
fulfills the task described in the problem. This activity builds facility with coding
structure and implementing common algorithms.
Object Diagram Object diagram activities ask the student to create a memory
diagram to illustrate how variables and objects are initialized and updated as sample
code executes. The activity depicts variables, objects, and references in the same way
as the figures in the book. After an activity is completed, pressing “Play” replays the
animation. This activity goes beyond hand-tracing to illuminate what is happening in
memory as code executes.
Code Completion Code completion activities ask the student to finish a partially-
completed program, then paste the solution into CodeCheck (a Wiley-based online
code evaluator) to learn whether it produces the desired result. Tester classes on the
CodeCheck site run and report whether the code passed the tests. This activity serves
as a skill-building lab to better prepare the student for writing programs from scratch.
A Tour of the Book
This book is intended for a two-semester introduction to programming that may also
include algorithms and data structures. The organization of chapters offers the same
flexibility as the previous edition; dependencies among the chapters are also shown
in Figure 1.
Part A: Fundamentals (Chapters 1–8)
The first six chapters follow a traditional approach to basic programming concepts.
Students learn about control structures, stepwise refinement, and arrays. Objects are
used only for input/output and string processing. Input/output is first covered in
Chapter 2, which may be followed by an introduction to reading and writing text
files in Section 8.1.
In a course for engineers with a need for systems and embedded programming,
you will want to cover Chapter 7 on pointers. Sections 7.1 and 7.4 are sufficient for
using pointers with polymorphism in Chapter 10.
File processing is the subject of Chapter 8. Section 8.1 can be covered sooner for
an introduction to reading and writing text files. The remainder of the chapter gives
additional material for practical applications.
Preface ix
Part B: Object-Oriented Design (Chapters 9–10)
After students have gained a solid foundation, they are ready to tackle the implemen-
tation of classes. Chapters 9 and 10 introduce the object-oriented features of C++.
Chapter 9 introduces class design and implementation. Chapter 10 covers inheritance
and polymorphism. By the end of these chapters, students will be able to implement
programs with multiple interacting classes.
Any subset of these chapters can be incorporated into a custom print version of
this text; ask your Wiley sales representative for details, or visit customselect.wiley.com
to create your custom order.
Appendices
Appendices A and B summarize C++ reserved words and operators. Appendix C
lists character escape sequences and ASCII character code values. Appendix D docu-
ments all of the library functions and classes used in this book.
Appendix E contains a programming style guide. Using a style guide for program
ming assignments benefits students by directing them toward good habits and reduc-
ing gratuitous choice. The style guide is available in electronic form on the book’s
companion web site so that instructors can modify it to reflect their preferred style.
Appendix F, available in the E-Text, introduces common number systems used in
computing.
Fundamentals
1. Introduction
Object-Oriented Design
2. Fundamental
Data Types
3. Decisions
4. Loops
A gentle
introduction to recursion
5. Functions is optional.
Section 8.1
contains the core
material
6. Arrays
6. Iteration
and Vectors
7. Pointers 8. Streams 9. Classes
Sections 10. Inheritance
7.1 and 7.4 are
required
Figure 1 Chapter Dependencies
x Preface
Web Resources
This book is complemented by a complete suite of online resources. Go to www.wiley.
com/go/bclo3 to visit the online companion sites, which include
• Source code for all example programs in the book and its Worked Examples, plus
additional example programs.
• Worked Examples that apply the problem-solving steps in the book to other
realistic examples.
• Lecture presentation slides (for instructors only).
• Solutions to all review and programming exercises (for instructors only).
• A test bank that focuses on skills, not just terminology (for instructors only). This
extensive set of multiple-choice questions can be used with a word processor or
imported into a course management system.
• “CodeCheck” assignments that allow students to work on programming prob-
lems presented in an innovative online service and receive immediate feedback.
Instructors can assign exercises that have already been prepared, or easily add
their own. Visit http://codecheck.it to learn more.
Pointers in the print
companion describe what
students will find in their WORKED EXAMPLE 2.1
Computing Travel Time
E-Text or online.
Learn how to develop a hand calculation to compute the time that
a robot requires to retrieve an item from rocky terrain. See your
.
E-Text or visit wiley.com/go/bclo3
Courtesy of NASA.
EXAMPLE CODE See how_to_1/scores_vector in your companion code for a solution using vectors instead of arrays.
Walkthrough xi
A Walkthrough of the Learning Aids
The pedagogical elements in this book work together to focus on and reinforce key
concepts and fundamental principles of programming, with additional tips and detail
organized to support and deepen these fundamentals. In addition to traditional
features, such as chapter objectives and a wealth of exercises, each chapter contains
elements geared to today’s visual learner.
106 Chapter 4 Loops
4.3 The for Loop
Throughout each chapter,
It often happens that you want to execute a sequence of
margin notes show where The for loop is
used when a statements a given number of times. You can use a while
value runs from a loop that is controlled by a counter, as in the following
new concepts are introduced starting point to an
ending point with a
example:
and provide an outline of key ideas. constant increment
or decrement.
counter = 1; // Initialize the counter
while (counter <= 10) // Check the counter
{
cout << counter << endl;
counter++; // Update the counter
}
Because this loop type is so common, there is a special
form for it, called the for loop (see Syntax 4.2).
for (counter = 1; counter <= 10; counter++)
{
© Enrico Fianchini/iStockphoto.
cout << counter << endl;
}
You can visualize the
Some people call this loop count-controlled. In contrast, for loop as an orderly
the while loop of the preceding section can be called an sequence of steps.
event-controlled loop because it executes until an event
occurs (for example, when the balance reaches the target). Another commonly-used
Annotated syntax boxes term for a count-controlled loop is definite. You know from the outset that the loop
body will be executed a definite number of times––ten times in our example. In con-
provide a quick, visual overview trast, you do not know how many iterations it takes to accumulate a target balance.
Such a loop is called indefinite.
of new language constructs.
Syntax 4.2 for Statement
These three
expressions should be related.
See Programming Tip 4.1.
Annotations explain This initialization The loop is This update is
required components happens once
before the loop starts.
executed while
this condition is true.
executed after
each iteration.
and point to more information for (int i = 5; i <= 10; i++)
on common errors or best practices The variable i is
{
sum = sum + i;
This loop executes 6 times.
associated with the syntax. defined only in this
for loop.
}
See Programming Tip 4.3.
The for loop neatly groups the initialization, condition, and update expressions
together. However, it is important to realize that these expressions are not executed
together (see Figure 3).
Analogies to everyday objects are
used to explain the nature and behavior
of concepts such as variables, data
Like a variable in a computer types, loops, and more.
program, a parking space has
an identifier and contents.
xii Walkthrough
Memorable photos reinforce
analogies and help students
remember the concepts. pie(fruit) pie(fruit)
A recipe for a fruit pie may say to use any kind of fruit.
Here, “fruit” is an example of a parameter variable.
Apples and cherries are examples of arguments.
Problem Solving sections teach
techniques for generating ideas and
6.5 Problem Solving: Discovering Algorithms by Manipulating Physical Objects 277
evaluating proposed solutions, often
using pencil and paper or other Now how does that help us with our problem, switching the first and the second
half of the array?
artifacts. These sections emphasize Let’s put the first coin into place, by swapping it with the fifth coin. However, as
C++ programmers, we will say that we swap the coins in positions 0 and 4:
that most of the planning and problem
solving that makes students successful
happens away from the computer.
Next, we swap the coins in positions 1 and 5:
HOW TO 1.1
Describing an Algorithm with Pseudocode
This is the first of many “How To” sections in this book that give you step-by-step proce-
dures for carrying out important tasks in developing computer programs.
Before you are ready to write a program in C++, you need to develop an algorithm—a
method for arriving at a solution for a particular problem. Describe the algorithm in pseudo-
code––a sequence of precise steps formulated in English. To illustrate, we’ll devise an algo-
rithm for this problem:
How To guides give step-by-step
Problem Statement You have the choice of buying one guidance for common programming
of two cars. One is more fuel efficient than the other, but also
more expensive. You know the price and fuel efficiency (in miles tasks, emphasizing planning and
per gallon, mpg) of both cars. You plan to keep the car for ten
years. Assume a price of $4 per gallon of gas and usage of 15,000 testing. They answer the beginner’s
miles per year. You will pay cash for the car and not worry about
financing costs. Which car is the better deal? © dlewis33/Getty Images. question, “Now what do I do?” and
Step 1 Determine the inputs and outputs. integrate key concepts into a
In our sample problem, we have these inputs: problem-solving sequence.
• purchase price1 and fuel efficiency1, the price and fuel efficiency (in mpg) of the first car
• purchase price2 and fuel efficiency2, the price and fuel efficiency of the second car
WORKED EXAMPLE 1.1
Writing an Algorithm for Tiling a Floor
Problem Statement Your task is to tile a rectangular bathroom floor with alternating Worked Examples apply
black and white tiles measuring 4 × 4 inches. The floor dimensions, measured in inches, are
multiples of 4. the steps in the How To to
Step 1 Determine the inputs and outputs.
a different example, showing
The inputs are the floor dimensions (length × width), how they can be used to
measured in inches. The output is a tiled floor.
Step 2 Break down the problem into smaller tasks.
plan, implement, and test
A natural subtask is to lay one row of tiles. If you can a solution to another
solve that task, then you can solve the problem by lay-
ing one row next to the other, starting from a wall, until programming problem.
you reach the opposite wall.
How do you lay a row? Start with a tile at one wall.
If it is Names
Table 3 Variable white, putin
a black
C++ one next to it. If it is black, put
a white one next to it. Keep going until you reach the
Variable Name wall. The row will contain width / 4 tiles.
opposite Comment © rban/iStockphoto.
Step 3 Describe each subtask in pseudocode.
can_volume1 Variable names consist of letters, numbers, and the underscore
character.
x In mathematics, you use short variable names such as x or y. This is
legal in C++, but not very common, because it can make programs
harder to understand (see Programming Tip 2.1). Example tables support beginners
!
Can_volume Caution: Variable names are case sensitive. This variable name is with multiple, concrete examples.
different from can_volume.
These tables point out common
6pack Error: Variable names cannot start with a number.
can volume Error: Variable names cannot contain spaces.
errors and present another quick
double Error: You cannot use a reserved word as a variable name. reference to the section’s topic.
ltr/fl.oz Error: You cannot use symbols such as . or /
Walkthrough xiii
Consider the function call illustrated in Figure 3:
double result1 = cube_volume(2); Progressive figures trace code
• The parameter variable side_length of the cube_volume function is created. ❶
• The parameter variable is initialized with the value of the argument that was
segments to help students visualize
passed in the call. In our case, side_length is set to 2. ❷ the program flow. Color is used
• The function computes the expression side_length * side_length * side_length,
which has the value 8. That value is stored in the variable volume. ❸ consistently to make variables and
• The function returns. All of its variables are removed. The return value is trans-
ferred to the caller, that is, the function calling the cube_volume function. ❹
other elements easily recognizable.
1 Function call result1 =
double result1 = cube_volume(2);
1 Initialize counter
side_length = for (counter = 1; counter <= 10; counter++)
{
cout << counter << endl;
2 Initializing function parameter variable counter = 1 }
result1 =
double result1 = cube_volume(2);
2 Check condition
side_length = for (counter = 1; counter <= 10; counter++)
2
{
cout << counter << endl;
counter = 1 }
3 About to return to the caller result1 =
3 Execute loop body
for (counter = 1; counter <= 10; counter++)
side_length = 2 {
double volume = side_length * side_length * side_length;
return volume; cout << counter << endl;
volume = 8 counter = 1 }
4 After function call result1 = 8 4 Update counter
for (counter = 1; counter <= 10; counter++)
double result1 = cube_volume(2); {
cout << counter << endl;
counter = 2 }
Figure 3 Parameter Passing
5 Check condition again
for (counter = 1; counter <= 10; counter++)
{
cout << counter << endl;
counter = 2 }
Figure 3 Execution of a for Loop
Optional engineering exercises
engage students with applications
from technical fields. Engineering P7.12 Write a program that simulates the control
software for a “people mover” system, a set of
driverless trains that move in two concentric
circular tracks. A set of switches allows trains
to switch tracks.
In your program, the outer and inner tracks
should each be divided into ten segments.
Each track segment can contain a train that
moves either clockwise or counterclockwise.
sec02/cube.cpp A train moves to an adjacent segment in its track or, if that segment is occupied, to
the adjacent segment in the other track.
1 #include <iostream>
2 Define a Segment structure. Each segment has a pointer to the next and previous
3 using namespace std; segments in its track, a pointer to the next and previous segments in the other track,
4
5 /**
6 Computes the volume of a cube.
7 @param side_length the side length of the cube
8 @return the volume
9 */
10 double cube_volume(double side_length)
11 {
12 double volume = side_length * side_length * side_length;
13 return volume;
14 }
15
16 int main()
Program listings are carefully
17
18
{
double result1 = cube_volume(2); designed for easy reading,
double result2 = cube_volume(10);
19
20 cout << "A cube with side length 2 has volume " << result1 << endl; going well beyond simple
21 cout << "A cube with side length 10 has volume " << result2 << endl;
22 color coding. Functions are set
23 return 0;
24 } off by a subtle outline.
Program Run
A cube with side length 2 has volume 8
A cube with side length 10 has volume 1000
EXAMPLE CODE See sec04 of your companion code for another implementation of the earthquake program that you
Additional example programs
saw in Section 3.3. Note that the get_description function has multiple return statements.
are provided with the companion
code for students to read, run,
and modify.
xiv Walkthrough
Common Errors describe the kinds Common Error 2.1
Using Undefined Variables
of errors that students often make, You must define a variable before you use it for the first time. For example, the following
with an explanation of why the errors sequence of statements would not be legal:
double can_volume = 12 * liter_per_ounce;
occur, and what to do about them. double liter_per_ounce = 0.0296;
In your program, the statements are compiled in order. When the compiler reaches the first
statement, it does not know that liter_per_ounce will be defined in the next line, and it reports
an error.
Programming Tip 3.6
Hand-Tracing
A very useful technique for understanding whether a program
works correctly is called hand-tracing. You simulate the pro-
gram’s activity on a sheet of paper. You can use this method with
pseudocode or C++ code.
Get an index card, a cocktail napkin, or whatever sheet of
Programming Tips explain paper is within reach. Make a column for each variable. Have the
program code ready. Use a marker, such as a paper clip, to mark
good programming practices, the current statement. In your mind, execute statements one at a
time. Every time the value of a variable changes, cross out the old
and encourage students to be value and write the new value below the old one.
© thomasd007/iStockphoto.
For example, let’s trace the tax program with the data from the
more productive with tips and program run in Section 3.4. In lines 13 and 14, tax1 and tax2 are
Hand-tracing helps you
understand whether a
initialized to 0. program works correctly.
techniques such as hand-tracing. 6 int main()
7 {
8 const double RATE1 = 0.10; marital
9 const double RATE2 = 0.25; tax1 tax2 income status
10 const double RATE1_SINGLE_LIMIT = 32000;
11 const double RATE1_MARRIED_LIMIT = 64000; 0 0
12
13 double tax1 = 0;
14 double tax2 = 0;
15
In lines 18 and 22, income and marital_status are initialized by input statements.
16 double income;
17 cout << "Please enter your income: ";
18 cin >> income; marital
19 tax1 tax2 income status
20 cout << "Please enter s for single, m for married: ";
21 string marital_status; 0 0 80000 m
22 cin >> marital_status;
23
Because marital_status is not "s", we move to the else
branch of the outer if statement (line 36).
24 if (marital_status == "s")
25 {
26 if (income <= RATE1_SINGLE_LIMIT)
27
28
{ Special Topic 6.5
tax1 = RATE1 * income;
29
30
}
else The Range-Based for Loop
31 {
32 C++ 11 introduces a convenient syntax for visiting all elements in a “range” or sequence of ele-
tax1 = RATE1 * RATE1_SINGLE_LIMIT;
ments. This loop displays all elements in a vector:
vector<int> values = {1, 4, 9, 16, 25, 36};
for (int v : values)
{
cout << v << " ";
}
Special Topics present optional In each iteration of the loop, v is set to an element of the vector. Note that you do not use an
index variable. The value of v is the element, not the index of the element.
topics and provide additional If you want to modify elements, declare the loop variable as a reference:
for (int& v : values)
explanation of others. {
v++;
}
This loop increments all elements of the vector.
You can use the reserved word auto, which was introduced in Special Topic 2.3, for the type
of the element variable:
for (auto v : values) { cout << v << " "; }
The range-based for loop also works for arrays:
int primes[] = { 2, 3, 5, 7, 11, 13 };
for (int p : primes)
{
cout << p << " ";
}
Computing & Society 7.1 Embedded Systems The range-based for loop is a convenient shortcut for visiting or updating all elements of a
vector or an array. This book doesn’t use it because one can achieve the same result by looping
An embedded sys- would feel comfortable upgrading the duced in large volumes. Thus, the pro-
tem is a computer software in their washing machines grammer of an embedded system has
over index values. But if you like the more concise form, and use C++ 11 or later, you should
system that controls a device. The or automobile engines. If you ever a much larger economic incentive to certainly consider using it.
device contains a processor and other handed in a programming assignment conserve resources than the desktop
EXAMPLE CODE See special_topic_5 of your companion code for a program that demonstrates the range-based
hardware and is controlled by a com- that you believed to be correct, only to software programmer. Unfortunately, for loop.
puter program. Unlike a personal have the instructor or grader find bugs trying to conserve resources usually
computer, which has been designed in it, then you know how hard it is to makes it harder to write programs that
to be flexible and run many different write software that can reliably do its work correctly.
computer programs, the hardware task for many years without a chance C and C++ are commonly used
and software of an embedded system of changing it. Quality standards are languages for developing embedded
are tailored to a specific device. Com- especially important in devices whose systems.
puter controlled devices are becom- failure would destroy property or
ing increasingly common, ranging endanger human life. Many personal
from washing machines to medical computer purchasers buy computers Computing & Society presents social
equipment, cell phones, automobile that are fast and have a lot of stor-
engines, and spacecraft.
Several challenges are specific to
age, because the investment is paid
back over time when many programs
and historical topics on computing—for
programming embedded systems.
Most importantly, a much higher stan-
are run on the same equipment. But
the hardware for an embedded device
interest and to fulfill the “historical and
dard of quality control applies. Ven-
dors are often unconcerned about
is not shared––it is dedicated to one
device. A separate processor, memory,
social context” requirements of the
bugs in personal computer software,
because they can always make you
and so on, are built for every copy of
the device. If it is possible to shave a ACM/IEEE curriculum guidelines.
install a patch or upgrade to the next few pennies off the manufacturing © Courtesy of Professor Prabal Dutta.
version. But in an embedded system, cost of every unit, the savings can add
that is not an option. Few consumers up quickly for devices that are pro- The Controller of an Embedded System
Walkthrough xv
Interactive activities in the E-Text
engage students in active reading as they…
Trace through a code segment
Build an example table
Explore common algorithms
Arrange code to fulfill a task
Complete a program and Create a memory diagram
get immediate feedback
Acknowledgments xvii
Acknowledgments
Many thanks to Don Fowley, Graig Donini, Dan Sayre, Ryann Dannelly, David
Dietz, Laura Abrams, and Billy Ray at John Wiley & Sons for their help with this
project. An especially deep acknowledgment and thanks goes to Cindy Johnson for
her hard work, sound judgment, and amazing attention to detail.
I am grateful to Mark Atkins, Ivy Technical College, Katie Livsie, Gaston College,
Larry Morell, Arkansas Tech University, and Rama Olson, Gaston College, for
their contributions to the supplemental material. Special thanks to Stephen Gilbert,
Orange Coast Community College, for his help with the interactive exercises.
Every new edition builds on the suggestions and experiences of new and prior
reviewers, contributors, and users. We are very grateful to the individuals who pro-
vided feedback, reviewed the manuscript, made valuable suggestions and contribu-
tions, and brought errors and omissions to my attention. They include:
Charles D. Allison, Utah Valley State College
Fred Annexstein, University of Cincinnati
Mark Atkins, Ivy Technical College
Stefano Basagni, Northeastern University
Noah D. Barnette, Virginia Tech
Susan Bickford, Tallahassee Community College
Ronald D. Bowman, University of Alabama, Huntsville
Robert Burton, Brigham Young University
Peter Breznay, University of Wisconsin, Green Bay
Richard Cacace, Pensacola Junior College, Pensacola
Kuang-Nan Chang, Eastern Kentucky University
Joseph DeLibero, Arizona State University
Subramaniam Dharmarajan, Arizona State University
Mary Dorf, University of Michigan
Marty Dulberg, North Carolina State University
William E. Duncan, Louisiana State University
John Estell, Ohio Northern University
Waleed Farag, Indiana University of Pennsylvania
Evan Gallagher, Polytechnic Institute of New York University
Stephen Gilbert, Orange Coast Community College
Kenneth Gitlitz, New Hampshire Technical Institute
Daniel Grigoletti, DeVry Institute of Technology, Tinley Park
Barbara Guillott, Louisiana State University
Charles Halsey, Richland College
Jon Hanrath, Illinois Institute of Technology
Neil Harrison, Utah Valley University
Jurgen Hecht, University of Ontario
Steve Hodges, Cabrillo College
xviii Acknowledgments
Jackie Jarboe, Boise State University
Debbie Kaneko, Old Dominion University
Mir Behrad Khamesee, University of Waterloo
Sung-Sik Kwon, North Carolina Central University
Lorrie Lehman, University of North Carolina, Charlotte
Cynthia Lester, Tuskegee University
Yanjun Li, Fordham University
W. James MacLean, University of Toronto
LindaLee Massoud, Mott Community College
Adelaida Medlock, Drexel University
Charles W. Mellard, DeVry Institute of Technology, Irving
Larry Morell, Arkansas Tech University
Ethan V. Munson, University of Wisconsin, Milwaukee
Arun Ravindran, University of North Carolina at Charlotte
Philip Regalbuto, Trident Technical College
Don Retzlaff, University of North Texas
Jeff Ringenberg, University of Michigan, Ann Arbor
John P. Russo, Wentworth Institute of Technology
Kurt Schmidt, Drexel University
Brent Seales, University of Kentucky
William Shay, University of Wisconsin, Green Bay
Michele A. Starkey, Mount Saint Mary College
William Stockwell, University of Central Oklahoma
Jonathan Tolstedt, North Dakota State University
Boyd Trolinger, Butte College
Muharrem Uyar, City College of New York
Mahendra Velauthapillai, Georgetown University
Kerstin Voigt, California State University, San Bernardino
David P. Voorhees, Le Moyne College
Salih Yurttas, Texas A&M University
A special thank you to all of our class testers:
Pani Chakrapani and the students of the University of Redlands
Jim Mackowiak and the students of Long Beach City College, LAC
Suresh Muknahallipatna and the students of the University of Wyoming
Murlidharan Nair and the students of the Indiana University of South Bend
Harriette Roadman and the students of New River Community College
David Topham and the students of Ohlone College
Dennie Van Tassel and the students of Gavilan College
CONTENTS
PREFACE v CE2 Using Uninitialized Variables 33
SPECIAL FEATURES xxiv PT1 Choose Descriptive Variable Names 33
PT2 Do Not Use Magic Numbers 34
QUICK REFERENCE xxviii
ST1 Numeric Types in C++ 34
ST2 Numeric Ranges and Precisions 35
1 INTRODUCTION 1 ST3 Defining Variables with auto 35
1.1 What Is Programming? 2 2.2 Arithmetic 36
Arithmetic Operators 36
1.2 The Anatomy of a Computer 3
Increment and Decrement 36
C&S Computers Are Everywhere 5
Integer Division and Remainder 36
1.3 Machine Code and Programming Converting Floating-Point Numbers to
Languages 5 Integers 37
C&S Standards Organizations 7 Powers and Roots 38
CE3 Unintended Integer Division 39
1.4 Becoming Familiar with Your
CE4 Unbalanced Parentheses 40
Programming Environment 7
CE5 Forgetting Header Files 40
PT1 Backup Copies 10
CE6 Roundoff Errors 41
1.5 Analyzing Your First Program 11
PT3 Spaces in Expressions 42
CE1 Omitting Semicolons 13
ST4 Casts 42
ST1 Escape Sequences 13
ST5 Combining Assignment and Arithmetic 42
1.6 Errors 14 C&S The Pentium Floating-Point Bug 43
CE2 Misspelling Words 15
2.3 Input and Output 44
1.7 PROBLEM SOLVING Algorithm Design 16 Input 44
The Algorithm Concept 16 Formatted Output 45
An Algorithm for Solving an Investment
Problem 17
2.4 PROBLEM SOLVING First Do It By Hand 47
Pseudocode 18 WE1 Computing Travel Time 48
From Algorithms to Programs 19 HT1 Carrying out Computations 48
HT1 Describing an Algorithm with WE2 Computing the Cost of Stamps 51
Pseudocode 19 2.5 Strings 51
WE1 Writing an Algorithm for Tiling a Floor 21 The string Type 51
Concatenation 52
2 FUNDAMENTAL DATA String Input 52
String Functions 52
TYPES 25
C&S International Alphabets and Unicode 55
2.1 Variables 26
Variable Definitions 26 3 DECISIONS 59
Number Types 28
Variable Names 29 3.1 The if Statement 60
The Assignment Statement 30 CE1 A Semicolon After the if Condition 63
Constants 31 PT1 Brace Layout 63
Comments 31
PT2 Always Use Braces 64
CE1 Using Undefined Variables 33
PT3 Tabs 64
xix
xx Contents
PT4 Avoid Duplication in Branches 65 4.4 The do Loop 111
ST1 The Conditional Operator 65 PT4 Flowcharts for Loops 111
3.2 Comparing Numbers and Strings 66 4.5 Processing Input 112
CE2 Confusing = and == 68 Sentinel Values 112
CE3 Exact Comparison of Floating-Point Reading Until Input Fails 114
Numbers 68 ST1 Clearing the Failure State 115
PT5 Compile with Zero Warnings 69 ST2 The Loop-and-a-Half Problem and the
ST2 Lexicographic Ordering of Strings 69 break Statement 116
HT1 Implementing an if Statement 70 ST3 Redirection of Input and Output 116
WE1 Extracting the Middle 72 4.6 PROBLEM SOLVING Storyboards 117
C&S Dysfunctional Computerized Systems 72
4.7 Common Loop Algorithms 119
3.3 Multiple Alternatives 73
Sum and Average Value 119
ST3 The switch Statement 75 Counting Matches 120
3.4 Nested Branches 76 Finding the First Match 120
CE4 The Dangling else Problem 79 Prompting Until a Match is Found 121
PT6 Hand-Tracing 79 Maximum and Minimum 121
Comparing Adjacent Values 122
3.5 PROBLEM SOLVING Flowcharts 81
HT1 Writing a Loop 123
3.6 PROBLEM SOLVING Test Cases 83 WE1 Credit Card Processing 126
PT7 Make a Schedule and Make Time for
Unexpected Problems 84 4.8 Nested Loops 126
WE2 Manipulating the Pixels in an Image 129
3.7 Boolean Variables and Operators 85
CE5 Combining Multiple Relational Operators 88
4.9 PROBLEM SOLVING Solve a Simpler
CE6 Confusing && and || Conditions 88
Problem First 130
ST4 Short-Circuit Evaluation of Boolean 4.10 Random Numbers and Simulations 134
Operators 89 Generating Random Numbers 134
ST5 De Morgan’s Law 89 Simulating Die Tosses 135
3.8 APPLICATION Input Validation 90 The Monte Carlo Method 136
C&S Artificial Intelligence 92 C&S Digital Piracy 138
4 LOOPS 95 5 FUNCTIONS 141
4.1 The while Loop 96 5.1 Functions as Black Boxes 142
CE1 Infinite Loops 100 5.2 Implementing Functions 143
CE2 Don’t Think “Are We There Yet?” 101 PT1 Function Comments 146
CE3 Off-by-One Errors 101 5.3 Parameter Passing 146
C&S The First Bug 102 PT2 Do Not Modify Parameter Variables 148
4.2 PROBLEM SOLVING Hand-Tracing 103 5.4 Return Values 148
4.3 The for Loop 106 CE1 Missing Return Value 149
PT1 Use for Loops for Their Intended ST1 Function Declarations 150
Purpose Only 109 HT1 Implementing a Function 151
PT2 Choose Loop Bounds That Match WE1 Generating Random Passwords 152
Your Task 110 WE2 Using a Debugger 152
PT3 Count Iterations 110
5.5 Functions Without Return Values 153
Contents xxi
5.6 PROBLEM SOLVING Reusable Functions 154 6.4 PROBLEM SOLVING Adapting
5.7 PROBLEM SOLVING Stepwise Algorithms 198
Refinement 156 HT1 Working with Arrays 200
PT3 Keep Functions Short 161 WE1 Rolling the Dice 203
PT4 Tracing Functions 161 6.5 PROBLEM SOLVING Discovering Algorithms by
PT5 Stubs 162 Manipulating Physical Objects 203
WE3 Calculating a Course Grade 163 6.6 Two-Dimensional Arrays 206
5.8 Variable Scope and Global Variables 163 Defining Two-Dimensional Arrays 207
PT6 Avoid Global Variables 165 Accessing Elements 207
5.9 Reference Parameters 165 Locating Neighboring Elements 208
Computing Row and Column Totals 208
PT7 Prefer Return Values to Reference
Parameters 169 Two-Dimensional Array Parameters 210
CE2 Omitting the Column Size of a Two-
ST2 Constant References 170
Dimensional Array Parameter 212
5.10 Recursive Functions (Optional) 170 WE2 A World Population Table 213
HT2 Thinking Recursively 173
6.7 Vectors 213
C&S The Explosive Growth of Personal
Computers 174 Defining Vectors 214
Growing and Shrinking Vectors 215
Vectors and Functions 216
6 ARRAYS AND VECTORS 179 Vector Algorithms 216
Two-Dimensional Vectors 218
6.1 Arrays 180
PT2 Prefer Vectors over Arrays 219
Defining Arrays 180 ST5 The Range-Based for Loop 219
Accessing Array Elements 182
Partially Filled Arrays 183
CE1 Bounds Errors 184 7 POINTERS AND
PT1 Use Arrays for Sequences of Related STRUCTURES 223
Values 184
C&S Computer Viruses 185 7.1 Defining and Using Pointers 224
Defining Pointers 224
6.2 Common Array Algorithms 185
Accessing Variables Through Pointers 225
Filling 186 Initializing Pointers 227
Copying 186
CE1 Confusing Pointers with the Data to Which
Sum and Average Value 186 They Point 228
Maximum and Minimum 187
PT1 Use a Separate Definition for Each Pointer
Element Separators 187 Variable 229
Counting Matches 187
ST1 Pointers and References 229
Linear Search 188
Removing an Element 188 7.2 Arrays and Pointers 230
Inserting an Element 189 Arrays as Pointers 230
Swapping Elements 190 Pointer Arithmetic 230
Reading Input 191 Array Parameter Variables Are Pointers 232
ST1 Sorting with the C++ Library 192 ST2 Using a Pointer to Step Through
ST2 A Sorting Algorithm 192 an Array 233
ST3 Binary Search 193 CE2 Returning a Pointer to a Local Variable 234
PT2 Program Clearly, Not Cleverly 234
6.3 Arrays and Functions 194
ST3 Constant Pointers 235
ST4 Constant Array Parameters 198
xxii Contents
7.3 C and C++ Strings 235 8.5 Command Line Arguments 274
The char Type 235 C&S Encryption Algorithms 277
C Strings 236 HT1 Processing Text Files 278
Character Arrays 237 WE1 Looking for for Duplicates 281
Converting Between C and C++ Strings 237
8.6 Random Access and Binary Files 281
C++ Strings and the [] Operator 238
Random Access 281
ST4 Working with C Strings 238
Binary Files 282
7.4 Dynamic Memory Allocation 240 Processing Image Files 282
CE3 Dangling Pointers 242 C&S Databases and Privacy 286
CE4 Memory Leaks 243
7.5 Arrays and Vectors of Pointers 243 9 CLASSES 289
7.6 PROBLEM SOLVING Draw a Picture 246
HT1 Working with Pointers 248 9.1 Object-Oriented Programming 290
WE1 Producing a Mass Mailing 249 9.2 Implementing a Simple Class 292
C&S Embedded Systems 250 9.3 Specifying the Public Interface of
7.7 Structures 250 a Class 294
Structured Types 250 CE1 Forgetting a Semicolon 296
Structure Assignment and Comparison 251 9.4 Designing the Data Representation 297
Functions and Structures 252
9.5 Member Functions 299
Arrays of Structures 252
Structures with Array Members 253 Implementing Member Functions 299
Nested Structures 253 Implicit and Explicit Parameters 299
Calling a Member Function from a
7.8 Pointers and Structures 254 Member Function 301
Pointers to Structures 254 PT1 All Data Members Should Be Private; Most
Structures with Pointer Members 255 Member Functions Should Be Public 303
ST5 Smart Pointers 256 PT2 const Correctness 303
9.6 Constructors 304
8 STREAMS 259 CE2 Trying to Call a Constructor 306
ST1 Overloading 306
8.1 Reading and Writing Text Files 260 ST2 Initializer Lists 307
Opening a Stream 260 ST3 Universal and Uniform Initialization
Reading from a File 261 Syntax 308
Writing to a File 262
9.7 PROBLEM SOLVING Tracing Objects 308
A File Processing Example 262
HT1 Implementing a Class 310
8.2 Reading Text Input 265 WE1 Implementing a Bank Account Class 314
Reading Words 265 C&S Electronic Voting Machines 314
Reading Characters 266
9.8 PROBLEM SOLVING Discovering
Reading Lines 267
Classes 315
CE1 Mixing >> and getline Input 268
PT3 Make Parallel Vectors into Vectors of
ST1 Stream Failure Checking 269
Objects 317
8.3 Writing Text Output 270
9.9 Separate Compilation 318
ST2 Unicode, UTF-8, and C++ Strings 272
9.10 Pointers to Objects 322
8.4 Parsing and Formatting Strings 273
Dynamically Allocating Objects 322
The -> Operator 323
The this Pointer 324
Contents xxiii
9.11 PROBLEM SOLVING Patterns for Appendix A RESERVED WORD SUMMARY A-1
Object Data 324 Appendix B OPERATOR SUMMARY A-3
Keeping a Total 324 Appendix C CHARACTER CODES A-5
Counting Events 325
Appendix D C++ LIBRARY SUMMARY A-8
Collecting Values 326
Managing Properties of an Object 326 Appendix E C++ LANGUAGE CODING
Modeling Objects with Distinct States 327 GUIDELINES A-11
Describing the Position of an Object 328 Appendix F NUMBER SYSTEMS AND BIT AND SHIFT
C&S Open Source and Free Software 329 OPERATIONS (E-TEXT ONLY)
10 INHERITANCE 333 GLOSSARY G-1
INDEX I-1
10.1 Inheritance Hierarchies 334 CREDITS C-1
10.2 Implementing Derived Classes 338
CE1 Private Inheritance 341
CE2 Replicating Base-Class Members 341
PT1 Use a Single Class for Variation in Values,
ALPHABETICAL LIST OF SYNTAX BOXES
Inheritance for Variation in Behavior 342 Assignment 30
ST1 Calling the Base-Class Constructor 342 C++ Program 12
10.3 Overriding Member Functions 343 Class Definition 295
Comparisons 67
CE3 Forgetting the Base-Class Name 345
Constructor with Base-Class Initializer 342
10.4 Virtual Functions and Polymorphism 346 Defining an Array 181
The Slicing Problem 346 Defining a Structure 251
Pointers to Base and Derived Classes 347 Defining a Vector 213
Virtual Functions 348 Derived-Class Definition 340
Polymorphism 349 Dynamic Memory Allocation 240
PT2 Don’t Use Type Tags 352 for Statement 106
CE4 Slicing an Object 352 Function Definition 145
CE5 Failing to Override a Virtual Function 353 if Statement 61
ST2 Virtual Self-Calls 354 Input Statement 44
HT1 Developing an Inheritance Hierarchy 354 Member Function Definition 301
WE1 Implementing an Employee Hierarchy for Output Statement 13
Payroll Processing 359
Pointer Syntax 226
C&S Who Controls the Internet? 360
Two-Dimensional Array Definition 207
Variable Definition 27
while Statement 97
Working with File Streams 262
Another Random Scribd Document
with Unrelated Content
B.C.).But the philo-Laconian Xenophon is still more emphatic in his
condemnation of Sparta. Having described her triumphant and
seemingly unassailable position after the subjugation of Olynthus
and Phlius, he proceeds to say,[166]—“I could produce numerous
other incidents, both in and out of Greece, to prove that the gods
take careful note of impious men and of evil-doers; but the events
which I am now about to relate are quite sufficient. The
Lacedæmonians, who had sworn to leave each city autonomous,
having violated their oaths by seizing the citadel of Thebes, were
punished by the very men whom they had wronged,—though no one
on earth had ever before triumphed over them. And the Theban
faction who had introduced them into the citadel, with the deliberate
purpose that their city should be enslaved to Sparta in order that
they might rule despotically themselves,—were put down by no
more than seven assailants, among the exiles whom they had
banished.”
What must have been the hatred, and sense of abused
ascendency, entertained towards Sparta by neutral or unfriendly
Greeks, when Xenophon, alike conspicuous for his partiality to her
and for his dislike of Thebes, could employ these decisive words in
ushering in the coming phase of Spartan humiliation, representing it
as a well-merited judgment from the gods? The sentence which I
have just translated marks, in the commonplace manner of the
Xenophontic Hellenica, the same moment of pointed contrast and
transition,—past glory suddenly and unexpectedly darkened by
supervening misfortune,—which is foreshadowed in the narrative of
Thucydides by the dialogue between the Athenian envoys and the
Melian[167] council; or in the Œdipus and Antigonê of Sophokles,[168]
by the warnings of the prophet Teiresias.
The government of Thebes had now been for three years (since
the blow struck by Phœbidas) in the hands of Leontiades and his
oligarchical partisans, upheld by the Spartan garrison in the
Kadmeia. Respecting the details of its proceedings we have scarce
any information. We can only (as above remarked) judge of it by the
analogy of the Thirty tyrants at Athens, and of the Lysandrian
Dekarchies, to which it was exactly similar in origin, position, and
interests. That the general spirit of it must have been cruel,
oppressive, and rapacious,—we cannot doubt; though in what
degree we have no means of knowing. The appetites of uncontrolled
rulers, as well as those of a large foreign garrison, would ensure
such a result; besides which, those rulers must have been in
constant fear of risings or conspiracies amidst a body of high-spirited
citizens who saw their city degraded, from being the chief of the
Bœotian federation, into nothing better than a captive dependency
of Sparta. Such fear was aggravated by the vicinity of a numerous
body of Theban exiles, belonging to the opposite or anti-Spartan
party; three or four hundred of whom had fled to Athens at the first
seizure of their leader Ismenias, and had been doubtless joined
subsequently by others. So strongly did the Theban rulers
apprehend mischief from these exiles, that they hired assassins to
take them off by private murder at Athens; and actually succeeded
in thus killing Androkleidas, chief of the band and chief successor of
the deceased Ismenias,—though they missed their blows at the rest.
[169] And we may be sure that they made the prison in Thebes
subservient to multiplied enormities and executions, when we read
not only that one hundred and fifty prisoners were found in it when
the government was put down,[170] but also that in the fervor of that
revolutionary movement, the slain gaoler was an object of such
fierce antipathy, that his corpse was trodden and spit upon by a
crowd of Theban women.[171] In Thebes, as in other Grecian cities,
the women not only took no part in political disputes, but rarely even
showed themselves in public;[172] so that this furious demonstration
of vindictive sentiment must have been generated by the loss or
maltreatment of sons, husbands, and brothers.
The Theban exiles found at Athens not only secure shelter, but
genuine sympathy with their complaints against Lacedæmonian
injustice. The generous countenance which had been shown by the
Thebans, twenty-four years before, to Thrasybulus and the other
Athenian refugees, during the omnipotence of the Thirty, was now
gratefully requited under this reversal of fortune to both cities;[173]
and requited too in defiance of the menaces of Sparta, who
demanded that the exiles should be expelled,—as she had in the
earlier occasion demanded that the Athenian refugees should be
dismissed from Thebes. To protect these Theban exiles, however,
was all that Athens could do. Their restoration was a task beyond
her power,—and seemingly yet more beyond their own. For the
existing government of Thebes was firmly seated, and had the
citizens completely under control. Administered by a small faction,
Archias, Philippus, Hypatês, and Leontiades (among whom the first
two were at this moment polemarchs, though the last was the most
energetic and resolute)—it was at the same time sustained by the
large garrison of fifteen hundred Lacedæmonians and allies,[174]
under Lysanoridas and two other harmosts, in the Kadmeia,—as well
as by the Lacedæmonian posts in the other Bœotian cities around,—
Orchomenus, Thespiæ, Platæa, Tanagra, etc. Though the general
body of Theban sentiment in the city was decidedly adverse to the
government, and though the young men while exercising in the
palæstra (gymnastic exercises being more strenuously prosecuted at
Thebes than anywhere else except at Sparta) kept up by private
communication the ardor of an earnest, but compressed, patriotism,
—yet all manifestation or assemblage was forcibly kept down, and
the commanding posts of the lower town, as well as the citadel,
were held in vigilant occupation by the ruling minority.[175]
For a certain time the Theban exiles at Athens waited in hopes of
some rising at home, or some positive aid from the Athenians. At
length, in the third winter after their flight, they began to despair of
encouragement from either quarter, and resolved to take the
initiative upon themselves. Among them were numbered several
men of the richest and highest families at Thebes, proprietors of
chariots, jockeys, and training establishments, for contending at the
various festivals: Pelopidas, Mellon, Damokleidas, Theopompus,
Pherenikus, and others.[176]
Of these the most forward in originating aggressive measures,
though almost the youngest, was Pelopidas; whose daring and self-
devotion, in an enterprise which seemed utterly desperate, soon
communicated itself to a handful of his comrades. The exiles,
keeping up constant private correspondence with their friends in
Thebes, felt assured of the sympathy of the citizens generally, if they
could once strike a blow. Yet nothing less would be sufficient than
the destruction of the four rulers, Leontiades and his colleagues,—
nor would any one within the city devote himself to so hopeless a
danger. It was this conspiracy which Pelopidas, Mellon, and five or
ten other exiles (the entire band is differently numbered, by some as
seven, by others, twelve[177]) undertook to execute. Many of their
friends in Thebes came in as auxiliaries to them, who would not
have embarked in the design as primary actors. Of all auxiliaries, the
most effective and indispensable was Phyllidas, the secretary of the
polemarchs; next to him, Charon, an eminent and earnest patriot.
Phyllidas, having been despatched to Athens on official business,
entered into secret conference with the conspirators, concerted with
them the day for their coming to Thebes, and even engaged to
provide for them access to the persons of the polemarchs. Charon
not only promised them concealment in his house, from their first
coming within the gates until the moment of striking their blow
should have arrived,—but also entered his name to share in the
armed attack. Nevertheless, in spite of such partial encouragements,
the plan still appeared desperate to many who wished heartily for its
success. Epaminondas, for example,—who now for the first time
comes before us,—resident at Thebes, and not merely sympathizing
with the political views of Pelopidas, but also bound to him by
intimate friendship,—dissuaded others from the attempt, and
declined participating in it. He announced distinctly that he would
not become an accomplice in civil bloodshed. It appears that there
were men among the exiles whose violence made him fear that they
would not, like Pelopidas, draw the sword exclusively against
Leontiades and his colleagues, but would avail themselves of success
to perpetrate unmeasured violence against other political enemies.
[178]
The day for the enterprise was determined by Phyllidas the
secretary, who had prepared an evening banquet for Archias and
Philippus, in celebration of the period when they were going out of
office as polemarchs,—and who had promised on that occasion to
bring into their company some women remarkable for beauty, as
well as of the best families in Thebes.[179] In concert with the
general body of Theban exiles at Athens, who held themselves ready
on the borders of Attica, together with some Athenian sympathizers,
to march to Thebes the instant that they should receive intimation,—
and in concert also with two out of the ten Stratêgi of Athens, who
took on themselves privately to countenance the enterprise, without
any public vote,—Pelopidas and Mellon, and their five companions,
[180] crossed Kithæron from Athens to Thebes. It was wet weather,
about December B.C. 379; they were disguised as rustics or hunters,
with no other arms than a concealed dagger; and they got within
the gates of Thebes one by one at nightfall, just when the latest
farming men were coming home from their fields. All of them arrived
safe at the house of Charon, the appointed rendezvous.
It was, however, by mere accident that they had not been turned
back, and the whole scheme frustrated. For a Theban named
Hipposthenidas, friendly to the conspiracy, but faint-hearted, who
had been let into the secret against the will of Phyllidas,—became so
frightened as the moment of execution approached, that he took
upon himself, without the knowledge of the rest, to despatch
Chlidon, a faithful slave of Mellon, ordering him to go forth on
horseback from Thebes, to meet his master on the road, and to
desire that he and his comrades would go back to Attica, since
circumstances had happened to render the project for the moment
impracticable. Chlidon, going home to fetch his bridle, but not
finding it in its usual place, asked his wife where it was. The woman,
at first pretending to look for it, at last confessed that she had lent it
to a neighbor. Chlidon became so irritated with this delay, that he
got into a loud altercation with his wife, who on her part wished him
ill luck with his journey. He at last beat her, until neighbors ran in to
interpose. His departure was thus accidentally frustrated, so that the
intended message of countermand never reached the conspirators
on their way.[181]
In the house of Charon they remained concealed all the ensuing
day, on the evening of which the banquet of Archias and Philippus
was to take place. Phyllidas had laid his plan for introducing them at
that banquet, at the moment when the two polemarchs had become
full of wine, in female attire, as being the women whose visit was
expected. The hour had nearly arrived, and they were preparing to
play their parts, when an unexpected messenger knocked at the
door, summoning Charon instantly into the presence of the
polemarchs. All within were thunderstruck with the summons, which
seemed to imply that the plot had been divulged, perhaps by the
timid Hipposthenidas. It was agreed among them that Charon must
obey at once. Nevertheless, he himself, even in the perilous
uncertainty which beset him, was most of all apprehensive lest the
friends whom he had sheltered should suspect him of treachery
towards themselves and their cause. Before departing, therefore, he
sent for his only son, a youth of fifteen, and of conspicuous promise
in every way. This youth he placed in the hands of Pelopidas, as a
hostage for his own fidelity. But Pelopidas and the rest, vehemently
disclaiming all suspicion, entreated Charon to put his son away, out
of the reach of that danger in which all were now involved. Charon,
however, could not be prevailed on to comply, and left his son
among them to share the fate of the rest. He went into the presence
of Archias and Philippus; whom he found already half-intoxicated,
but informed, by intelligence from Athens, that some plot, they knew
not by whom, was afloat. They had sent for him to question him, as
a known friend of the exiles; but he had little difficulty, aided by the
collusion of Phyllidas, in blinding the vague suspicions of drunken
men, anxious only to resume their conviviality.[182] He was allowed
to retire and rejoin his friends. Nevertheless, soon after his
departure,—so many were the favorable chances which befel these
improvident men,—a fresh message was delivered to Archias the
polemarch, from his namesake Archias the Athenian Hierophant,
giving an exact account of the names and scheme of the
conspirators, which had become known to the philo-Laconian party
at Athens. The messenger who bore this despatch delivered it to
Archias with an intimation, that it related to very serious matters.
“Serious matters for to-morrow,” said the polemarch, as he put the
despatch, unopened and unread, under the pillow of the couch on
which he was reclining.[183]
Returning to their carousal, Archias and Philippus impatiently
called upon Phyllidas to introduce the women according to his
promise. Upon this the secretary retired, and brought the
conspirators, clothed in female attire, into an adjoining chamber;
then going back to the polemarchs, he informed them that the
women would not come in unless all the domestics were first
dismissed. An order was forthwith given that these latter should
depart, while Phyllidas took care that they should be well provided
with wine at the lodging of one among their number. The
polemarchs were thus left only with one or two friends at table, half-
intoxicated as well as themselves; among them Kabeirichus, the
archon of the year, who always throughout his term kept the
consecrated spear of office in actual possession, and had it at that
moment close to his person. Phyllidas now conducted the pretended
women into the banqueting-room; three of them attired as ladies of
distinction, the four others following as female attendants. Their long
veils, and ample folds of clothing, were quite sufficient as disguise,—
even had the guests at table been sober,—until they sat down by the
side of the polemarchs; and the instant of lifting their veils was the
signal for using their daggers. Archias and Philippus were slain at
once and with little resistance; but Kabeirichus with his spear tried to
defend himself, and thus perished with the others, though the
conspirators had not originally intended to take his life.[184]
Having been thus far successful, Phyllidas conducted three of the
conspirators,—Pelopidas, Kephisodôrus, and Damokleidas,—to the
house of Leontiades, into which he obtained admittance by
announcing himself as the bearer of an order from the polemarchs.
Leontiades was reclining after supper, with his wife sitting spinning
wool by his side, when they entered his chamber. Being a brave and
powerful man, he started up, seized his sword, and mortally
wounded Kephisodôrus in the throat; a desperate struggle then
ensued between him and Pelopidas in the narrow doorway, where
there was no room for a third to approach. At length, however,
Pelopidas overthrew and killed him, after which they retired,
enjoining the wife with threats to remain silent, and closing the door
after them with peremptory commands that it should not be again
opened. They then went to the house of Hypatês, whom they slew
while he attempted to escape over the roof.[185]
The four great rulers of the philo-Laconian party in Thebes
having been now put to death, Phyllidas proceeded with the
conspirators to the prison. Here the gaoler, a confidential agent in
the oppressions of the deceased governors, hesitated to admit him;
but was slain by a sudden thrust with his spear, so as to ensure free
admission to all. To liberate the prisoners, probably, for the most
part men of kindred politics with the conspirators,—to furnish them
with arms taken from the battle-spoils hanging up in the neighboring
porticos,—and to range them in battle order near the temple of
Amphion,—were the next proceedings; after which they began to
feel some assurance of safety and triumph.[186] Epaminondas and
Gorgidas, apprised of what had occurred, were the first who
appeared in arms with a few friends to sustain the cause; while
proclamation was everywhere made aloud, through heralds, that the
despots were slain,—that Thebes was free,—and that all Thebans
who valued freedom should muster in arms in the market-place.
There were at that moment in Thebes many trumpeters who had
come to contend for the prize at the approaching festival of the
Herakleia. Hipposthenidas engaged these men to blow their
trumpets in different parts of the city, and thus everywhere to excite
the citizens to arms.[187]
Although during the darkness surprise was the prevalent feeling,
and no one knew what to do,—yet so soon as day dawned, and the
truth became known, there was but one feeling of joy and patriotic
enthusiasm among the majority of the citizens.[188] Both horsemen
and hoplites hastened in arms to the agora. Here for the first time
since the seizure of the Kadmeia by Phœbidas, a formal assembly of
the Theban people was convened, before which Pelopidas and his
fellow-conspirators presented themselves. The priests of the city
crowned them with wreaths, and thanked them in the name of the
local gods; while the assembly hailed them with acclamations of
delight and gratitude, nominating with one voice Pelopidas, Mellon,
and Charon, as the first renewed Bœotarchs.[189] The revival of this
title, which had been dropped since the peace of Antalkidas, was in
itself an event of no mean significance; implying not merely that
Thebes had waked up again into freedom, but that the Bœotian
confederacy also had been, or would be, restored.
Messengers had been forthwith despatched by the conspirators
to Attica to communicate their success; upon which all the remaining
exiles, with the two Athenian generals privy to the plot, and a body
of Athenian volunteers, or corps francs, all of whom were ready on
the borders awaiting the summons,—flocked to Thebes to complete
the work. The Spartan generals, on their side also, sent to Platæa
and Thespiæ for aid. During the whole night, they had been
distracted and alarmed by the disturbance in the city; lights showing
themselves here and there, with trumpets sounding and shouts for
the recent success.[190] Apprised speedily of the slaughter of the
polemarchs, from whom they had been accustomed to receive
orders, they knew not whom to trust or to consult, while they were
doubtless beset by affrighted fugitives of the now defeated party,
who would hurry up the Kadmeia for safety. They reckoned at first
on a diversion in their favor from the forces at Platæa and Thespiæ.
But these forces were not permitted even to approach the city gate;
being vigorously charged, as soon as they came in sight, by the
newly-mustered Theban cavalry, and forced to retreat with loss. The
Lacedæmonians in the citadel were thus not only left without
support, but saw their enemies in the city reinforced by the other
exiles, and by the auxiliary volunteers.[191]
Meanwhile, Pelopidas and the other new Bœotarchs found
themselves at the head of a body of armed citizens, full of devoted
patriotism and unanimous in hailing the recent revolution. They
availed themselves of this first burst of fervor to prepare for
storming the Kadmeia without delay, knowing the importance of
forestalling all aid from Sparta. And the citizens were already rushing
up to the assault,—proclamation being made of large rewards to
those who should first force their way in,—when the Lacedæmonian
commander sent proposals for a capitulation.[192] Undisturbed
egress from Thebes, with the honors of war, being readily
guaranteed to him by oath, the Kadmeia was then surrendered. As
the Spartans were marching out of the gates, many Thebans of the
defeated party came forth also. But against these latter the
exasperation of the victors was so ungovernable, that several of the
most odious were seized as they passed, and put to death; in some
cases, even their children along with them. And more of them would
have been thus despatched, had not the Athenian auxiliaries, with
generous anxiety, exerted every effort to get them out of sight and
put them into safety.[193] We are not told,—nor is it certain,—that
these Thebans were protected under the capitulation. Even had they
been so, however, the wrathful impulse might still have prevailed
against them. Of the three harmosts who thus evacuated the
Kadmeia without a blow, two were put to death, the third was
heavily fined and banished, by the authorities at Sparta.[194] We do
not know what the fortifications of the Kadmeia were, nor how far it
was provisioned. But we can hardly wonder that these officers were
considered to have dishonored the Lacedæmonian arms, by making
no attempt to defend it; when we recollect that hardly more than
four or five days would be required to procure adequate relief from
home,—and that forty-three years afterwards, the Macedonian
garrison in the same place maintained itself against the Thebans in
the city for more than fourteen days, until the return of Alexander
from Illyria.[195] The first messenger who brought news to Sparta of
the conspiracy and revolution at Thebes, appears to have
communicated at the same time that the garrison had evacuated the
Kadmeia and was in full retreat, with a train of Theban exiles from
the defeated party.[196]
This revolution at Thebes came like an electric shock upon the
Grecian world. With a modern reader, the assassination of the four
leaders, in their houses and at the banquet, raises a sentiment of
repugnance which withdraws his attention from the other features of
this memorable deed. Now an ancient Greek not only had no such
repugnance, but sympathized with the complete revenge for the
seizure of the Kadmeia and the death of Ismenias; while he admired,
besides, the extraordinary personal daring of Pelopidas and Mellon,
—the skilful forecast of the plot,—and the sudden overthrow, by a
force so contemptibly small, of a government which the day before
seemed unassailable.[197] It deserves note that we here see the
richest men in Thebes undertaking a risk, single-handed and with
their own persons, which must have appeared on a reasonable
estimate little less than desperate. From the Homeric Odysseus and
Achilles down to the end of free Hellenism, the rich Greek strips in
the Palæstra,[198] and exposes his person in the ranks as a soldier
like the poorest citizens; being generally superior to them in strength
and bodily efficiency.
As the revolution in Thebes acted forcibly on the Grecian mind
from the manner in which it was accomplished, so by its positive
effects it altered forthwith the balance of power in Greece. The
empire of Sparta, far from being undisputed and nearly universal
over Greece, is from henceforward only maintained by more or less
effort, until at length it is completely overthrown.[199]
The exiles from Thebes, arriving at Sparta, inflamed both the
ephors, and the miso-Theban Agesilaus, to the highest pitch. Though
it was then the depth of winter,[200] an expedition was decreed
forthwith against Thebes, and the allied contingents were
summoned. Agesilaus declined to take the command of it, on the
ground that he was above sixty years of age, and therefore no
longer liable to compulsory foreign service. But this (says
Xenophon[201]) was not his real reason. He was afraid that his
enemies at Sparta would say,—“Here is Agesilaus again putting us to
expense, in order that he may uphold despots in other cities,”—as he
had just done, and had been reproached with doing, at Phlius; a
second proof that the reproaches against Sparta (which I have cited
a few pages above from Lysias and Isokrates) of allying herself with
Greek despots as well as with foreigners to put down Grecian
freedom, found an echo even in Sparta herself. Accordingly
Kleombrotus, the other king of Sparta, took the command. He had
recently succeeded his brother Agesipolis, and had never
commanded before.
Kleombrotus conducted his army along the Isthmus of Corinth
through Megara to Platæa, cutting to pieces an outpost of Thebans,
composed chiefly of the prisoners set free by the recent revolution,
who had been placed for the defence of the intervening mountain-
pass. From Platæa he went forward to Thespiæ, and from thence to
Kynoskephalæ in the Theban territory, where he lay encamped for
sixteen days; after which he retreated to Thespiæ. It appears that
he did nothing, and that his inaction was the subject of much
wonder in his army, who are said to have even doubted whether he
was really and earnestly hostile to Thebes. Perhaps the exiles, with
customary exaggeration, may have led him to hope that they could
provoke a rising in Thebes, if he would only come near. At any rate
the bad weather must have been a serious impediment to action;
since in his march back to Peloponnesus through Kreusis and
Ægosthenæ the wind blew a hurricane, so that his soldiers could not
proceed without leaving their shields and coming back afterwards to
fetch them. Kleombrotus did not quit Bœotia, however, without
leaving Sphodrias as harmost at Thespiæ, with one third of the
entire army, and with a considerable sum of money to employ in
hiring mercenaries and acting vigorously against the Thebans.[202]
The army of Kleombrotus, in its march from Megara to Platæa,
had passed by the skirts of Attica; causing so much alarm to the
Athenians, that they placed Chabrias with a body of peltasts, to
guard their frontier and the neighboring road through Eleutheræ into
Bœotia. This was the first time that a Lacedæmonian army had
touched Attica (now no longer guarded by the lines of Corinth, as in
the war between 394 and 388 B.C.) since the retirement of king
Pausanias in 404 B.C.; furnishing a proof of the exposure of the
country, such as to revive in the Athenian mind all the terrible
recollections of Dekeleia and the Peloponnesian war. It was during
the first prevalence of this alarm,—and seemingly while Kleombrotus
was still with his army at Thespiæ or Kynoskephalæ, close on the
Athenian frontier,—that three Lacedæmonian envoys, Etymoklês and
two others, arrived at Athens to demand satisfaction for the part
taken by the two Athenian generals and the Athenian volunteers, in
concerting and aiding the enterprise of Pelopidas and his comrades.
So overpowering was the anxiety in the public mind to avoid giving
offence to Sparta, that these two generals were both of them
accused before the dikastery. The first of them was condemned and
executed; the second, profiting by this warning (since, pursuant to
the psephism of Kannônus,[203] the two would be put on trial
separately), escaped, and a sentence of banishment was passed
against him.[204] These two generals had been unquestionably guilty
of a grave abuse of their official functions. They had brought the
state into public hazard, not merely without consulting the senate or
assembly, but even without taking the sense of their own board of
Ten. Nevertheless the severity of the sentence pronounced indicates
the alarm, as well as the displeasure, of the general body of
Athenians; while it served as a disclaimer in fact, if not in form, of all
political connection with Thebes.[205]
Even before the Lacedæmonian envoys had quitted Athens,
however, an incident, alike sudden and memorable, completely
altered the Athenian temper. The Lacedæmonian harmost Sphodrias
(whom Kleombrotus had left at Thespiæ to prosecute the war
against Thebes), being informed that Peiræus on its land side was
without gates or night watch,—since there was no suspicion of
attack,—conceived the idea of surprising it by a night-march from
Thespiæ, and thus of mastering at one stroke the commerce, the
wealth, and the naval resources of Athens. Putting his troops under
march one evening after an early supper, he calculated on reaching
the Peiræus the next morning before daylight. But his reckoning
proved erroneous. Morning overtook him when he had advanced no
farther than the Thriasian plain near Eleusis; from whence, as it was
useless to proceed farther, he turned back and retreated to Thespiæ;
not, however, without committing various acts of plunder against the
neighboring Athenian residents.
This plan against Peiræus appears to have been not ill conceived.
Had Sphodrias been a man competent to organize and execute
movements as rapid as those of Brasidas, there is no reason why it
might not have succeeded; in which case the whole face of the war
would have been changed, since the Lacedæmonians, if once
masters of Peiræus, both could and would have maintained the
place. But it was one of those injustices, which no one ever
commends until it has been successfully consummated,—“consilium
quod non potest laudari nisi peractum.[206]” As it failed, it has been
considered, by critics as well as by contemporaries, not merely as a
crime but as a fault, and its author Sphodrias as a brave man, but
singularly weak and hot-headed.[207] Without admitting the full
extent of this censure, we may see that his present aggression grew
out of an untoward emulation of the glory which Phœbidas, in spite
of the simulated or transient displeasure of his countrymen, had
acquired by seizing the Kadmeia. That Sphodrias received private
instructions from Kleombrotus (as Diodorus states) is not sufficiently
proved; while the suspicion, intimated by Xenophon as being abroad,
that he was wrought upon by secret emissaries and bribes from his
enemies the Thebans, for the purpose of plunging Athens into war
with Sparta, is altogether improbable;[208] and seems merely an
hypothesis suggested by the consequences of the act,—which were
such, that if his enemies had bribed him, he could not have served
them better.
The presence of Sphodrias and his army in the Thriasian plain
was communicated shortly after daybreak at Athens, where it
excited no less terror than surprise. Every man instantly put himself
under arms for defence; but news soon arrived that the invader had
retired. When thus reassured, the Athenians passed from fear to
indignation. The Lacedæmonian envoys, who were lodging at the
house of Kallias the proxenus of Sparta, were immediately put under
arrest and interrogated. But all three affirmed that they were not
less astonished, and not less exasperated, by the march of
Sphodrias, than the Athenians themselves; adding, by way of
confirmation, that had they been really privy to any design of seizing
the Peiræus, they would have taken care not to let themselves be
found in the city, and in their ordinary lodging at the house of the
proxenus, where of course their persons would be at once seized.
They concluded by assuring the Athenians, that Sphodrias would not
only be indignantly disavowed, but punished capitally, at Sparta. And
their reply was deemed so satisfactory, that they were allowed to
depart; while an Athenian embassy was sent to Sparta, to demand
the punishment of the offending general.[209]
The Ephors immediately summoned Sphodrias home to Sparta,
to take his trial on a capital charge. So much did he himself despair
of his case, that he durst not make his appearance; while the
general impression was, both at Sparta and elsewhere, that he
would certainly be condemned. Nevertheless, though thus absent
and undefended, he was acquitted, purely through private favor and
esteem for his general character. He was of the party of
Kleombrotus, so that all the friends of that prince espoused his
cause, as a matter of course. But as he was of the party opposed to
Agesilaus, his friends dreaded that the latter would declare against
him, and bring about his condemnation. Nothing saved Sphodrias
except the peculiar intimacy between his son Kleonymus and
Archidamus son of Agesilaus. The mournful importunity of
Archidamus induced Agesilaus, when this important cause was
brought before the Senate of Sparta, to put aside his judicial
conviction, and give his vote in the following manner: “To be sure,
Sphodrias is guilty; upon that there cannot be two opinions.
Nevertheless, we cannot put to death a man like him, who, as boy,
youth, and man, has stood unblemished in all Spartan honor. Sparta
cannot part with soldiers like Sphodrias.[210]” The friends of
Agesilaus, following this opinion and coinciding with those of
Kleombrotus, ensured a favorable verdict. And it is remarkable, that
Etymoklês himself, who as envoy at Athens had announced as a
certainty that Sphodrias would be put to death,—as senator and
friend of Agesilaus voted for his acquittal.[211]
This remarkable incident (which comes to us from a witness not
merely philo-Laconian, but also personally intimate with Agesilaus)
shows how powerfully the course of justice at Sparta was overruled
by private sympathy and interests,—especially, those of the two
kings. It especially illustrates what has been stated in a former
chapter respecting the oppressions exercised by the Spartan
harmosts and the dekadarchies, for which no redress was attainable
at Sparta. Here was a case where not only the guilt of Sphodrias
stood confessed, but in which also his acquittal was sure to be
followed by a war with Athens. If, under such circumstances, the
Athenian demand for redress was overruled by the favor of the two
kings, what chance was there of any justice to the complaint of a
dependent city, or an injured individual, against the harmost? The
contrast between Spartan and Athenian proceeding is also
instructive. Only a few days before, the Athenians condemned, at
the instance of Sparta, their two generals who had without authority
lent aid to the Theban exiles. In so doing, the Athenian dikastery
enforced the law against clear official misconduct,—and that, too, in
a case where their sympathies went along with the act, though their
fear of a war with Sparta was stronger. But the most important
circumstance to note is, that at Athens there is neither private
influence, nor kingly influence, capable of overruling the sincere
judicial conscience of a numerous and independent dikastery.
The result of the acquittal of Sphodrias must have been well
known beforehand to all parties at Sparta. Even by the general voice
of Greece, the sentence was denounced as iniquitous.[212] But the
Athenians, who had so recently given strenuous effect to the
remonstrances of Sparta against their own generals, were stung by
it to the quick; and only the more stung, in consequence of the
extraordinary compliments to Sphodrias on which the acquittal was
made to turn. They immediately contracted hearty alliance with
Thebes, and made vigorous preparations for war against Sparta both
by land and sea. After completing the fortifications of Peiræus, so as
to place it beyond the reach of any future attempt, they applied
themselves to the building of new ships of war, and to the extension
of their naval ascendency, at the expense of Sparta.[213]
From this moment, a new combination began in Grecian politics.
The Athenians thought the moment favorable to attempt the
construction of a new confederacy, analogous to the Confederacy of
Delos, formed a century before; the basis on which had been reared
the formidable Athenian empire, lost at the close of the
Peloponnesian war. Towards such construction there was so far a
tendency, that Athens had already a small body of maritime allies;
while rhetors like Isokrates (in his Panegyrical Discourse, published
two years before) had been familiarizing the public mind with larger
ideas. But the enterprise was now pressed with the determination
and vehemence of men smarting under recent insult. The Athenians
had good ground to build upon; since, while the discontent against
the ascendency of Sparta was widely spread, the late revolution in
Thebes had done much to lessen that sentiment of fear upon which
such ascendency chiefly rested. To Thebes, the junction with Athens
was preëminently welcome, and her leaders gladly enrolled their city
as a constituent member of the new confederacy.[214] They
cheerfully acknowledged the presidency of Athens,—reserving,
however, tacitly or expressly, their own rights as presidents of the
Bœotian federation, as soon as that could be reconstituted; which
reconstitution was at this moment desirable even for Athens, seeing
that the Bœotian towns were now dependent allies of Sparta under
harmosts and oligarchies.
The Athenians next sent envoys round to the principal islands
and maritime cities in the Ægean, inviting all of them to an alliance
on equal and honorable terms. The principles were in the main the
same as those upon which the confederacy of Delos had been
formed against the Persians, almost a century before. It was
proposed that a congress of deputies should meet at Athens, one
from each city, small as well as great, each with one vote; that
Athens should be president, yet each individual city autonomous;
that a common fund should be raised, with a common naval force,
through assessment imposed by this congress upon each, and
applied as the same authority might prescribe; the general purpose
being defined to be, maintenance of freedom and security from
foreign aggression, to each confederate, by the common force of all.
Care was taken to banish as much as possible those associations of
tribute and subjection which rendered the recollection of the former
Athenian empire unpopular.[215] And as there were many Athenian
citizens, who, during those times of supremacy, had been planted
out as kleruchs or out-settlers in various dependencies, but had been
deprived of their properties at the close of the war,—it was thought
necessary to pass a formal decree,[216] renouncing and barring all
revival of these suspended rights. It was farther decreed that
henceforward no Athenian should on any pretence hold property,
either in house or land, in the territory of any one of the
confederates; neither by purchase, nor as security for money lent,
nor by any other mode of acquisition. Any Athenian infringing this
law, was rendered liable to be informed against before the synod;
who, on proof of the fact, were to deprive him of the property,—half
of it going to the informer, half to the general purposes of the
confederacy.
Such were the liberal principles of confederacy now proposed by
Athens,—who, as a candidate for power, was straightforward and
just, like the Herodotean Deiokês,[217]—and formally ratified, as well
by the Athenians as by the general voice of the confederate deputies
assembled within their walls. The formal decree and compact of
alliance was inscribed on a stone column and placed by the side of
the statue of Zeus Eleutherius or the Liberator; a symbol, of
enfranchisement from Sparta accomplished, as well as of freedom to
be maintained against Persia and other enemies.[218] Periodical
meetings of the confederate deputies were provided to be held (how
often, we do not know) at Athens, and the synod was recognized as
competent judge of all persons, even Athenian citizens, charged with
treason against the confederacy. To give fuller security to the
confederates generally, it was provided in the original compact, that
if any Athenian citizen should either speak, or put any question to
the vote, in the Athenian assembly, contrary to the tenor of that
document,—he should be tried before the synod for treason; and
that, if found guilty, he might be condemned by them to the severest
punishment.
Three Athenian leaders stood prominent as commissioners in the
first organization of the confederacy, and in the dealings with those
numerous cities whose junction was to be won by amicable
inducement,—Chabrias, Timotheus son of Konon, and Kallistratus.
[219]
The first of the three is already known to the reader. He and
Iphikrates were the most distinguished warriors whom Athens
numbered among her citizens. But not having been engaged in any
war, since the peace of Antalkidas in 387 B.C., she had had no need
of their services; hence both of them had been absent from the city
during much of the last nine years, and Iphikrates seems still to
have been absent. At the time when that peace was concluded,
Iphikrates was serving in the Hellespont and Thrace, Chabrias with
Evagoras in Cyprus; each having been sent thither by Athens at the
head of a body of mercenary peltasts. Instead of dismissing their
troops, and returning to Athens as peaceful citizens, it was not less
agreeable to the military tastes of these generals, than conducive to
their importance and their profit, to keep together their bands, and
to take foreign service. Accordingly, Chabrias had continued in
service first in Cyprus, next with the native Egyptian king Akoris. The
Persians, against whom he served, found his hostility so
inconvenient, that Pharnabazus demanded of the Athenians to recall
him, on pain of the Great King’s displeasure; and requested at the
same time that Iphikrates might be sent to aid the Persian satraps in
organizing a great expedition against Egypt. The Athenians, to
whom the goodwill of Persia was now of peculiar importance,
complied on both points; recalled Chabrias, who thus became
disposable for the Athenian service,[220] and despatched Iphikrates
to take command along with the Persians.
Iphikrates, since the peace of Antalkidas, had employed his
peltasts in the service of the kings of Thrace: first of Seuthes, near
the shores of the Propontis, whom he aided in the recovery of
certain lost dominions,—next of Kotys, whose favor he acquired, and
whose daughter he presently married.[221] Not only did he enjoy
great scope for warlike operations and plunder, among the “butter-
eating Thracians,”[222]—but he also acquired, as dowry, a large stock
of such produce as Thracian princes had at their disposal, together
with a boon even more important,—a seaport village not far from
the mouth of the Hebrus, called Drys, where he established a
fortified post, and got together a Grecian colony dependent on
himself.[223] Miltiades, Alkibiades, and other eminent Athenians had
done the same thing before him; though Xenophon had refused a
similar proposition when made to him by the earlier Seuthes.[224]
Iphikrates thus became a great man in Thrace, yet by no means
abandoning his connection with Athens, but making his position in
each subservient to his importance in the other. While he was in a
situation to favor the projects of Athenian citizens for mercantile and
territorial acquisitions in the Chersonese and other parts of Thrace,—
he could also lend the aid of Athenian naval and military art, not
merely to princes in Thrace, but to others even beyond those limits,
—since we learn that Amyntas king of Macedonia became so
attached or indebted to him as to adopt him for his son.[225] When
sent by the Athenians to Persia, at the request of Pharnabazus
(about 378 B.C. apparently), Iphikrates had fair ground for
anticipating that a career yet more lucrative was opening before him.
[226]
Iphikrates being thus abroad, the Athenians joined with Chabrias,
in the mission and measures for organizing their new confederacy,
two other colleagues, of whom we now hear for the first time—
Timotheus son of Konon, and Kallistratus the most celebrated orator
of his time.[227] The abilities of Kallistratus were not military at all;
while Timotheus and Chabrias were men of distinguished military
merit. But in acquiring new allies and attracting deputies to her
proposed congress, Athens stood in need of persuasive appeal,
conciliatory dealing, and substantial fairness in all her propositions,
not less than of generalship. We are told that Timotheus, doubtless
as son of the liberator Konon, from the recollections of the battle of
Knidus—was especially successful in procuring new adhesions; and
probably Kallistratus,[228] going round with him to the different
islands, contributed by his eloquence not a little to the same result.
On their invitation, many cities entered as confederates.[229] At this
time (as in the earlier confederacy of Delos) all who joined must
have been unconstrained members. And we may understand the
motives of their junction, when we read the picture drawn by
Isokrates (in 380 B.C.) of the tyranny of the Persians on the Asiatic
mainland, threatening, to absorb the neighboring islands. Not only
was there now a new basis of imposing force, presented by Athens
and Thebes in union—but there was also a wide-spread hatred of
imperial Sparta, aggravated since her perversion of the pretended
boon of autonomy, promised by the peace of Antalkidas; and the
conjunction of these sentiments caused the Athenian mission of
invitation to be extremely successful. All the cities in Eubœa (except
Histiæa, at the north of the island)—as well as Chios, Mitylênê,
Byzantium, and Rhodes—the three former of whom had continued
favorably inclined to Athens ever since the peace of Antalkidas,[230]
—all entered into the confederacy. An Athenian fleet under Chabrias,
sailing among the Cyclades and the other islands of the Ægean,
aided in the expulsion of the Lacedæmonian harmosts,[231] together
with their devoted local oligarchies, wherever they still subsisted;
and all the cities thus liberated became equal members of the newly-
constituted congress at Athens. After a certain interval, there came
to be not less than seventy cities, many of them separately powerful,
which sent deputies to it;[232] an aggregate sufficient to intimidate
Sparta, and even to flatter Athens with the hope of restoration to
something like her former lustre.
The first votes both of Athens herself, and of the newly-
assembled congress, threatened war upon the largest scale. A
resolution was passed to equip twenty thousand hoplites, five
hundred horsemen, and two hundred triremes.[233] Probably the
insular and Ionic deputies promised each a certain contribution of
money, but nothing beyond. We do not, however, know how much,
—nor how far the engagements, large or small, were realized,—nor
whether Athens was authorized to enforce execution against
defaulters,—or was in circumstances to act upon such authority, if
granted to her by the congress. It was in this way (as the reader will
recollect from my fifth volume) that Athens had first rendered herself
unpopular in the confederacy of Delos,—by enforcing the resolutions
of the confederate synod against evasive or seceding members. It
was in this way that what was at first a voluntary association had
ultimately slid into an empire by constraint. Under the new
circumstances of 378 B.C., we may presume that the confederates,
though ardent and full of promises on first assembling at Athens,
were even at the outset not exact, and became afterwards still less
exact, in performance; yet that Athens was forced to be reserved in
claiming, or in exercising, the right of enforcement. To obtain a vote
of contribution by the majority of deputies present, was only the first
step in the process; to obtain punctual payment, when the Athenian
fleet was sent round for the purpose of collecting,—yet without
incurring dangerous unpopularity,—was the second step, but by far
the most doubtful and difficult.
It must, however, be borne in mind that at this moment, when
the confederacy was first formed, both Athens and the other cities
came together from a spontaneous impulse of hearty mutuality and
coöperation. A few years afterwards, we shall find this changed;
Athens selfish, and the confederates reluctant.[234] Inflamed, as well
by their position of renovated headship, as by fresh animosity
against Sparta, the Athenians made important efforts of their own,
both financial and military. Equipping a fleet, which for the time was
superior in the Ægean, they ravaged the hostile territory of Histiæa
in Eubœa, and annexed to their confederacy the islands of
Peparêthus and Skiathus. They imposed upon themselves also a
direct property-tax; to what amount, however, we do not know.
It was on the occasion of this tax that they introduced a great
change in the financial arrangements and constitution of the city; a
change conferring note upon the archonship of Nausinikus, (B.C. 378-
377). The great body of substantial Athenian citizens as well as
metics were now classified anew for purposes of taxation. It will be
remembered that even from the time of Solon[235] the citizens of
Athens had been distributed into four classes,—Pentakosiomedimni,
Hippeis, Zeugitæ, Thêtes,—distinguished from each other by the
amount of their respective properties. Of these Solonian classes, the
fourth, or poorest, paid no direct taxes; while the three former were
taxed according to assessments representing a certain proportion of
their actual property. The taxable property of the richest (or
Pentakosiomedimni, including all at or above the minimum income of
five hundred medimni of corn per annum) was entered in the tax-
book at a sum equal to twelve times their income; that of the
Hippeis (comprising all who possessed between three hundred and
five hundred medimni of annual income) at ten times their income;
that of the Zeugitæ (or possessors of an annual income between
two hundred and three hundred medimni) at five times their income.
A medimnus of corn was counted as equivalent to a drachma; which
permitted the application of this same class-system to movable
property as well as to land. So that, when an actual property-tax (or
eisphora) was imposed, it operated as an equal or proportional tax,
so far as regarded all the members of the same class; but as a
graduated or progressive tax, upon all the members of the richer
class as compared with those of the poorer.
The three Solonian property-classes above named appear to have
lasted, though probably not without modifications, down to the close
of the Peloponnesian war; and to have been in great part preserved,
after the renovation of the democracy in B.C. 403, during the
archonship of Eukleides.[236] Though eligibility to the great offices of
state had before that time ceased to be dependent on pecuniary
qualification, it was still necessary to possess some means of
distinguishing the wealthier citizens, not merely in case of direct
taxation being imposed, but also because the liability to serve in
liturgies or burdensome offices was consequent on a man’s
enrolment as possessor of more than a given minimum of property.
It seems, therefore, that the Solonian census, in its main principles
of classification and graduation, was retained. Each man’s property
being valued, he was ranged in one of three or more classes
according to its amount. For each of the classes, a fixed proportion
of taxable capital to each man’s property was assumed, and each
was entered in the schedule, not for his whole property, but for the
sum of taxable capital corresponding to his property, according to
the proportion assumed. In the first or richest class, the taxable
capital bore a greater ratio to the actual property than in the less
rich; in the second, a greater ratio than in the third. The sum of all
these items of taxable capital, in all the different classes, set
opposite to each man’s name in the schedule, constituted the
aggregate census of Attica; upon which all direct property-tax was
imposed, in equal proportion upon every man.
Respecting the previous modifications in the register of taxable
property, or the particulars of its distribution into classes, which had
been introduced in 403 B.C. at the archonship of Eukleides, we have
no information. Nor can we make out how large or how numerous
were the assessments of direct property-tax, imposed at Athens
between that archonship and the archonship of Nausinikus in 378
B.C. But at this latter epoch the register was again considerably
modified, at the moment when Athens was bracing herself up for
increased exertions. A new valuation was made of the property of
every man possessing property to the amount of twenty-five minæ
(or twenty-five hundred drachmæ) and upwards. Proceeding upon
this valuation, every one was entered in the schedule for a sum of
taxable capital equal to a given fraction of what he possessed. But
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about testbank and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebooksecure.com