Absolute C++ 5th Edition Savitch Solutions Manual

xambreiony 41 views 56 slides Apr 18, 2025
Slide 1
Slide 1 of 56
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56

About This Presentation

Absolute C++ 5th Edition Savitch Solutions Manual
Absolute C++ 5th Edition Savitch Solutions Manual
Absolute C++ 5th Edition Savitch Solutions Manual


Slide Content

Absolute C++ 5th Edition Savitch Solutions
Manual install download
https://testbankfan.com/product/absolute-c-5th-edition-savitch-
solutions-manual/
Download more testbank from https://testbankfan.com

We believe these products will be a great fit for you. Click
the link to download now, or visit testbankfan.com
to discover even more!
Absolute C++ 5th Edition Savitch Test Bank
https://testbankfan.com/product/absolute-c-5th-edition-savitch-
test-bank/
Absolute C++ 6th Edition Savitch Solutions Manual
https://testbankfan.com/product/absolute-c-6th-edition-savitch-
solutions-manual/
Absolute C++ 6th Edition Savitch Test Bank
https://testbankfan.com/product/absolute-c-6th-edition-savitch-
test-bank/
Absolute Java 5th Edition Walter Savitch Solutions
Manual
https://testbankfan.com/product/absolute-java-5th-edition-walter-
savitch-solutions-manual/

Absolute Java 5th Edition Walter Savitch Test Bank
https://testbankfan.com/product/absolute-java-5th-edition-walter-
savitch-test-bank/
Absolute Java 6th Edition Savitch Test Bank
https://testbankfan.com/product/absolute-java-6th-edition-
savitch-test-bank/
Problem Solving with C++ 10th Edition Savitch Solutions
Manual
https://testbankfan.com/product/problem-solving-with-c-10th-
edition-savitch-solutions-manual/
Problem Solving with C++ 9th Edition Savitch Solutions
Manual
https://testbankfan.com/product/problem-solving-with-c-9th-
edition-savitch-solutions-manual/
Problem Solving with C++ 9th Edition Savitch Test Bank
https://testbankfan.com/product/problem-solving-with-c-9th-
edition-savitch-test-bank/

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

Chapter 7
Constructors and Other Tools

Key Terms
constructor
initialization section
default constructor
constant parameter
const with member functions
inline function
static variable
initializing static member variables
nested class
local class
vector
declaring a vector variable
template class
v[i]
push_back
size
size unsigned int
capacity


Brief Outline
7.1 Constructors
Constructor Definitions
Explicit Constructor Calls
Class Type Member Variables
7.2 More Tools
The const Parameter Modifier
Inline Functions
Static Members
Nested and Local Class Definitions
7.3 Vectors – A Preview of the Standard Template Library
Vector Basics
Efficiency Issues.

1. Introduction and Teaching Suggestions

Tools developed in this chapter are the notion of const member functions, inline functions, static
members, nested classes and composition. A const member function is a promise not to change
state of the calling object. A call to an inline function requests that the compiler put the body of
the function in the code stream instead of a function call. A static member of a class is

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

connected to the class rather than being connected to specific object. The chapter ends with a
brief introduction to the vector container and a preview of the STL.

Students should immediately see the comparison of vectors to arrays and note how it is generally
much easier to work with vectors. In particular, the ability to grow and shrink makes it a much
easier dynamic data structure while the use of generics allows vectors to store arbitrary data
types. If you have given assignments or examples with traditional arrays then it may be
instructive to re-do those same programs with vectors instead.

2. Key Points

Constructor Definitions. A constructor is a member function having the same name as the
class. The purpose of a class constructor is automatic allocation and initialization of resources
involved in the definition of class objects. Constructors are called automatically at definition of
class objects. Special declarator syntax for constructors uses the class name followed by a
parameter list but there is no return type.

Constructor initialization section. The implementation of the constructor can have an
initialization section:
A::A():a(0), b(1){ /* implementation */ }
The text calls the :a(0), b(1) the initialization section. In the literature, this sometimes
called a member initializer list. The purpose of a member initializer list is to initialize the class
data members. Only constructors may have member initializer lists. Much of the time you can
initialize the class members by assignment within the constructor block, but there are a few
situations where this is not possible. In these cases you must use an initialization section, and the
error messages are not particularly clear. Encourage your students to use initialization sections in
preference to assignment in the block of a constructor. Move initialization from the member
initializer list to the body of the constructor when there is a need to verify argument values.

Class Type Member Variables. A class may be used like any other type, including as a type of
a member of another class. This is one of places where you must use the initializer list to do
initialization.

The const Parameter Modifier. Reference parameters that are declared const provide
automatic error checking against changing the caller’s argument. All uses of the const modifier
make a promise to the compiler that you will not change something and a request for the
compiler to hold you to your promise. The text points out that the use of a call-by-value
parameter protects the caller’s argument against change. Call-by-value copies the caller’s
argument, hence for a large type can consume undesirable amounts of memory. Call-by-
reference, on the other hand, passes only the address of the caller’s argument, so consumes little
space. However, call-by-reference entails the danger of an undesired change in the caller’s
argument. A const call-by-reference parameter provides a space efficient, read-only parameter
passing mechanism.

A const call-by-value parameter mechanism, while legal, provides little more than an annoyance
to the programmer.

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


The const modifier appended to the declaration of a member function in a class definition is a
promise not to write code in the implementation that will change the state of the class. Note that
the const modifier on the function member is part of the signature of a class member function
and is required in both declaration and definition if it is used in either.

The const modifier applied to a return type is a promise not to do anything the returned object to
change it. If the returned type is a const reference, the programmer is promising not to use the
call as an l-value. If the returned type is a const class type, the programmer is promising not to
apply any non-const member function to the returned object.

Inline Functions. Placing the keyword inline before the declaration of a function is a hint to the
compiler to put body of the function in the code stream at the place of the call (with arguments
appropriately substituted for the parameters). The compiler may or may not do this, and some
compilers have strong restrictions on what function bodies will be placed inline.

Static Members. The keyword static is used in several contexts. C used the keyword static
with an otherwise global declaration to restrict visibility of the declaration from within other
files. This use is deprecated in the C++ Standard.. In Chapter 11, we will see that unnamed
namespaces replace this use of static.

In a function, a local variable that has been declared with the keyword static is allocated once
and initialized once, unlike other local variables that are allocated and initialized (on the system
stack) once per invocation. Any initialization is executed only once, at the time the execution
stream reaches the initialization. Subsequently, the initialization is skipped and the variable
retains its value from the previous invocation.

The third use of static is the one where a class member variable or function is declared with the
static keyword. The definition of a member as static parallels the use of static for function local
variables. There is only one member, associated with the class (not replicated for each object).

Nested and Local Classes. A class may be defined inside another class. Such a class is in the
scope of the outer class and is intended for local use. This can be useful with data structures
covered in Chapter 17.

Vectors. The STL vector container is a generalization of array. A vector is a container that is
able to grow (and shrink) during program execution. A container is an object that can contain
other objects. The STL vector container is implemented using a template class (Chapter 16). The
text’s approach is to define some vector objects and use them prior to dealing with templates and
the STL in detail (Chapter 19). Unlike arrays, vector objects can be assigned, and the behavior is
what you want. Similar to an array, you can declare a vector to have a 10 elements initialized
with the default constructor by writing
vector<baseType> v(10);
Like arrays, objects stored in a vector object can be accessed for use as an l-value or as an r-
value using indexing.
v[2] = 3;
x = v[0];

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

Unlike arrays, however, you cannot (legally) index into a vector, say v[i], to fetch a value or to
assign a value unless an element has already been inserted at every index position up to and
including index position i. The push_back(elem) function can be used to add an element to
the end of a vector.

Efficiency Issues for Vectors. Most implementations of vector have an array that holds its
elements. The array is divided into that used for elements that have been inserted, and the rest is
called reserve. There is a member function that can be used to adjust the reserve up or down.
Implementations vary with regard to whether the reserve member can decrease the capacity of a
vector below the current capacity.


3. Tips

Invoking constructors. You cannot call a constructor as if it were a member function, but
frequently it is useful to invoke a constructor explicitly. In fact this declaration of class A in
object u :
A u(3);
is short hand for
A u = A(3);
Here, we have explicitly invoked the class A constructor that can take an int argument. When we
need to build a class object for return from a function, we can explicitly invoke a constructor.
A f()
{
int i;
// compute a value for i
return A(i);
}

Always Include a Default Constructor. A default constructor will automatically be created for
you if you do not define one, but it will not do anything. However, if your class definition
includes one or more constructors of any kind, no constructor is generated automatically.

Static member variables must be initialized outside the class definition. Static variables may
be initialized only once, and they must be initialized outside the class definition.. The text points
out that the class author is expected to do the initializations, typically in the same file where the
class definition appears.
Example:
class A
{
public:
A();
. . .
private:
static int a;
int b;

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

};
int A::a = 0; // initialization

A static member is intended to reduce the need for global variables by providing alternatives that
are local to a class. A static member function or variable acts as a global for members of its class
without being available to, or clashing with, global variables or functions or names of members
of other classes.

A static member function is not supplied with the implicit “this” pointer that points to the
instance of a class. Consequently, a static member function can only use nested types,
enumerators, and static members directly. To access a non-static member of its class, a static
member function must use the . or the -> operator with some instance (presumably passed to
the static member function via a parameter).


4. Pitfalls

Attempting to invoke a constructor like a member function. We cannot call a constructor for
a class as if it were a member of the class.

Constructors with No Arguments. It is important not to use any parentheses when you declare
a class variable and want the constructor invoked with no arguments, e.g.
MyClass obj;
instead of
MyClass obj();
Otherwise, the compiler sees it as a prototype declaration of a function that has no parameters
and a return type of MyClass.

Inconsistent Use of const. If you use const for one parameter of a particular type, then you
should use it for every other parameter that has that type and is not changed by the function call.

Attempt to access non-static variables from static functions. Non-static class instance
variables are only created when an object has been created and is therefore out of the scope of a
static function. Static functions should only access static class variables. However, non-static
functions can access static class variables.

Declaring An Array of class objects Requires a Default Constructor. When an array of class
objects is defined, the default constructor is called for each element of the array, in increasing
index order. You cannot declare an array of class objects if the class does not provide a default
constructor.

There is no array bounds checking done by a vector. There is a member function,
at(index) that does do bounds checking. When you access or write an element outside the
index range 0 to (size-1), is undefined. Otherwise if you try to access v[i] where I is greater than
the vector’s size, you may or may not get an error message but the program will undoubtedly
misbehave.

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


5. Programming Projects Answers
1. Class Month
Notes:

Abstract data type for month.
Need:
Default constructor
constructor to set month using first 3 letters as 3 args
constructor to set month using int value : 1 for Jan etc

input function (from keyboard) that sets month from 1
st
3 letters of month name
input function (from keyboard) that sets month from int value : 1 for Jan etc
output function that outputs (to screen) month as 1
st
3 letters in the name of the month (C-
string?)
output function that outputs (to screen) month as number, 1 for Jan etc.
member function that returns the next month as a value of type Month.

.int monthNo; // 1 for January, 2 for February etc

Embed in a main function and test.

//file: ch7prb1.cpp
//Title: Month
//To create and test a month ADT

#include <iostream>
#include <cstdlib> // for exit()
#include <cctype> // for tolower()

using namespace std;

class Month
{
public:
//constructor to set month based on first 3 chars of the month name
Month(char c1, char c2, char c3); // done, debugged
//a constructor to set month base on month number, 1 = January etc.
Month( int monthNumber); // done, debugged
//a default constructor (what does it do? nothing)
Month(); // done, no debugging to do
//an input function to set the month based on the month number
void getMonthByNumber(istream&); // done, debugged
//input function to set the month based on a three character input
void getMonthByName(istream&); // done, debugged
//an output function that outputs the month as an integer,
void outputMonthNumber(ostream&); // done, debugged
//an output function that outputs the month as the letters.
void outputMonthName(ostream&); // done, debugged
//a function that returns the next month as a month object

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

Month nextMonth(); //
//NB: each input and output function have a single formal parameter
//for the stream

int monthNumber();

private:
int mnth;
};

//added
int Month::monthNumber()
{
return mnth;
}

Month Month::nextMonth()
{
int nextMonth = mnth + 1;
if (nextMonth == 13)
nextMonth = 1;
return Month(nextMonth);
}

Month::Month( int monthNumber)
{
mnth = monthNumber;
}

void Month::outputMonthNumber( ostream& out )
{
//cout << "The current month is "; // only for debugging
out << mnth;
}
// This implementation could profit greatly from use of an array!
void Month::outputMonthName(ostream& out)
{
// a switch is called for. We don't have one yet!
if (1 == mnth) out << "Jan";
else if (2 == mnth) out << "Feb";
else if (3 == mnth) out << "Mar";
else if (4 == mnth) out << "Apr";
else if (5 == mnth) out << "May";
else if (6 == mnth) out << "Jun ";
else if (7 == mnth) out << "Jul ";
else if (8 == mnth) out << "Aug";
else if (9 == mnth) out << "Sep";
else if (10 == mnth) out << "Oct";
else if (11 == mnth) out << "Nov";
else if (12 == mnth) out << "Dec";
}
void error(char c1, char c2, char c3)
{
cout << endl << c1 << c2 << c3 << " is not a month. Exiting \n";
exit(1);
}
void error(int n)

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

{
cout << endl << n << " is not a month number. Exiting" << endl;
exit(1);
}
void Month::getMonthByNumber(istream& in)
{
in >> mnth; // int Month::mnth;
}
// use of an array and linear search could help this implementation.
void Month::getMonthByName(istream& in)
{
// Calls error(...) which exits, if the month name is wrong.
// An enhancement would be to allow the user to fix this.
char c1, c2, c3;
in >> c1 >> c2 >> c3;
c1 = tolower(c1); //force to lower case so any case
c2 = tolower(c2); //the user enters is acceptable
c3 = tolower(c3);

if('j' == c1)
if('a' == c2)
mnth = 1; // jan
else
if ('u' == c2)
if('n' == c3)
mnth = 6; // jun
else if ('l' == c3)
mnth = 7; // jul
else error(c1, c2, c3); // ju, not n or
else error(c1, c2, c3); // j, not a or u
else
if('f' == c1)
if('e' == c2)
if('b' == c3)
mnth = 2; // feb
else error(c1, c2, c3); // fe, not b
else error(c1, c2, c3); // f, not e
else
if('m' == c1)
if('a' == c2)
if('y' == c3)
mnth = 5; // may
else
if('r' == c3)
mnth = 3; // mar
else error(c1, c2, c3); // ma not a, r
else error(c1,c2,c3); // m not a or r
else
if('a' == c1)
if('p' == c2)
if('r' == c3)
mnth = 4; // apr
else error(c1, c2, c3 ); // ap not r
else
if('u' == c2)
if('g' == c3)
mnth = 8; // aug

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

else error(c1,c2,c3); // au not g
else error(c1,c2,c3); // a not u or p
else
if('s' == c1)
if('e' == c2)
if('p' == c3)
mnth = 9; // sep
else error(c1, c2, c3); // se, not p
else error(c1, c2, c3); // s, not e
else
if('o' == c1)
if('c' == c2)
if('t' == c3)
mnth = 10; // oct
else error(c1, c2, c3); // oc, not t
else error(c1, c2, c3); // o, not c
else
if('n' == c1)
if('o' == c2)
if('v' == c3)
mnth = 11; // nov
else error(c1, c2, c3); // no, not v
else error(c1, c2, c3); // n, not o
else
if('d' == c1)
if('e' == c2)
if('c' == c3)
mnth = 12; // dec
else error(c1, c2, c3);// de, not c
else error(c1, c2, c3);// d, not e
else error(c1, c2, c3);//c1,not j,f,m,a,s,o,n,or d
}
Month::Month(char c1, char c2, char c3)
{
c1 = tolower(c1);
c2 = tolower(c2);
c3 = tolower(c3);
if('j' == c1)
if('a' == c2)
mnth=1; // jan
else if ('u' == c2)
if('n' == c3)
mnth = 6; // jun
else if('l' == c3)
mnth = 7; // jul
else error(c1, c2, c3); // ju, not n or
else error(c1, c2, c3); // j, not a or u
else if('f' == c1)
if('e' == c2)
if('b' == c3)
mnth = 2; // feb
else error(c1, c2, c3); // fe, not b
else error(c1, c2, c3); // f, not e
else
if('m' == c1)
if('a' == c2)
if('y' == c3)

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

mnth = 5; // may
else
if('r' == c3)
mnth = 3; // mar
else error(c1, c2, c3); // ma not a, r
else error(c1,c2,c3); // m not a or r
else
if('a' == c1)
if('p' == c2)
if('r' == c3)
mnth = 4; // apr
else error(c1, c2, c3 ); // ap not r
else
if('u' == c2)
if('g' == c3)
mnth = 8; // aug
else error(c1,c2,c3); // au not g
else error(c1,c2,c3); // a not u or p
else
if('s' == c1)
if('e' == c2)
if('p' == c3)
mnth = 9; // sep
else error(c1, c2, c3); // se, not p
else error(c1, c2, c3); // s, not e
else
if('o' == c1)
if('c' == c2)
if('t' == c3)
mnth = 10; // oct
else error(c1, c2, c3); // oc, not t
else error(c1, c2, c3); // o, not c
else
if('n' == c1)
if('o' == c2)
if('v' == c3)
mnth = 11; // nov
else error(c1, c2, c3); // no, not v
else error(c1, c2, c3); // n, not o
else
if('d' == c1)
if('e' == c2)
if('c' == c3)
mnth = 12; // dec
else error(c1, c2, c3); // de, not c
else error(c1, c2, c3); // d, not e
else error(c1, c2, c3);//c1 not j,f,m,a,s,o,n,or d
}
Month::Month()
{
// body deliberately empty
}


int main()
{
cout << "testing constructor Month(char, char, char)" << endl;

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

Month m;
m = Month( 'j', 'a', 'n');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'f', 'e', 'b');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'm', 'a', 'r');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'a', 'p', 'r');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'm', 'a', 'y');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'j', 'u', 'n');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'j', 'u', 'l');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'a', 'u', 'g');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 's', 'e', 'p');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'o', 'c', 't');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'n', 'o', 'v');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
m = Month( 'd', 'e', 'c');
m.outputMonthNumber( cout ); cout << " ";
m.outputMonthName(cout); cout << endl;
cout << endl << "Testing Month(int) constructor" << endl;
int i = 1;
while (i <= 12)
{
Month mm(i);
mm.outputMonthNumber( cout ); cout << " ";
mm.outputMonthName(cout); cout << endl;
i = i+1;
}
cout << endl
<< "Testing the getMonthByName and outputMonth* \n";
i = 1;
Month mm;
while (i <= 12)
{
mm.getMonthByName(cin);
mm.outputMonthNumber( cout ); cout << " ";
mm.outputMonthName(cout); cout << endl;
i = i+1;
}

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

cout << endl
<< "Testing getMonthByNumber and outputMonth* " << endl;
i = 1;
while (i <= 12)
{
mm.getMonthByNumber(cin);
mm.outputMonthNumber( cout ); cout << " ";
mm.outputMonthName(cout); cout << endl;
i = i+1;
}
cout << endl << "end of loops" << endl;
cout << endl << "Testing nextMonth member" << endl;
cout << "current month ";
mm.outputMonthNumber(cout); cout << endl;
cout << "next month ";
mm.nextMonth().outputMonthNumber(cout); cout << " ";
mm.nextMonth().outputMonthName(cout); cout << endl;
cout << endl << "new Month created " << endl;
Month mo(6);
cout << "current month ";
mo.outputMonthNumber(cout); cout << endl;
cout << "nextMonth ";
mo.nextMonth().outputMonthNumber(cout); cout << " ";
mo.nextMonth().outputMonthName(cout); cout << endl;
return 0;
}

/*
A partial testing run follows:
$a.out
testing constructor Month(char, char, char)
1 Jan
2 Feb
3 Mar
4 Apr
5 May
6 Jun
7 Jul
8 Aug
9 Sep
10 Oct
11 Nov
12 Dec
Testing Month(int) constructor
1 Jan

Remainder of test run omitted
*/
\

2. Redefinition of class Month
Same as #1, except state is now the 3 char variables containing the first 3 letters of month name.
Variant: Use C-string to hold month.
Variant 2: Use vector of char to hold month. This has more promise.

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


3. “Little Red Grocery Store Counter”
A good place to start is with the solution to #2 from Chapter 6.

The class counter should provide:
A default constructor. For example, Counter(9999); provides a counter that can count up
to 9999 and displays 0.
A member function, void reset() that returns count to 0
A set of functions that increment digits 1 through 4:
void incr1() //increments 1 cent digit
void incr10() //increments 10 cent digit
void incr100() //increments 100 cent ($1) digit
void incr1000() //increments 1000 cent ($10)digit
Account for carries as necessary.
A member function bool overflow(); detects overflow.
Use the class to simulate the little red grocery store money counter.
Display the 4 digits, the right most two are cents and tens of cents, the next to are dollars and
tens of dollars.
Provide keys for incrementing cents, dimes, dollars and tens of dollars.
Suggestion: asdfo: a for cents, followed by 1-9
s for dimes, followed by 1-9
d for dollars, followed by 1-9
f for tens of dollars, followed by 1-9
Followed by pressing the return key in each case.
Adding is automatic, and overflow is reported after each operation. Overflow can be requested
with the O key.
Here is a tested implementation of this simulation.

You will probably need to adjust the PAUSE_CONSTANT for your machine, otherwise the
pause can be so short as to be useless, or irritatingly long.

//Ch7prg3.cpp
//
//Simulate a counter with a button for each digit.
//Keys a for units
// s for tens, follow with digit 1 -9
// d for hundreds, follow with digit 1 -9
// f for thousands, follow with digit 1 -9
// o for overflow report.
//
//Test thoroughly
//
//class Counter
//
// default constructor that initializes the counter to 0
// and overflowFlag to 0
// member functions:
// reset() sets count to 0 and overflowFlag to false

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

// 4 mutators each of which increment one of the 4 digits.
// (carry is accounted for)
// bool overflow() returns true if last operation resulted in
// overflow.
// 4 accessors to display each digit
// a display function to display all 4 digits
//
//
// The class keeps a non -negative integer value.
// It has an accessor that returns the count value,
// and a display member that write the current count value
// to the screen.

#include <iostream>
using namespace std;

const int PAUSE_CONSTANT = 100000000; // 1e8
void pause(); // you may need to adjust PAUSE_CONSTANT

class Counter
{
public:
Counter();

//mutators
void reset();
void incr1();
void incr10();
void incr100();
void incr1000();

//accessors
void displayUnits();
void displayTens();
void displayHundreds();
void displayThousands();

int currentCount();
void display();

bool overflow();

private:
int units;
int tens;
int hundreds;
int thousands;
bool overflowFlag;
};
int main()
{
int i;
int j; // digit to follow "asdf"
char ch;

Counter c;
int k = 100;

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

while(k-- > 0)
{
system("cls");
//system("clear");

if(c.overflow())
cout << "ALERT: OVERFLOW HAS OCCURRED. RESULTS "
<< "ARE NOT RELIABLE. Press Q to quit. \n";

cout << endl;
c.displayThousands(); c.displayHundreds();
cout << ".";
c.displayTens(); c.displayUnits();
cout << endl;
cout << "Enter a character followed by a digit 1 -9:\n"
<< "Enter a for units \n"
<< " s for tens \n"
<< " d for hundreds \n"
<< " f for thousands \n"
<< " o to inquire about overflow \n"
<< "Q or q at any time to quit. \n";
cin >> ch;

//vet value of ch, other housekeeping
if(ch != 'a' && ch != 's' && ch != 'd' && ch != 'f')
{
if(ch == 'Q' || ch == 'q')
{
cout << ch << " pressed. Quitting \n";
return 0;
}

if(ch == 'o')
{ cout << "Overflow test requested \n";
if(c.overflow())
{
cout << "OVERFLOW HAS OCCURRED. RESULTS "
<< "ARE NOT RELIABLE. Press Q to quit. \n";
}
pause();
continue; //restart loop
}
cout << "Character entered not one of a, s, d, f, or o. \n";
pause();
continue; //restart loop.
}

cin >> j;
// vet value of j
if( !(0 < j && j <= 9))
{
cout << "Digit must be between 1 and 9 \n";
continue;
}

switch(ch)
{

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

case 'a': for(i = 0; i < j; i++)
c.incr1();
break;
case 's': for(i = 0; i < j; i++)
c.incr10();
break;

case 'd': for(i = 0; i < j; i++)
c.incr100();
break;

case 'f': for(i = 0; i < j; i++)
c.incr1000();
break;
case 'Q': // fall through
case 'q': cout << "Quitting \n";
return 0; // quit.

default: cout << "Program should never get here \n"
<< "Fix program\n";
abort();
}
cout << "At end of switch \n";
}

return 0;
}

// Implementations

void pause()
{
cout << "Pausing for you to read . . . \n";
for(int X = 0; X < PAUSE_CONSTANT; X++)
{
X++; X--;
}
}
void Counter::displayUnits()
{
cout << units;
}
void Counter::displayTens()
{
cout << tens;
}
void Counter::displayHundreds()
{
cout << hundreds;
}
void Counter::displayThousands()
{
cout << thousands;
}

void Counter::reset()
{

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

units = tens = hundreds = thousands = 0;
overflowFlag = false;
}

void Counter::display()
{
cout << thousands << hundreds
<< tens << units ;
}

bool Counter::overflow()
{
return overflowFlag;
}

Counter::Counter():units(0), tens(0), hundreds(0),
thousands(0), overflowFlag(false)
{// body deliberately empty
}

void Counter::incr1()
{
if(units < 9)
units++;
else
{
units = 0;
if(tens < 9)
tens++;
else
{
tens = 0;
if(hundreds < 9)
hundreds++;
else
{
hundreds = 0;
if(thousands < 9)
thousands++;
else
overflowFlag = true;
}
}
}
}

void Counter::incr10()
{
if(tens < 9)
tens++;
else
{
tens = 0;
if(hundreds < 9)
hundreds++;
else
{

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

hundreds = 0;
if(thousands < 9)
thousands++;
else
overflowFlag = true;
}
}
}

void Counter::incr100()
{
if(hundreds < 9)
hundreds++;
else
{
hundreds = 0;
if(thousands < 9)
thousands++;
else
overflowFlag = true;
}
}
void Counter::incr1000()
{
if(thousands < 9)
thousands++;
else
{
thousands = 0;
overflowFlag = true;
}
}

4. Hot Dogs
You operate several hot dog stands distributed throughout town. Definite a class named
HotDogStand that has a member variable for the hot dog stand's ID number and a member
variable for how many hot dogs the stand has sold that day. Create a constructor that allows a
user of the class to initialize both values.

Also create a method named "JustSold" that increments the number of hot dogs the stand has
sold by one. The idea is that this method will be invoked each time the stand sells a hot dog so
that we can track the total number of hot dogs sold by the stand. Add another method that
returns the number of hot dogs sold.

Finally, add a static variable that tracks the total number of hotdogs sold by all hot dog stands
and a static method that returns the value in this variable.

Write a main method to test your class with at least three hot dog stands that each sell a variety
of hot dogs.

CodeMate Hint: Recall that static variables must be initialized outside of the class definition.

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


//hotdogs.cpp
//This program defines a class for tracking hot dog sales.
//
//It tracks the stand's ID number, hot dogs sold at each stand,
// and hot dogs sold at all stands.

#include <iostream>
#include <cstdlib>

using namespace std;

class HotDogStand
{
public:
HotDogStand();
HotDogStand(int newID, int newNnumSold);
int GetID();
void SetID(int newID);
void JustSold();
int GetNumSold();
static int GetTotalSold();

private:
static int totalSold;
int numSold;
int ID;
};

int HotDogStand::totalSold = 0;

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

// ======================
// HotDogStand::HotDogStand
// The default constructor initializes the ID and num sold to zero.
// ======================
HotDogStand::HotDogStand()
{
numSold = 0;
ID = 0;
}

// ======================
// HotDogStand::HotDogStand
// This constructor initializes the ID and num sold.
// ======================
HotDogStand::HotDogStand(int newID, int newNumSold)
{
numSold = newNumSold;
ID = newID;
}

// ======================

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

// HotDogStand::GetID
// Returns the ID number of this stand.
// ======================
int HotDogStand::GetID()
{
return ID;
}

// ======================
// HotDogStand::SetID
// Sets the ID number of this stand.
// ======================
void HotDogStand::SetID(int newID)
{
ID = newID;
}

// ======================
// HotDogStand::JustSold
// Increments the number of hotdogs this stand
// has sold by one.
// ======================
void HotDogStand::JustSold()
{
numSold++; // increment number sold at this stand
totalSold++; // increment number sold across all stands
}

// ======================
// HotDogStand::GetNumSold
// Returns the number of hotdogs this stand has sold.
// ======================
int HotDogStand::GetNumSold()
{
return numSold;
}

// ======================
// HotDogStand::GeTotalSold
// Returns the number of hotdogs sold by all stands
// ======================
int HotDogStand::GetTotalSold()
{
return totalSold;
}


//
// --------------------------------
// --------- END USER CODE --------
// --------------------------------



// ======================
// main function
// ======================

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

int main()
{
// Test our code with three hot dog stands
HotDogStand s1(1,0),s2(2,0),s3(3,0);

// Sold at stand 1, 2
s1.JustSold();
s2.JustSold();
s1.JustSold();

cout << "Stand " << s1.GetID() << " sold " << s1.GetNumSold() << endl;
cout << "Stand " << s2.GetID() << " sold " << s2.GetNumSold() << endl;
cout << "Stand " << s3.GetID() << " sold " << s3.GetNumSold() << endl;
cout << "Total sold = " << s1.GetTotalSold() << endl;
cout << endl;

// Sold some more
s3.JustSold();
s1.JustSold();

cout << "Stand " << s1.GetID() << " sold " << s1.GetNumSold() << endl;
cout << "Stand " << s2.GetID() << " sold " << s2.GetNumSold() << endl;
cout << "Stand " << s3.GetID() << " sold " << s3.GetNumSold() << endl;
cout << "Total sold = " << s1.GetTotalSold() << endl;
cout << endl;
return 0;
}

5. Suitors
In an ancient land, the beautiful princess Eve had many suitors. She decided on the following
procedure to determine which suitor she would marry. First, all of the suitors would be lined up
one after the other and assigned numbers. The first suitor would be number 1, the second
number 2, and so on up to the last suitor, number n. Starting at the first suitor she would then
count three suitors down the line (because of the three letters in her name) and the third suitor
would be eliminated from winning her hand and removed from the line. Eve would then
continue, counting three more suitors, and eliminating every third suitor. When she reached the
end of the line she would continue counting from the beginning.

For example, if there were 6 suitors then the elimination process would proceed as follows:

123456 initial list of suitors, start counting from 1
12456 suitor 3 eliminated, continue counting from 4
1245 suitor 6 eliminated, continue counting from 1
125 suitor 4 eliminated, continue counting from 5
15 suitor 2 eliminated, continue counting from 5
1 suitor 5 eliminated, 1 is the lucky winner

Write a program that uses a vector to determine which position you should stand in to marry the
princess if there are n suitors. You will find the following method from the Vector class useful:

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

v.erase(iter);
// Removes element at position iter

For example, to use this method to erase the 4th element from the beginning of a vector variable
named theVector use:

theVector.erase(theVector.begin() + 3);

The number 3 is used since the first element in the vector is at index position 0.

CodeMate Hint: Use a vector of size n and a loop that continues to eliminate the next suitor until
the size of the vector includes only one element.

//suitors.cpp
//
//This program determines where to stand in line if you would
// like to win the hand of the princess. The princess eliminates
// every third suitor and loops back to the beginning of the line upon
// reaching the end.
//
//This program uses a vector to store the list of suitors and removes
// each one in turn.

#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;


// ======================
// main function
// ======================
int main()
{
// Variable declarations
int i;
int current;
int numSuitors;

cout << "Enter the number of suitors" << endl;
cin >> numSuitors;

vector<int> suitors(numSuitors);

for (int i=0; i<numSuitors; i++)
{
suitors[i] = i+1; // Number each suitor's position
}

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

if (numSuitors <=0)
{
cout << "Not enough suitors." << endl;
}
else if (numSuitors == 1)
{
cout << "You would stand first in line." << endl;
}
else
{
current=0; // Current suitor the princess will examine
// Eliminate a suitor as long as there is at least one
while (suitors.size() > 1)
{
// Count three people ahead, or go two people down
// since we include the current person in the count
for (i=0; i<2; i++)
{
current++;
// If we reached the end, go back to the front
if (current == suitors.size())
{
current=0;
}
}
// Eliminate contestant current
suitors.erase(suitors.begin() + current);
// If we were at the last suitor, go to the first one
if (current == suitors.size())
{
current=0;
}
}
cout << "To win the princess, you should stand in position " <<
suitors[0] << endl;
}

// --------------------------------
// --------- END USER CODE --------
// --------------------------------
return 0;
}


6. More Pizza
This Programming Project requires you to first complete Programming Project 7 from Chapter 5,
which is an implementation of a Pizza class. Add an Order class that contains a private vector
of type Pizza. This class represents a customer’s entire order, where the order may consist of
multiple pizzas. Include appropriate functions so that a user of the Order class can add pizzas to
the order (type is deep dish, hand tossed, or pan; size is small, medium, or large; number of
pepperoni or cheese toppings). You can use constants to represent the type and size. Also write
a function that outputs everything in the order along with the total price. Write a suitable test
program that adds multiple pizzas to an order(s).

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


Notes: The following solution uses the pizza.h and pizza.cpp classes from Programming Project
7 of Chapter 5.

// order.h
//
// Interface file for the Pizza ordering class.

#include "pizza.h"
#include <vector>
#include <iostream>
using namespace std;

class Order
{
public:
Order();
~Order() {};
void addPizza(Pizza p);
void outputOrder();
private:
vector<Pizza> orders;
};

// order.cpp
//
// Implementation file for the Pizza ordering class.

#include "order.h"
#include <vector>
#include <iostream>
using namespace std;

Order::Order()
{
}

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

void Order::addPizza(Pizza p)
{
orders.push_back(p);
}

void Order::outputOrder()
{
double total = 0;
cout << "There are " << orders.size() <<
" pizzas in the order." << endl;
for (int i=0; i<orders.size(); i++)
{
orders[i].outputDescription();
total += orders[i].computePrice();
}

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

cout << "The total price is $" << total << endl;
}


// --------------------------------
// --------- END USER CODE --------
// --------------------------------


// ======================
// main function
// ======================
int main()
{
// Variable declarations
Order myOrder;
Pizza cheesy;
Pizza pepperoni;

// Make some pizzas
cheesy.setCheeseToppings(3);
cheesy.setType(HANDTOSSED);

pepperoni.setSize(LARGE);
pepperoni.setPepperoniToppings(2);
pepperoni.setType(PAN);

// Add to the order
myOrder.addPizza(cheesy);
myOrder.addPizza(pepperoni);

// Output order
myOrder.outputOrder();

cout << endl;
}


7. Money Constructor
Do Programming Project 6.8, the definition of a Money class, except create a default constructor
that sets the monetary amount to 0 dollars and 0 cents, and create a second constructor with input
parameters for the amount of the dollars and cents variables. Modify your test code to invoke the
constructors.

#include <iostream>
using namespace std;

class Money
{
public:
// Constructors
Money();
Money(int initialDollars, int initialCents);
// Functions
int getDollars();

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

int getCents();
void setDollars(int d);
void setCents(int c);
double getAmount();
private:
int dollars;
int cents;
};

Money::Money()
{
dollars = 0;
cents = 0;
}

Money::Money(int initialDollars, int initialCents) :
dollars(initialDollars), cents(initialCents)
{
}

int Money::getDollars()
{
return dollars;
}

int Money::getCents()
{
return cents;
}

void Money::setDollars(int d)
{
dollars = d;
}

void Money::setCents(int c)
{
cents = c;
}

double Money::getAmount()
{
return static_cast<double>(dollars) +
static_cast<double>(cents) / 100;
}

int main( )
{
Money m1(20, 35), m2(0, 98);

cout << m1.getDollars() << "." << m1.getCents() << endl;
cout << m1.getAmount() << endl;
cout << m2.getAmount() << endl;

cout << "Changing m1's dollars to 50" << endl;
m1.setDollars(50);
cout << m1.getAmount() << endl;

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.


cout << "Enter a character to exit." << endl;
char wait;
cin >> wait;
return 0;
}

8. Histogram of Grades
Write a program that outputs a histogram of grades for an assignment given to a class of
students. The program should input each student’s grade as an integer and store the grade in a
vector. Grades should be entered until the user enters -1 for a grade. The program should then
scan through the vector and compute the histogram. In computing the histogram the minimum
value of a grade is 0 but your program should determine the maximum value entered by the user.
Output the histogram to the console. See Programming Project 5.7 for information on how to
compute a histogram.

#include <iostream>
#include <vector>

using namespace std;

int main()
{
vector<int> grades;
int max = -1;
int score;
int i;

// Input grades until -1 is entered
cout << "Enter each grade and then -1 to stop." << endl;
do
{
cin >> score;
// Add to vector
if (score >= 0)
{
grades.push_back(score);
// Remember the largest value
if (score > max)
max = score;
}
} while (score != -1);

// Create histogram vector large enough to store the largest score
vector<int> histogram(max+1);
// Initialize histogram to 0
for (i=0; i<=max; i++)
{
histogram[i]=0;
}

// Loop through grades and increment histogram index
for (i=0; i<grades.size(); i++)

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

{
histogram[grades[i]]++;
}

// Output histogram
for (i=0; i<=max; i++)
{
cout << histogram[i] << " grade(s) of " << i << endl;
}
cout << endl;

cout << "Enter a character to exit." << endl;
char wait;
cin >> wait;
return 0;
}


9. POSTNET Bar Codes
The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip
code using a format called POSTNET (this format is being deprecated in favor of a new system,
OneCode, in 2009). The bar code consists of long and short bars as shown below:



For this program we will represent the bar code as a string of digits. The digit 1 represents a
long bar and the digit 0 represents a short bar. Therefore, the bar code above would be
represented in our program as:

110100101000101011000010011

The first and last digits of the bar code are always 1. Removing these leave 25 digits. If these 25
digits are split into groups of five digits each then we have:

10100 10100 01010 11000 01001

Next, consider each group of five digits. There will always be exactly two 1’s in each group of
digits. Each digit stands for a number. From left to right the digits encode the values 7, 4, 2, 1,
and 0. Multiply the corresponding value with the digit and compute the sum to get the final
encoded digit for the zip code. The table below shows the encoding for 10100.
Bar Code
Digits
1 0 1 0 0
Value 7 4 2 1 0
Product of
Digit * Value
7 0 2 0 0
Zip Code Digit = 7 + 0 + 2 + 0 + 0 = 9

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

Repeat this for each group of five digits and concatenate to get the complete zip code. There is
one special value. If the sum of a group of five digits is 11, then this represents the digit 0 (this
is necessary because with two digits per group it is not possible to represent zero). The zip code
for the sample bar code decodes to 99504. While the POSTNET scheme may seem
unnecessarily complex, its design allows machines to detect if errors have been made in scanning
the zip code.

Write a zip code class that encodes and decodes five digit bar codes used by the US Postal
Service on envelopes. The class should have two constructors. The first constructor should
input the zip code as an integer and the second constructor should input the zip code as a bar
code string consisting of 0’s and 1’s as described above. Although you have two ways to input
the zip code, internally the class should only store the zip code using one format (you may
choose to store it as a bar code string or as a zip code number.) The class should also have at
least two public member functions, one to return the zip code as an integer, and the other to
return the zip code in bar code format as a string. All helper functions should be declared
private. Embed your class definition in a suitable test program.

#include <iostream>
#include <string>
using namespace std;

class ZipCode
{
public:
ZipCode(int zip);
// Constructs a ZipCode from an integer zip code value
ZipCode(string code);
// Constructs a ZipCode from a string of 1's and 0's
string get_bar_code();
// Returns the zip code in bar form
int get_zip_code();
// Returns the zip code in numeric form

private:
int zip;
int parse_bar_code(string code);
// Returns an integer, parsed from the given bar code.
// If the code is not valid, this function will print
// an error message and then exit.
};


// Constructs a ZipCode from an integer zip code value
ZipCode::ZipCode(int z) : zip(z)
{
}

// Constructs a ZipCode from a string of 1's and 0's
ZipCode::ZipCode(string code)
{
zip = parse_bar_code(code);
}

Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

Copyright © 2012 Pearson Education Addison-Wesley. All rights reserved.

// Returns an integer, parsed from the given bar code.
// If the code is not valid, this function will print
// an error message and then exit.
int ZipCode::parse_bar_code(string code)
{
int value = 0;

if (((code.length() - 2) % 5) != 0)
{
cout << "ERROR: '" << code << "' has invalid length " << endl
<< " (Length must be 5*n+2, where n is the number of"
<< endl
<< " digits in the zip code)" << endl;
return -1;
}
else if ((code[0] != '1') || (code[code.length() - 1] != '1'))
{
cout << "ERROR: '" << code << "' must begin and end with '1'" << endl;
return -1;
}
else
{
int digits = (code.length() - 2)/5;

// Each position 0 - 5 in each 1/0 digit sequence has
// a unique value. Putting these in an array lets us
// map a digit position to a value by doing an array
// lookup, rather than an if -else-if statement.
int values[] = { 7, 4, 2, 1, 0 };

for (int d = 0; d < digits; d++)
{
int digit = 0;
for (int i = 0; i < 5; i++)
{
char ch = code[d * 5 + i + 1];
if (ch == '1')
{
digit += values[i];
}
else if (ch != '0')
{
cout << "ERROR: '" << code
<< "' must contain only '1' and '0'" << endl;
// exit(1);
return -1;
}
}

if ((digit < 1) || (digit == 10) || (digit > 11))
{
cout << "ERROR: '" << code << "' has invalid sequence '"
<< code.substr(d * 5 + 1, 5) << "'" << endl;
// exit(1);
return -1;
}

Exploring the Variety of Random
Documents with Different Content

istuutui hän Kazarskin kuvapatsaan lähelle ja alkoi polttaa
paperossia.
Parooni Pesth näyttäytyi hänkin bulevardilla. Hän kertoi olleensa
mukana aselepoa tehtäessä ja puhelleensa ranskalaisten upseerien
kanssa ja että eräs näistä muka oli hänelle sanonut: s'il n'avait pas
fait clair encore pendant une demi-heure les embuscades auraient
été reprises,[10] ja kuinka hän oli vastannut: monsieur! je ne dis pas
non, pour ne pas vous donner un dementi,[11] ja kuinka mainiosti
se oli sanottu j.n.e.
Asia oli niin että vaikka hän oli ollut mukana aselepoa tehtäessä, ei
hän kuitenkaan tullut sanoneeksi mitään erityistä vaikka hänellä kyllä
oli kova halu puhella ranskalaisten kanssa (sehän on niin kovin
hauskaa). Junkkari, parooni Pesth oli kauan aikaa kävellyt
edestakaisin pitkin linjaa ja kysellyt ehtimiseen lähellä olevilta
ranskalaisilta: de quel régiment êtes vous? Hän sai vastauksen —
eikä enempää. Vaan kun hän meni liian kauas linjan toiselle puolelle,
niin ranskalainen vahtisotamies, joka ei osannut arvata että tuo
sotamies osaa ranskaa, rupesi haukkumaan yksikön kolmannessa
persoonassa: "Il vient regarder nos travaux ce sacré…" sanoi hän,
jolloin junkkari parooni Pesth, välittämättä enää aselevosta lähti
kotia ja sovitti matkalla ne ranskalaiset lauseparret, joita nyt lateli.
Bulevardilla oli myöskin kapteeni Zobov, joka puhua rähisi kovalla
äänellä, siellä resuisen näköinen kapteeni Obzhogov, siellä tykkiväen
kapteeni, joka ei pyrkinyt kenenkään suosioon, siellä naisten suosikki
junkkari, siellä kaikki nuo eiliset henkilöt, iänikuisine vaikuttimineen.
Puuttui vain Praskuhin, Neferdov ja vielä joku, mutta heitä tuskin
kukaan muisti ja ajatteli, sillä heidän ruumiitaan ei vielä oltu ehditty
pestä, pukea eikä panna maahan.

XVI.
Meikäläisten vallinsarvelle ja ranskalaisten saartokaivannolle on
nostettu valkeita lippuja ja niiden välissä kukoistavassa laaksossa
viruu läjittäin saappaattomia, harmaa- ja sinipukuisia silvottuja
ruumiita, joita työmiehet pinoovat kuormarattaille. Kalmanhaju
täyttää ilman. Sevastopolista ja ranskalaisten leiristä on tulvinut
väkeä katselemaan tätä näytelmää, lähestyen toisiaan ahneen ja
hyväntahtoisen uteliaina. Kuunnelkaahan, mitä nuo ihmiset
puhelevat keskenään.
Tuossa on venäläisiä ja ranskalaisia piirissä nuoren upseerin
ympärillä, joka tosin huonosti, vaan kyllin ymmärrettävästi puhuen
ranskaa tarkastelee kaartilaisen patruunakoteloa.
— E sesii purkuaa se uazoo liee?[12] — kysyi hän.
— Parce que c'est une giberne d'un régiment de la garde,
monsieur, qui porte l'aigle imperial.[13]
— E vu de la gard?[14]
— Pardon, monsieur, du 6 ème de ligne.[15]
— E sesii u ashtee?[16] — kysyy upseeri, osottaen ranskalaisen
keltaista puista paperossin imuketta.
— A Balaclava, monsieur! C'est tout simple en bois de palme.[17]
— Zholii,[18] — sanoo upseeri, jonka täytyy sovittaa puheensa
vähemmin oman tahtonsa kuin niiden ranskalaisten sanojen mukaan,
joita taitaa.

— Si vous voulez bien garder cela comme souvenir de cette
rencontre, vous m'obligerez.[19]
Ja kohtelias ranskalainen puhaltaa paperossin ja tarjoaa imukkeen
upseerille hieman kumartaen. Upseeri antaa hänelle omansa, ja
kaikki läsnäolijat sekä ranskalaiset että venäläiset näyttävät hyvin
tyytyväisiltä ja hymyilevät.
Tuossa reipas punapaitainen jalkasotamies tulee sinelli harteilla ja
toisten sotamiesten seuraamana, jotka kädet seläntakana ja iloisin,
uteliain kasvoin astuvat hänen perässään ja pyytää ranskalaiselta
tulta piippuunsa. Ranskalainen imasee piippuaan, kaivaa pesää ja
karistaa tulen venäläisen piippuun.
— Tupakka bun! — virkkoi punapaitainen sotamies — ja katselijat
hymyilevät.
— Oui, bon tabac, tabac turc — sanoo ranskalainen: et chèz vous
autres, tabac — russe? bon?[20] — rus — bun, — sanoo
punapaitainen sotamies läsnäolijain nauraessa pakahtuakseen. —
Frantsee niet bun, bonzhuurmusjee![21] — puhuu edelleen
punapaitainen sotamies kerrassaan tyhjentäen koko kielivarastonsa
ja taputtaa ranskalaista vatsaan ja nauraa. Ranskalaisetkin nauravat.
— Ils ne sont pas jolis ces b…de Russes,[22] — sanoo eräs zuavi
ranskalaisten joukosta.
— De quoi de ce qu'ils rient donc?[23] — kysyy toinen, tumma
sotamies italiaksi murtaen ja lähestyy meikäläisiä.
— Kaftan bun[24] — sanoo reipas sotamies, tarkastellen zuavin
kirjailtuja takin liepeitä, ja taas nauretaan.

— Ne sors pas de ta ligne, à vos places, sacré nom![25] — huutaa
ranskalainen korpraali ja sotamiehet hajaantuvat huomattavan
tyytymättöminä.
Vaan tuolla ranskalaisten upseerien ryhmässä on nuori venäläinen
ratsuväenupseeri perin miellyttämistä. Puhellaan eräästä comte
Sazonov'ista, que j'ai beaucoup connu, monsieur,[26] — puhuu
yksipolettinen ranskalainen upseeri — c'est un de ces vrais comtes
russes, comme nous les aimons.[27]
— Il y a un Sazonov, que j'ai connu — sanoo ratsu-upseeri, —
mais il n'est pas comte, à moins, que je sache; un petit brun de
votre âge à peu prés.[28]
— Cest ca, monsieur, c'est lui. Oh, que je voudrais le voir ce cher
comte. Si vous le voyez, je vous prie bien de lui faire mes
compliments. — Capitaine Latour,[29] — sanoo hän kumartaen.
— N'est ce pas terrible la triste besogne, que nous faisons? Ça
chauffait cette nuit, n'est-ce pas?[30] — kysyy ratsu-upseeri, tahtoen
ylläpitää keskustelua ja osottaen ruumiita.
— Oh, monsieur, c'est affreux! Mais quels gaillards vos soldats,
quels gaillards! C'est un plaisir, que de se battre avec des gaillards
comme eux.[31]
— Il faut avouer que les votres ne se mouchent pas du pied non
plus,[32] — sanoo ratsu-upseeri, kumartaen ja luulotellen olevansa
hyvin miellyttävä.
Vaan jo riittää.

Katsokaahan mieluummin tuota kymmenvuotiasta poikanaskalia,
jolla on vanha — kenties isänsä — lakki päässä, jalassa paljaat
kengät ja vain yhden kannattimen varassa riippuvat nankinihousut ja
joka ilmestyen vallin takaa on hamasta aselevon alusta samoillut
laaksossa tylsän uteliaana katsellen ranskalaisia ja maassa viruvia
ruumiita ja poiminut vaaleansinisiä kukkia, jotka yltyleensä peittävät
laakson. Palatessaan kotia suuri kukkakimppu kädessä hän pitelee
nenäänsä tuulen tuomalta löyhkältä, ja pysähtyen siihen pinotun
ruumiskasan ääreen katselee kauan kammottavaa päätöntä
ruumista, joka on häntä likinnä. Seistyään pitkän aikaa paikallaan
hän siirtyy lähemmä ja koskettaa jalallaan ruumiin jäykkää oikaistua
käsivartta. Käsivarsi hieman liikahtaa. Hän koskettaa sitä vielä kerran
ja kovemmin. Käsivarsi hieman liikahtaa ja asettuu taas entiselle
paikalleen. Äkkiä poika kirkaisee, piilottaa kasvonsa kukkiin ja
juoksee minkä jalat kantavat linnotukselle päin.
Niin, vallinsarvella ja saartokaivannolla liehuvat valkeat liput,
kukoistava laakso on täynnä ruumiita, ihana aurinko laskee siniseen
mereen ja sininen meri välkkyy keinuen auringon kultaisissa säteissä.
Tuhannet ihmiset kokoontuvat yhteen katselemaan, puhumaan ja
hymyilemään toinen toisilleen ja nuo ihmiset, samaa ylevää
rakkauden ja itsekieltäytymyksen lakia tunnustavat kristityt eivät
katsellessaan sitä mitä ovat tehneet heti lankea katumuksesta
polvilleen Sen eteen, joka antaessaan heille elämän, istutti jokaisen
sydämeen, paitsi kuolemanpelkoa, rakkauden hyvyyteen ja
kauneuteen, ja ilon ja onnen kyynelin syleile toisiaan veljinä. Vaan
poissa ovat valkeat liput ja taas toimivat kuoleman ja kärsimysten
välikappaleet, taas vuotaa viaton veri ja kuuluu voihkinaa ja
kirouksia.

Ja niinpä olen puhunut mitä minulla tällä kertaa oli puhumista.
Mutta raskas epätietoisuus valtaa minut. Kenties minun ei olisi
pitänytkään puhua, kenties se, mitä olen puhunut, on niitä ilkeitä
totuuksia, jotka itsetiedottomasti piilevät jokaisen sielussa ja
saattavat käydä turmiollisiksi kun ne tuodaan julki, kuten viinin
sakka, joka sekotettuna pilaa viinin.
Missä on tässä kertomuksessa se paha, jota on vältettävä, missä
hyvä, jota on seurattava? Kuka on sen konna, kuka sankari? Kaikki
ovat hyviä ja kaikki ovat pahoja.
Ei loistavan urhoollinen Kalugin, jolla turhamaisuus on kaikkien
tekojen vaikuttimena, ei tuo tyhjänpäiväinen, hyväsydäminen
Praskuhin, vaikka hän kaatui taistelussa uskon, valtaistuimen ja
isänmaan puolesta, ei ujo Mihailov, ei Pesth, lujaa vakaumusta ja
periaatteita vailla oleva lapsi, — voi olla kertomuksen konnana eikä
sankarina.
Vaan kertomukseni sankari, jota rakastan kaikesta sielustani, jota
olen koettanut kuvata kaikessa kauneudessaan ja joka aina on ollut,
on ja tulee olemaan yhtä kaunis — on totuus.
Sevastopoli elokuulla 1855.
I.
Elokuun lopulla ajoi suurta, kalliorotkojen välissä luikertelevaa
Sevastopolin maantietä, Duvankan[33] ja Bahtshisarain välillä,
käymäjalkaa paksussa polttavassa pölyssä upseerin vankkurit

(sellaiset erityiset, joita ei enää missään muualla tapaa, ja jotka
muistuttavat puoleksi juutalaisrilloja, puoleksi venäläisiä
kuormarattaita korineen).
Rattailla istui edessä kyykkysillään tensikka pitkä nankinitakki
päällä ja ihan pehmennyt entinen upseerin lakki päässä, ohjaksia
nykien, takana, sotilasviitalla peitettyjen kääröjen ja myttyjen päällä
jalkaväenupseeri yllä kesäsinelli. Upseeri oli, mikäli saattoi päättää
hänen istuessaan, lyhytkasvuinen, vaan tavattoman tukeva, ei niin
leveä olasta olkaan kuin rinnasta selkään; hän oli tukeva ja jäntterä,
kaula ja niska olivat hänellä hyvin kehittyneet ja jäntevät. Niin
sanottua vyötärystä — hoikennusta keskivälissä vartaloa — ei hänellä
ollut, mutta ei hän ollut isovatsainenkaan; päinvastoin hän oli
pikemmin laiha, varsinkin kasvoiltaan, jotka olivat sairaloisen
kellertävät. Hänen kasvonsa olisivat olleet kauniit, ellei jonkinlainen
pöhötys ja pehmeät, ennenaikaiset paksut rypyt olisi sekottaneet ja
suurentaneet piirteitä ja antaneet kasvoille yleisen kuihtuneisuuden
ja karkeuden ilmettä. Hänen silmänsä olivat pienet, ruskeat,
tavattoman eloisat, jopa julkeat; viiksensä hyvin tuuheat, mutta
kapeat, ja pureksitut; vaan leukaa ja varsinkin poskipäitä peitti
tavattoman vahva, sakea parin päivän vanha parta. 10 päivänä
toukokuuta upseeria oli haavottanut pommin pirstale päähän, jossa
hän aina näihin asti oli pitänyt sidettä, ja nyt, tuntien itsensä jo
viikko takaperin täysin terveeksi hän matkusti Simferopolin
sairashuoneesta rykmenttiin, joka majaili jossain siellä mistä kuului
laukauksia, — mutta Sevastopolissa, Severnajassa vai
Inkermanissako, siitä hän ei vielä ollut saanut keltään täyttä selvää.
Laukaukset kuuluivat, varsinkin toisinaan kun vuoret eivät estäneet
ja tuuli toi ne perille, tavattoman selvään, taajaan ja kuten tuntui
läheltä: milloin ilma räjähdyksestä ikäänkuin värisi ja saattoi
ehdottomasti vavahtamaan, milloin seurasivat nopeasti toinen

toistaan heikommat äänet, aivan kuin rummunpärrytys, jonka silloin
tällöin keskeytti tärisyttävä jyrinä, milloin taas kaikki suli kiiriväksi
rytinäksi, joka muistutti ukkosilmaa, kun myrsky on rajuimmillaan ja
rankkasade on juuri alkanut virrata. Kaikki puhuivat ja saattoi sen
kuullakin, että on paraikaa käymässä hirmuinen pommitus. Upseeri
hoputti tensikkaa: hän näytti haluavan päästä niin pian kuin suinkin
perille. Vastaan ajoi suuri joukko venäläisiä talonpoikia, jotka olivat
kuljettaneet muonavaroja Sevastopoliin ja jotka nyt olivat sieltä
tulossa kuormat täynnä sairaita ja haavottuneita harmaaviittaisia
sotamiehiä, mustiin päällystakkeihin puettuja matruuseja,
punamyssyisiä vapaaehtoisia ja parrakasta nostoväkeä. Upseerin
rattaiden täytyi pysähtyä kuormaston nostamassa paksussa,
liikkumattomassa pölypilvessä, ja siristellen ja nyrpistellen pölyn
vuoksi, joka täytti hänen silmänsä, korvansa, upseeri katseli
sairaiden ja haavottuneiden kasvoja, jotka liikkuivat hänen ohitsensa.
— Sehän on meidän komppaniastamme tuo heikko sotamies —
sanoi tensikka kääntyen herraansa päin ja osottaen kuormarattaita,
jotka täpötäynnä haavottuneita joutuivat silloin heidän kohdalleen.
Rattailla istui edessä sivuttain parrakas ryssä vuonanvillalakki
päässä, ja, pidellen kyynäspäällään ruoskan vartta, sitoi ruoskaa.
Hänen takanaan istui vankkurien tärinässä nelisen sotamiestä eri
asennoissa. Yksi, jolla oli käsi siteessä, sinelli hartioilla paidan päällä,
istui keskellä vankkureja reippaana, vaikka olikin laiha ja kalpea, ja
oli tarttumaisillaan lakkiinsa nähtyään upseerin, vaan sitten muistikin
kai olevansa haavottunut ja olikin vain raappaisevinaan päätään.
Toinen hänen vieressään makasi rattaiden pohjalla; näkyvissä oli
vain kaksi kättä, joilla hän piteli kiinni rattaiden kaustoista, ja ylös
nostetut polvet, jotka kuin rääsytukot heiluivat sinne tänne. Kolmas,
jonka kasvot olivat turvoksissa ja jonka siteisiin käärityssä päässä

törrötti sotilaslakki, istui jalat laidalta alas roikkuen ja nojaten
kyynäspäillään polviinsa näytti nukahtaneen. Hänen puoleensa
kääntyi nyt matkustava upseeri.
— Dolzhnikov! — huusi hän.
— Minä-ä! — vastasi sotamies avaten silmänsä ja ottaen
sotilaslakin päästään, niin syvällä ja katkonaisella bassoäänellä kuin
parisenkymmentä sotamiestä olisi yhdessä huutanut.
— Milloin tulit haavotetuksi, veliseni? Sotamiehen tinamaiset
tihruiset silmät saivat eloa: näkyi, että hän tunsi päällikkönsä.
— Terveyttä toivotan, teidän jalosukuisuutenne! — virkkoi hän
samalla katkonaisella bassoäänellä.
— Missä rykmentti nyt majailee?
— Sivastopolissa majailivat, keskiviikkona aikoivat lähteä, teidän
jalosukuisuutenne.
— Mihin?
— En tiedä… varmaankin Sivernajaan, teidän jalosukuisuutenne!
Nyt, teidän jalosukuisuutenne, — lisäsi hän ääntään venyttäen ja
pannen lakin päähänsä: — jo läpi kaupungin on ruvennut
ampumaan, yhä enemmän vaan pommeja, jotta salmeen asti
kantaa; sellainen on temmellys — että auta armias, niin jotta…
Kauemmas oli mahdoton kuulla mitä sotamies puhui; mutta hänen
kasvojensa ilmeestä ja ryhdistä näkyi, että hän, kärsivän ihmisen
ilkeydellä, puhui lohduttomia asioita.

Matkustava upseeri, luutnantti Kozeljtsov, ei ollut mikään
tusinaupseeri. Hän ei ollut niitä, jotka elävät ja tekevät jotain siksi,
että muut elävät ja tekevät niin: hän teki mitä halutti ja toisetkin
tekivät samoin ja olivat vakuutetut että se oli oikein. Hän oli
verrattain lahjakas: lauloi hyvin, soitti kitaraa, puhui hyvin sujuvasti
ja kirjotti sangen helposti varsinkin kruunun papereita, mihin oli
harjaantunut pataljoonan ajutanttina ollessaan; mutta huomattavin
puoli hänen luonteessaan oli itserakas tarmokkuus, joka, vaikka
etupäässä perustuikin tuohon pikku lahjakkaisuuteen, oli
sellaisenaan räikeä ja hämmästyttävä piirre. Hänen itserakkautensa
oli sellaista, joka siihen määrin suli elämään ja joka useimmiten
kehittyy mies- ja varsinkin sotilaspiireissä, että hän ei käsittänyt
muuta valinnan mahdollisuutta kuin olla ensimäisenä tai hävitä, ja
että itserakkaus oli hänen sisäistenkin vaikuttimiensa määrääjänä:
hän oli mielellään ensimmäinen miesten joukossa, joihin vertaili
itseään.
— Kuinkas sitten! rupean kai kuuntelemaan mitä moskova[34]
lavertelee! — mutisi luutnantti, tuntien herpaisevaa mielen raskautta
ja ajatusten sekavuutta katsellessaan haavottuneiden kuljetusta ja
kuunnellessaan sotamiehen sanoja, joiden merkitystä pommituksen
äänet ehdottomasti suurensivat ja vahvistivat. — Naurettava tuo
moskova… Aja, Nikolajev! annahan mennä… Oletko nukkunut! —
lisäsi hän hieman äkäisesti tensikalle, korjaten sinellinsä liepeitä.
Ohjaksista nykäistiin, Nikolajev maiskahutti suutaan ja
kuormarattaat vierivät ravia eteenpäin.
— Syötetään vain hetkinen ja kohta, mutta nyt… eteenpäin, —
virkkoi upseeri.

II.
Kun luutnantti Kozeljtsov jo ajoi kadulle Duvankan tatarilaistalojen
sortuneiden kivimuurien keskelle, pidätti hänet pommi- ja
tykinkuulakuormasto, joka oli menossa Sevastopoliin ja oli
kasaantunut tielle.
Kaksi jalkasotamiestä istui parhaassa pölyssä sortuneen aidan
kivillä tien vieressä ja söi arbuusia leivän kanssa.
— Kauasko on matka, maamies? — virkkoi heistä muuan leipää
purren sotamiehelle, joka pieni reppu olalla pysähtyi heidän
viereensä.
— Komppaniaan menemme, — vastasi sotamies vilkaisten syrjään
arbuusista ja korjaten reppua selkäänsä. — Me olimme näetsen,
kolmatta viikkoa komppanian heinässä, vaan nyt vaativat kaikkia; en
tiedä vain missä nyt rykmentti on tällä hetkellä. Kertovat, että
meikäläiset ovat asettuneet Korabeljnajaan viime viikolla. Ettekös ole
kuulleet, hyvät herrat?
— Kaupungissa se on, veikkonen, kaupungissa, — virkkoi toinen,
vanha kuormastosotamies, joka kaivoi kääntöpääveitsellä raakaa,
valkoista arbuusia. — Me tulimme sieltä vasta puolenpäivän
tienoissa. Sitä hirmua, veli veikkoseni sinä!
— Mitä niin, hyvät herrat?
— Etkös kuule, nyt ampuu yltä ympäri, jotta ei ehjää paikkaa enää
missään. Niin on meidän poikia kaatanut, ettei sanoakaan osaa!
Ja puhuja heilahutti kättään ja korjasi lakkiaan.

Jalankulkeva sotamies pudisti miettivästi päätään, maiskahutti
kielellään, veti saapasvarresta piipun, kaivoi kynnellään mutta
panematta pesään palanutta tupakkaa, sytytti taulanpalasen
polttavan sotamiehen piipusta ja kohotti lakkiaan.
— Jumalan ainoan on valta, hyvät herrat! hyvästi jääkää! — sanoi
hän ja kohentaen reppua selkäänsä lähti astumaan tietä pitkin.
— Elähän, odottelisit ennemmin! — virkkoi vakuuttavasti arbuusin
kaivelija.
— Yhtä kaikki! — jupisi jalankulkija, pujahdellen yhdessä
rykelmässä seisovien kuormarattaiden lomitse.
III.
Kyytiasema oli täynnä väkeä kun Kozeljtsov ajoi pihalle. Ensimäinen
henkilö, jonka hän tapasi portailla, oli hintelä, hyvin nuori mies,
katsastusmies, joka yhtämittaa riiteli kahden perässään käyvän
upseerin kanssa.
— Kolmesta ei puhettakaan, kymmenen vuorokautta odottakaa!
kenraalitkin odottavat, herra hyvä! — puheli katsastusmies, tahtoen
puhua pisteliäästi matkaa tekeville: — en minä ainakaan rupea teille
valjaisiin.
— Niinpä elköön sitten annettako hevosia kenellekään, jos kerran
ei ole!… Mutta miksikäs annettiin sille eräälle lakeijallekin? — kiljui
vanhempi upseereista, teelasi kädessä ja nähtävästi välttäen
teitittelyä, vaan samalla tahtoen huomauttaa, että kävisi kyllä päinsä
sanoa katsastusmiestä sinuksikin.

— Päättäkäähän nyt itsekin, herra katsastusmies, — puheli
kangerrellen toinen, ihan nuori upseeri, — emme me oman huvimme
vuoksi matkusta. Meitähän niinmuodoin tarvitaan, koska meidät on
kutsuttu. Muuten tulen varmasti puhumaan tästä kenraalille.
Sitäpaitsi, tämähän on… tarkotan — te ette kunnioita
upseerinkutsumusta.
— Aina te sotkette! — keskeytti hänet kiukkuisesti vanhempi: — te
häiritsette vain minua; pitää osata puhua hänen kanssaan. Nyt hän
on kadottanut kaiken kunnioituksensa. Hevosia heti paikalla! —
kuulettekos?
— Varmasti, herra hyvä, vaan mistäs ottaa?… Katsastusmies
vaikeni hieman, vaan sitten yhtäkkiä tulistui ja rupesi käsillään
huitoen puhumaan.
— Kyllä minä, herra hyvä, ymmärrän ja tiedän kaikki; vaan mitäs
teette! Antakaahan minun vain (upseerien kasvoilla kuvastui
toivoa)… antakaahan minun vain olla kuukauden loppuun — niin ei
minua enää täällä nähdä. Ennemmin menen Malahovin
hautakummulle kuin jään tänne, Jumal'auta! Tehkööt niinkuin
tahtovat. Koko asemalla ei ole yhtään ainoata lujaa vankkuria nyt, ja
jo kolmeen päivään eivät hevoset ole heinän rivettäkään nähneet.
Ja katsastusmies katosi portista.
Kozeljtsov meni upseerien kanssa huoneeseen.
— Kas niin! — virkkoi vanhempi upseeri nuoremmalle ihan
tyynesti, vaikka hetki sitten oli näyttänyt olevan vihan vimmassa: —
olemme jo matkustaneet kolme kuukautta, varrotaanhan vielä
vähän. Ei hätää — kyllä ennätämme perille.

Savuinen, likainen huone oli niin täynnä upseereja ja
matkalaukkuja, että Kozeljtsov hädin tuskin löysi paikan ikkunalla,
mihin istuutui; tarkastellen kasvoja ja kuunnellen puhelua hän rupesi
tekemään paperossia. Oven oikealla puolella, vinon rasvaisen pöydän
ympärillä, jolla seisoi kaksi teekeittiötä paikkapaikoin vihertynein
kuparikyljin ja jolla oli levällään sokeria eri papereissa, istui
pääryhmä: nuori, viiksetön upseeri, uusi tikattu kaukaasialainen takki
yllä, täytti teekannua; nelisen samanlaista nuorta upseeria virui
huoneen eri nurkissa: muuan näistä nukkui turkki pään alla sohvalla;
toinen seisoi pöydän ääressä ja leikkasi lampaanpaistia kädettömälle
upseerille, joka istui pöydän ääressä. Kaksi upseeria, toisella
ajutantin sinelli, toisella ohut jalkaväen sinelli ja laukku olalla, istui
pankon vieressä, ja pelkästään jo siitä kuinka he katselivat muita ja
kuinka se, jolla oli laukku, poltti sikariaan, näkyi selvästi, etteivät he
olleet mitään rintamaan kuuluvia jalkaväenupseereja ja että he olivat
siihen tyytyväisiä. Ei heidän käytöksessään ilmennyt
ylenkatsettakaan, vaan itsetyytyväinen tyyneys, joka perustui osaksi
rahoihin, osaksi heidän ja kenraalin läheisiin väleihin — tunto
paremmuudesta, joka kasvoi aina sen peittelemisen haluksi. Vielä
nuori, paksuhuulinen tohtori ja saksalais-piirteinen tykistösotilas
istuivat melkein sohvalla makaavan nuoren upseerin jaloilla ja
laskivat rahoja. Oli vielä nelisen tensikkaa, joista toiset torkkuivat,
toiset puuhailivat matkalaukkuineen ja kääröineen lähellä ovea.
Kozeljtsov ei löytänyt kaikkien näiden henkilöjen joukossa
ainoatakaan tuttua; mutta hän rupesi uteliaasti kuuntelemaan
puhelua. Nuoret upseerit, jotka, kuten hän heti pelkän ulkonäön
nojalla päätti, juuri olivat saapuneet upseerikoulusta, miellyttivät
häntä ja ennen kaikkea muistuttivat, että hänen veljensä piti
myöskin näinä päivinä saapua upseerikoulusta eräälle Sevastopolin
patterille. Reppuselkäisessä upseerissa taas, jonka kasvot hän oli

nähnyt jossain, oli hänestä kaikki vastenmielistä ja julkeaa. Jopa hän
ajatellen: "nolaan hänet, jos hänen päähänsä vaan pälkähtää sanoa
jotain", lähti ikkunalta ja istui pankolle. Yleensä hän pelkkänä
rintamasoturina ja hyvänä upseerina ei pitänyt "esikuntalaisista",
joihin hän ensi silmäyksellä luki molemmat upseerit.
IV.
— On se kuitenkin aika kiusallista, — puhui muuan nuorista
upseereista, — olla jo näin lähellä eikä päästä perille. Kukaties nyt
tulee taistelu emmekä me ole siellä.
Äänen vinkuvassa sävyssä ja täplikkäässä raikkaassa punassa,
joka karkasi tuon upseerin nuorekkaille kasvoille hänen puhuessaan,
ilmeni tuo armas nuorekas arkuus, joka lakkaamatta pelkää, ettei
sanansa osu oikein paikalleen.
Kädetön upseeri katseli häntä hymyillen.
— Kyllä vielä ennätätte, uskokaa minua, — virkkoi hän.
Nuori upseeri katseli kunnioituksella kädettömän laihoja kasvoja,
joita odottamatta hymy kirkasti, oli ääneti ja ryhtyi uudelleen teen
juontiin. Ja todellakin, kädettömän upseerin kasvoissa, hänen
ryhdissään ja varsinkin hänen tyhjässä sinellin hihassaan ilmeni
paljon sitä tyyntä kylmäverisyyttä, jonka saattaa selittää niin, että
mitä hyvänsä tehtiinkin tai puheltiin hän näytti aivankuin sanovan:
"kaikki tuo on hyvin kaunista, kaiken tuon tiedän ja kaiken tuon voin
kyllä tehdä, jos vaan tahdon."
— Kuinkas nyt päätetään, — virkkoi taas nuori upseeri
kaukaasialaiseen takkiin puetulle toverilleen: — jäädäänkö tänne

yöksi vai lähdetäänkö omalla hevosella?
Toveri kieltäytyi lähtemästä.
— Ajatelkaahan, kapteeni, — jatkoi teetä jakeleva, kääntyen
kädettömän puoleen ja nostaen ylös veitsen, jonka tämä oli
pudottanut, — meille sanottiin, että hevoset ovat hirveän kalliita
Sevastopolissa, ja me ostimme yhteisesti hevosen Simferopolista.
— Kalliinko, arvaan että teitä on nyletty?
— Enpä tosiaankaan tiedä, kapteeni; maksoimme hevosesta ja
kärryistä yhteensä yhdeksänkymmentä ruplaa. Oliko kovin paljon? —
lisäsi hän kääntyen kaikkien sekä Kozeljtsovin puoleen, joka katseli
häntä.
— Ei, jos hevonen on nuori, — sanoi Kozeljtsov.
— Niin, eikö totta? ja meille on vakuutettu, että se on kallis… tosin
se ontuu hiukan, vaan se kyllä menee ohi. Meille sanottiin sen olevan
aika elukan.
— Mistä upseerikoulusta tulette? — kysyi Kozeljtsov, joka halusi
tietoja veljestään.
— Me tulemme nyt aatelisrykmentistä, meitä on kuusi miestä ja
me matkustamme kaikki Sevastopoliin omasta halustamme, — kertoi
puhelias upseeri: — me emme vain tiedä missä meidän patterimme
ovat: toiset sanovat Sevastopolissa, vaan nyt sanotaan, että ne
ovatkin Odessassa.
— Eiköhän Simferopolissa olisi voinut tiedustella? — kysyi
Kozeljtsov.

— Eivät tiedä… Ajatelkaahan, toverimme kävi siellä kansliassa ja
sai suut silmät täyteen hävyttömyyksiä… ajatelkaahan kuinka
epämiellyttävää… Suvaitsetteko valmiin paperossin, — sanoi hän
samalla kädettömälle upseerille, joka aikoi ottaa esiin
sikarikotelonsa.
Hän palveli tätä aivan matelevalla ihastuksella.
— Tulettehan tekin Sevastopolista? — jatkoi hän.
— Ah, Jumalani, kuinka ihmeellistä! Kuinka me kaikki Pietarissa
ajattelimme teitä, kaikkia sankareja! — sanoi hän, kääntyen
Kozeljtsovin puoleen kunnioittavasti ja hyväntahtoisen
mielistelevästi.
— Vaan täytyykös teidän nyt matkustaa takaisin? — kysyi
luutnantti.
— Sitäpä me juuri pelkäämme. Ajatelkaahan, me kun ostimme
hevosen ja hankimme kaikki mitä tarvitaan — spriillä kiehuvan
kahvipannun sekä vielä kaikenlaisia välttämättömiä pikkukapineita,
— niin meiltä on rahat ihan lopussa, — sanoi hän hiljaisella äänellä
ja katsahti toveriinsa: — niin että jos takaisin täytyy matkustaa, niin
emme tiedä mitä on tehtävä.
— Ettekös saanet muuttorahoja? — kysyi Kozeljtsov.
— Emme, — vastasi hän kuiskaten: — meille kyllä luvattiin täällä
antaa.
— Mutta onhan teillä todistus?

— Tiedän, että kaikkein tärkein on todistus, mutta minulle sanoi
Moskovassa eräs senaattori — hän on minun setäni — kun olin
hänen luonansa, että täällä annetaan: muuten olisi hän itse sen
minulle antanut. Annetaan kai siis siellä?
— Kyllä varmaan annetaan.
— Niin minäkin luulen, että siellä annetaan, — virkkoi hän tavalla,
joka todisti, että hän, kyseltyään kolmellakymmenellä asemalla
samaa asiaa ja saatuaan joka paikassa erilaisen vastauksen, ei enää
uskonut niin ketään.
V.
— Kuka on tilannut juurikassoppaa? — toitotti jotakuinkin likainen
emäntä, pyylevä, nelisenkymmenvuotias nainen, astuen huoneeseen
liemimaljaa kantaen.
Puhelu taukosi samassa ja kaikkien huoneessa ohjain silmät
kääntyivät ravintolanemäntään. Muuan upseeri iski vielä silmääkin
toiselle.
— Ah, sitä on Kozeljtsov pyytänyt, — virkkoi nuo upseeri: — täytyy
hänet herättää. Nousehan päivälliselle, sanoi hän mennen sohvalla
nukkujan luo ja tyrkkäsi tätä olkapäähän.
Seitsentoistavuotias, iloinen mustasilmäinen ja punaposkinen
nuorukainen hypähti reippaasti sohvalta ja silmiään hieroen pysähtyi
keskelle lattiaa.
— Ai, suokaa anteeksi, olkaa niin hyvä, — sanoi hän tohtorille, jota
ylösnoustessaan oli tyrkännyt.

Luutnantti Kozeljtsov tunsi samassa veljensä ja astui hänen
luokseen.
— Etkö tunne? — sanoi hän hymyillen.
— A a-a! — huudahti nuorempi veli: — sepä ihmeellistä! — ja
rupesi suutelemaan veljeään.
He suutelivat kolme kertaa, vaan kolmannella kerralla katsoivat
hämmentyneinä toisiinsa, aivankuin kummallekin olisi pälkähtänyt
päähän ajatus: miksi välttämättä juuri kolme kertaa?
— Kas niin, sepä oli hauska, — virkkoi vanhempi, tarkastellen
veljeä. — Mennään portaille juttelemaan.
— Mennään, mennään. Minä en tahdo juurikaslientä… syö sinä,
Federson! — virkkoi hän toverilleen.
— Vaan tahdoithan sinä syödä.
— En tahdo mitään.
Kun he tulivat portaille, kyseli nuorempi yhä veljeltään: "No, mitä,
kerro", ja yhä puhui kuinka hauskaa oli tavata, vaan itse ei kertonut
mitään.
Kun oli kulunut viitisen minuuttia, jonka kuluessa oli ennättänyt
syntyä äänettömyyttäkin, kysyi vanhempi veli minkävuoksi ei
nuorempi ollut mennyt kaartiin, niinkuin kaikki odottivat.
— Ennemmin halutti Sevastopoliin: täällähän, jos onnistaa, ylenee
vielä pikemmin kuin kaartissa: siellä kymmenen vuotta everstinä,
vaan täällä Todtlebenkin kahdessa vuodessa kohosi

everstiluutnantista kenraaliksi. No, ja jos taas kaatuu, niin minkäs
sille voi!
— Oletpas sinä veitikka! — virkkoi veli hymyillen.
— Ja ennen kaikkea, tiedätkös, veli, — sanoi nuorempi hymyillen
ja punastuen, aivankuin olisi ollut aikeissa sanoa jotain hyvin
hävettävää: — kaikki tuo on vähäpätöistä; ennen kaikkea pyysin
päästä sen vuoksi, että sentään vähän kuin hävettää elää Pietarissa,
kun täällä kuollaan isänmaan puolesta. Ja sitten minua halutti olla
sinunkin kanssasi, — lisäsi hän vielä ujommin.
— Sinäpäs olet lystikäs, — sanoi vanhempi veli, ottaen esiin
paperossikotelon ja häneen katsomatta. — Vahinko vaan, ettemme
saa olla yhdessä.
— Vaan sanoppas ihan toden perästä, onko vallinsarvilla
kamalata? — kysäsi äkkiä nuorempi.
— Alussa on, vaan sitten kyllä tottuu, niin ettei tunnu miltään.
Itse tulet kokemaan.
— Mutta kuule, sanoppas vielä: kuinka luulet, vallotetaankohan
Sevastopoli? Minä luulen, ettei sitä valloteta millään hinnalla.
— Jumala ties.
— Se vaan on kiusallista… Ajatteleppas mikä paha onni: meiltä
varastettiin tiellä kokonainen mytty tavaroita ja siinä oli minun
huopalakkini, niin että minä olen nyt vaikeassa asemassa, kun en
tiedä kuinka voin esiintyä.

Kozeljtsov toinen, Vladimir, oli hyvin veljensä Mihailin näköinen,
muistuttaen tätä kuin puhkeava ruusupensas loppuunkukkinutta
orjantappuraa. Tukka oli hänelläkin vaalea, vaan tuuhea ja
suortuvissa ohimoilla. Valkeassa, pehmeässä niskassa oli hänellä
vaalea hiustupsu — onnen merkki, kuten lapsenhoitajat sanovat.
Hienossa valkeassa hipiässä väri vaihteli, ja poskilla väreili
sielunliikkeet ilmaisten verevä, nuorekas puna. Samat silmät kuin
veljellä, mutta avonaisemmat ja kirkkaammat, mikä näkyi varsinkin
siitä, että niitä usein verhosi kevyt kosteus. Vaaleita haivenia rupesi
nousemaan poskille ja yläpuolelle punaisten huulten, jotka usein
asettuivat ujoon hymyyn paljastaen valkeat, välkkyvät hampaat.
Seisoen veljensä edessä solakkana, hartiakkaana, sinelli levällään,
jonka alta näkyi vinokauluksinen punainen paita, paperossi kädessä,
nojaten portaan kaiteeseen, lapsellinen ilo kasvoissaan ja ryhdissään
oli hän niin miellyttävä ja herttainen nuorukainen, ettei saattanut
häntä kyllikseen katsella. Hän iloitsi suuresti veljestään, katseli häntä
kunnioituksella ja ylpeydellä, kuvitellen hänet sankariksi; mutta
muutamissa suhteissa, nimittäin mitä hienoon sivistykseen,
ranskankielentaitoon, seurusteluun huomattavien henkilöiden
kanssa, tanssimiseen y.m. tulee, hän hieman häpesi hänen
puolestaan, tunsi paremmuutensa, jopa toivoi voivansa, jos vain
kävisi laatuun, sivistääkin veljeänsä. Kaikki hänen vaikutelmansa
olivat näihin asti vain Pietarista, erään rouvan talosta, joka piti
sievistä pojista ja oli kutsunut hänet juhlapäiviksi luokseen, sekä
senaattorin talosta Moskovassa, missä hän kerran oli tanssinut
suurissa tanssiaisissa.
VI.

Puheltuaan kyllikseen ja saatuaan lopulta kokea, että on niin vähän
yhteistä, vaikka kumpikin pitää toisesta, olivat veljekset kauan aikaa
ääneti.
— Otahan sitten kapineesi, niin lähdetään heti, — virkkoi
vanhempi.
Nuorempi punastui äkkiä ja hämmentyi.
— Suoraanko Sevastopoliin mennään? — kysyi hän hetken vaiti
oltuaan.
— Niin tietysti. Sinullahan on vähän kapineita, ne pannaan kai
kokoon.
— Mainiota! lähdetään heti paikalla, — virkkoi nuorempi huoaten
ja meni sisään.
Vaan ovea avaamatta hän pysähtyi eteiseen pää surullisesti
painuneena ja rupesi miettimään:
"Heti suoraan Sevastopoliin, pommisateeseen… kauheata! Vaan
samantekevä, kerranhan sen kuitenkin olisi täytynyt tapahtua.
Nythän on edes veli kanssani…"
Asia oli niin, että vasta nyt, ajatellessaan, että kun hän istuu
kärryihin, hän yhtä kyytiä ajaa Sevastopoliin saakka eikä mikään
sattuma enää voi tulla väliin, hänen mieleensä kuvastui selvästi
vaara, jota hän oli etsinyt, ja pelkkä ajatus, että vaara oli lähellä, sai
hänet ymmälle. Koettaen jotenkuten rauhoittua hän meni sisään;
vaan kului neljännestunti eikä häntä kuulunut takaisin, niin että veli
vihdoin avasi oven kutsuakseen hänet ulos. Nuorempi Kozeljtsov