100% found this document useful (13 votes)
23 views66 pages

Instant Download for Absolute C++ 5th Edition Savitch Solutions Manual 2024 Full Chapters in PDF

The document provides information on downloading various test banks and solution manuals, particularly focusing on the Absolute C++ 5th Edition Savitch Solutions Manual. It outlines key concepts from Chapter 7 of the manual, including constructors, inline functions, static members, and vectors, along with teaching suggestions and common pitfalls. Additionally, it includes programming project answers related to creating a Month class in C++.

Uploaded by

makishader65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (13 votes)
23 views66 pages

Instant Download for Absolute C++ 5th Edition Savitch Solutions Manual 2024 Full Chapters in PDF

The document provides information on downloading various test banks and solution manuals, particularly focusing on the Absolute C++ 5th Edition Savitch Solutions Manual. It outlines key concepts from Chapter 7 of the manual, including constructors, inline functions, static members, and vectors, along with teaching suggestions and common pitfalls. Additionally, it includes programming project answers related to creating a Month class in C++.

Uploaded by

makishader65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 66

Visit https://testbankfan.

com to download the full version and


explore more testbank or solution manual

Absolute C++ 5th Edition Savitch Solutions


Manual

_____ Click the link below to download _____


https://testbankfan.com/product/absolute-c-5th-edition-
savitch-solutions-manual/

Explore and download more testbank at testbankfan.com


Here are some suggested products you might be interested in.
Click the link to download

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/

Financial Accounting Canadian 6th Edition Harrison Test


Bank

https://testbankfan.com/product/financial-accounting-canadian-6th-
edition-harrison-test-bank/
Understanding Computers Today and Tomorrow Comprehensive
14th Edition Morley Test Bank

https://testbankfan.com/product/understanding-computers-today-and-
tomorrow-comprehensive-14th-edition-morley-test-bank/

International Business Competing in the Global Marketplace


10th Edition Hill Test Bank

https://testbankfan.com/product/international-business-competing-in-
the-global-marketplace-10th-edition-hill-test-bank/

South Western Federal Taxation 2012 Individual Income


Taxes 35th Edition Hoffman Solutions Manual

https://testbankfan.com/product/south-western-federal-
taxation-2012-individual-income-taxes-35th-edition-hoffman-solutions-
manual/

Biological Psychology 13th Edition Kalat Test Bank

https://testbankfan.com/product/biological-psychology-13th-edition-
kalat-test-bank/

Financial Accounting 4th Edition Spiceland Solutions


Manual

https://testbankfan.com/product/financial-accounting-4th-edition-
spiceland-solutions-manual/
Essentials of Business Communication 8th Edition Guffey
Test Bank

https://testbankfan.com/product/essentials-of-business-
communication-8th-edition-guffey-test-bank/
Savitch, Absolute C++ 5/e: Chapter 7, Instructor’s Manual

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

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


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

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.

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


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

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];

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


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

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;

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


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

};
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.

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


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

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 1st 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 1st 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

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


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

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)

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


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

{
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

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


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

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)

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


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

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;

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


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

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;
}

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


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

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.

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


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

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

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


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

// 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;

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


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

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)
{

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


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

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()
{

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


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

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
{

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


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

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.

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


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

//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;
}

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

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


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

// 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
// ======================

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


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

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:

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


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

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 -----
// --------------------------------

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


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

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).

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


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

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();
}

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


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

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();

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


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

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;

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


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

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++)

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


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

{
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 1 0 1 0 0
Digits
Value 7 4 2 1 0
Product of 7 0 2 0 0
Digit * Value
Zip Code Digit = 7 + 0 + 2 + 0 + 0 = 9

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


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

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);
}

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


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

// 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;
}

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


Discovering Diverse Content Through
Random Scribd Documents
— Sinä lienet niin luja, myönnytti Kustaava. — Ei minussa
raukassa ole sellaista lujuutta.

— Eikö vielä nytkään? kysyi toinen.

— En uskalla sanoa.

— Etkö uskalla? kysyi Heta kiivastuen. — Taitaisit olla valmis


kuuntelemaan, kun vain tulee joku kuiskuttelemaan.

— Älä, hyvä ystävä, sano niin, vaikeroi Kustaava. — Silloinhan


saisit ajaa pois huoneestasi. Sitä niinä ainoastaan, etten ole niin luja
kuin sinä.

— No, enhän minä ole sinun vannottajasi, sanoi Heta huomaten


toisen väsymyksen yhä lisääntyvän.

— Mutta kyllä sinun täytyy nyt totella minua siinä, että tulet tähän
istumaan ja liikuttelet kätkyttä. Minä otan pojan ja koetan saada
nukkumaan.

Kustaava totteli ja asettui rukin ääreen, antaen lapsensa Hetalle,


joka kääräisi sen vaatteisiin ja vei ulos Kustaava katsoi kysyvästi
hänen jälkeensä, mutta ei puhunut mitään. Hän kuunteli, aukeniko
ruokahuoneen ovi. "Ulos se meni", ajatteli Kustaava. "Jokohan vei
minun tietämättäni". Hän kävi kiireesti sivuikkunasta kurkistamassa
ja näki, että Heta vei lapsen latoon. "No jauhakoon vain", hän
ajatteli. "Ei sitä syntiä minulle lueta."

Hän ei sittenkään voinut olla oikein rauhallinen. Aika alkoi tuntua


pitkältä, vaikkei ollut kulunut kymmentäkään minuuttia. Jo kuului
askeleita eteisestä, ja ruokahuoneen ovi aukeni. "Nyt se juottaa
lapselle maitoa. Saahan nähdä."
Kohta tuli Heta tupaan vähän hengästyneenä ja asetti Kustaavan
lapsen oman lapsensa kätkyen jalkapuolelle ja sanoi hiljaa, mutta
varmasti:

— Saapa nähdä, eikö poika nuku.

— Mitä sinä sille teit? kysyi Kustaava, vaikka aavisti asian.

Minä jauhoin pois painajaisen, koska et itse ruvennut.

— Minä en usko painajaista olevankaan, sanoi Kustaava.

— Uskoppa tai et, mutta kohta näet, että poika nukkuu kuin hako.

— Sittenpähän uskon, jos nukkuu. Mutta mitenkä se pysyi


jauhinkiven päällä.

— Eihän se keskeltä kiveä mihin mene, selitteli toinen.

— Eikö se huutanut?

— Ei tuon enempää. Rapisteli vain silmiään, kun pyörittää hyrräsin


vuoroon myötä- ja vuoroon vastapäivään.

— Pitikö siinä loihtia?

— Ei tarvitse muuta kuin jauhaa.

— Eihän tuo sitten taida olla mikään synti.

— Synnin pelostako sinä et itse suostunut illalla jauhamaan?

— Niin, kun taikomista sanotaan synniksi.


— Kyllä siltä synniltä saat olla rauhassa, sanoi Heta. — Mutta hae
nyt ruokaa ja syö, ettet tarvitse nälkääsi valittaa.

Kustaava meni ruokahuoneeseen, mutta ei hän malttanut monta


palaa haukata, kun jo kiirehti karjan ruokintaan. Heta jäi
kehräämään ja tuudittamaan kätkyttä. Hän johtui ajattelemaan
tavallista vakavammin apulaisensa elämän kohtaloa. Ennen elänyt
huolettomia päiviä talon emäntänä, nyt leipäkannikka omaa ruokaa.
Täytyy olla tyytyväinen, kun saapi keittoa kuppiinsa ja piimää
tuoppiinsa. On tämä elämä kuitenkin kummaa nuijaroimista.

Hän alkoi hyräillä virttä: Ah mi' ompi elom' tääll', tuska vaiva
tuskan pääll'… Sitä tulla hoilotti säkeistö toisensa perästä. Sen
lurikoitteleva sävel soveltui kehtolauluksi lapsille ja oli samalla
yhteinen huokaus tämän elämän kirjavuudesta.
IV.

Hetan virsi ei ennättänyt loppua, kun metsässä ollut miesväki tuli


päivälliselle. Isännällä itsellään oli vielä toimitettavaa tallissa, mutta
talon ensikymmenen lopulla oleva poika, Veerti, kiirehti tupaan
katsomaan, oliko ruoka pöydällä. Perästä seurasi talon silloinen
työmies, mustapartainen Jaakko, jota sen vuoksi sanottiinkin Parta-
Jaakoksi. Tämäkin katsahti heti ovesta astuttuaan pöydälle, ja kun ei
siinä näkynyt mitään, niin tiristi tyytymättömänä silmäkulmiansa ja
mytisti samalla suutaan niin pitkään ja kovasti, että kulma- ja
partakarvat melkein koskettivat toisiinsa. Samanlainen silmäkulmien
ja suun liike seurasi aina, milloin Parta-Jaakko jotain ajatteli. Jos
ajatus oli mieluinen, kohoilivat ja tiristyivät kulmat ehtimiseen, ja
huulet laajenivat ja mytistyivät sitä mukaa. Jos ajatus oli oikein
hupainen, pääsi yhtäkkiä kuuluva naurun posaus.

Näistä kasvojen eleistä voi jo huomata, ettei hänellä ollut "kaikki


kotona". Mutta hän ei tehnyt kellekään pahaa, vaan teki työtäkin,
kun oli mukana muita, jotka osasivat sävyisästi irroittaa noista
pitkistä ajatuksista ja ohjata työhön. Olipa hänellä käsityötaitoakin.
Uusi kätkyt, jossa lapset parhaillaan nukkuivat, oli hänen tekemänsä.
Emäntä Heta tiesi työmiehensä ruokahalun ja kohoten rukkinsa
äärestä, sanoi:

— Tule, Veerti, liikuttelemaan kätkyttä, niin minä noudan ruokaa.

Poika lähestyi vastahakoisesti kätkyttä ja kysyi:

— Tuleeko äiti sitten liikuttelemaan, että minä pääsen syömään?

— Kyllä sinä pääset, sanoi Heta ulos mennessään.

Kun ei ruuan hakija heti palannut, alkoi Jaakko käydä


rauhattomaksi lavitsalla istuessaan. Kulmat ja huulet myträhtelivät
ehtimiseen, ja jopa täytyi nousta kävelemään ympäri tupaa.

— Tuossako se on tuokin, tokaisi hän tullessaan kätkyen lähelle,


kurtistaen samalla kulmiaan. — Eikö se omassa "lotiskossaan"…

— Siinähän tuo on, ja sitten on niin raskas liikutella, virkkoi Veerti


kenkänsä kärjellä kätkyen jalkaa pukkiloiden.

— Nosta pois! kehoitti Parta-Jaakko. — Mitä se akan pentu siinä.

— En minä, esteli toinen.

— Nosta vain, nosta vain! kehoitti Jaakko yhä kiihkeämmin. —


Olkoon vanhassa lotiskossaan.

Veerti ei näyttänyt halukkaalta. Parta-Jaakolla oli kova kiire saada


tahtonsa toteutumaan.

— Nosta nyt sukkelaan, niin minä teen taas sen…

Poika nosti ihastuneena päätään ja kysyi:


— Senkö sen?

— Sen sen, kun vain et anna äitisi särjettäväksi.

— Milloinka sinä sen teet?

— Iltasella saunassa… nosta, nosta.

Se auttoi. Liepsaus vain, niin Kustaavan poika oli vanhassa


kätkyessä. Liittolaiset istuivat paikoillaan, Parta-Jaakon huulet tekivät
tyytyväisyyttä osoittavia liikkeitä, ja hänellä oli kova työ pidätellessä
naurun posahduksia.

Kohta tuli Heta kantaen ruokaa pöydälle. Hän ei huomannut


mitään koko tapahtumasta, vaikka Jaakko samoin kuin Veertikin
olivat tavallista hitaampia hyökkäämään pöydän ääreen.

— Siinä on, hän huomautti Jaakolle ja meni kätkyen luokse.

Veertikin aikoi siirtyä pöytään, mutta silloin huomasi Heta asian ja


kysyi ihmetellen:

— Kuka tästä nosti pois Villen? Kustaavako?

Pojan äänettömyys ja hätääntyminen ilmoitti, ettei sitä ollut


Kustaava tehnyt, ja hän kysyi lujemmin:

— Sinäkö, Veerti, nostit? Äläpä tartu leipään, ennenkuin selität,


mitä varten niin teit.

Veertin silmiin alkoi kohoilla vesikarpalot, ja hän tunnusti:

— Jaakko käski nostamaan uudesta kätkyestä vanhaan.


— Vai niin, sanoi Heta tiukasti. — Pitikö sinun totella Jaakkoa? Ja
mitä varten Jaakko meni sellaista neuvomaan?

Parta-Jaakko mutisti pari kertaa kulmiaan ja sanoa tokaisi:

— Mitä se talon lapsen kätkyessä… huoripentu…

— Mitä se sinuun kuuluu, tiuskasi Heta. — Minä sen siihen asetin,


ja kun siitä ei minun lapseni pahene, niin anna olla siirtelemättä.

Parta-Jaakko olisi ehkä unohtanut koko asian ja syventynyt


mielityöhönsä, syöntiin, mutta kun Kustaavan lapsi nostettiin
takaisin, niin vielä tosahti:

— Se on minun tekemäni kätkyt.

— No eiköhän tuo saa nukkua sinun tekemässäsi, sanoi Heta


naurahtaen, vaikka harmissaan. — Siitä saattaa tulla paljon parempi
mies kuin sinusta, hupelo.

Parta-Jaakko oli herkkä suuttumaan "hupelon" nimestä, mutta


kärsi kumminkin niiden sanovan, jotka hänelle antoivat ruokaa.
Niinpä hän nytkin sivuutti sen puolen ja murahti:

— Ei tule huoripennusta.

Heta jätti Jaakon laisekseen ja kääntyi puhuttelemaan poikaansa,


johon pelkäsi tarttuneen samaa halveksimista. Hän kyseli moneen
kertaan, mitä tämä ajatteli nostaessaan, ja selitti, etteivät lapset saa
halveksia toisiansa, sillä kaikilla on sama Jumala ja kaikki ihmiset
ovat syntisiä. Hän jätti pojan rankaisematta, kun se itkusilmin lupasi
hoitaa ja suojella Kustaavan poikaa yhtä hyvin kuin omaa pientä
veljeänsä.
Parta-Jaakko ei enää kuunnellut tätä keskustelua, vaan puri ja nieli
niin tempomalla kuin nälkäinen lehmä, joka on päässyt
apilaspeltoon.
V.

Kuu valaisi hämärästi Kivimäen tuvan, jossa kaikilla joukoilla oli


nukkumapaikkansa, paitsi Parta-Jaakolla, joka nukkui mieluimmin
saunassa. Heta oli herännyt ennen puolta yötä ja käynyt ulkona
jäähdyttelemässä. Sieltä palattuaan hän huomasi, ettei Veerti
ollutkaan vuoteellaan, ja meni hätäisenä herättelemään Kustaavaa,
joka nukkui lapsensa kanssa uunin kupeella.

— Nouse, hyvä Kustaava, minun toverikseni katselemaan, mihin


Veerti on joutunut. Sitä ei näy koko tuvassa.

Kustaava nousi siunaillen ja kysyi, onko katseltu uunilta.

— En ole vielä sieltä katsellut, sanoi Heta ja kävi käsillään


haparoimassa uunin päällyksen, mutta ei siellä ollut ketään.

— Jos se on vain käymässä ulkona, arveli Kustaava.

— Jo se olisi ennättänyt tulla tavalliselta käynniltään. Eikä se ole


ottanut kenkiä eikä mitään vaatteita päälleen. Voi hyvä Jumala! Nyt
se parhaansa teki.

— Niin mitä sinä luulet? kyseli Kustaava.


— Sen on ottanut painajainen kuljetellakseen, ja nyt se raukka
paleltuu, voivotteli Heta. — Ota sinäkin päällesi vaatetta, niin
mennään yhtenä katselemaan jälkiä.

Kohta oli kumpaisellakin kengät jalassa ja turkit päällä. He


hyppäilivät kuutamossa huoneitten ympäristöllä ja tirkistelivät jalan
jälkiä kartanosta lähtevien teiden suilta.

— En minä näe mitään, sanoi Kustaava. — Jos olisi mennyt Parta-


Jaakon luokse saunaan.

— Eihän Veerti ole ennenkään mennyt yöllä saunaan. Kyllä se


painajainen otti nyt minun oman lapseni kostoksi siitä, kun kävin
jauhamassa pois sinun lapsestasi.

Kustaavakin alkoi jo kauhistua, että hänen lapsensa tautta lienee


tuollainen kirous tarttunut talon lapseen. Hän ei kuitenkaan ilmaissut
tätä ajatustaan, vaan koki uskotella pahaa paremmaksi ja sanoi:

— Minä käyn kuitenkin katsomassa saunasta.

Hän juoksi sinne ja palasi takaisin ilosta läähättäen.

— Siellä se on! Minä vilkaisin ikkunasta, niin tuli näkyi ja puhelu


kuului.

— Sepä oli hyvä, ihastui Hetakin. — Mutta mitä varten se on näin


keskellä yötä mennyt sinne.

— Mennään ja kuunnellaan hiljaa oven takaa, ehdotti Kustaava.

He hiipivät oven taakse, jossa oli harvat raot, joista näki ja kuuli,
mitä saunassa tehtiin. Jaakko istui selin oveen ja vuolla tohelti niin
työhönsä syventyneenä, että pinnistyksestä pullistuneet huulet
puksahtelivat käden liikkeen mukaan. Veerti piteli palavaa pärettä ja
katsoi tarkasti työhön.

— Noinko vahvaksi sinä jätit kaulan? kysyi Veerti.

— Vuollaan vielä, vuollaan vielä.

Alkoi taas kuulua säännöllinen puh… puh…

— Nyt se kaula välttää.

— Jo nyt, myönnytti Veerti.

Kustaava suhki oven takana Hetalle, että puuhevosta ne varmaan


tekivät.
Heta ei ennättänyt vastata, kun Veerti sanoi:

— Rallatappas vielä sitä "littuttaata", että minäkin oppisin.

— Etkö sinä vielä muista, tokaisi Parta-Jaakko. — Ei tässä joutaisi.

— Rallattele vuollessasi.

— No kuuntele sitten:

Littuttaa liukkaalla jäällä, ei ole kuka mua auttaapi täällä…


toiset köyhät toisia köyhiä armossansa auttavat.

Jaakko aikoi kiekutella saman sävelen toiseen kertaan, mutta Heta


keskeytti sen tempaisemalla auki saunan oven. Saunassa olijat
säikähtivät, ja Jaakko piilotti veistoksensa selkänsä taakse.
— Mitä renkutusta täällä Jaakko opettaa Veertille? kysyi Heta
kiivaasti.

— En minä mitään, en minä mitään, pulpatti Jaakko hätäisenä.

— Vai et mitään. Minä kuuntelin oven takana.

— Itse pyysi… itse pyysi.

— Niin teki. Mutta mikä se on se kapine, jota pitää yöllä tehdä?

— Sitä ei akoille näytetä, tosahti Parta-Jaakko.

Enempää puhumatta sivalsi Heta tuon piilotetun kapineen ja


nähdessään sen viulun tekeleeksi, löi yhtä kyytiä kiukaan kiveen
kappaleiksi. Parta-Jaakon huulet ja kulmat mutistuivat niin kamalan
näköisiksi, että Heta kiirehti ulos ja kutsui Veertin mukaansa. Saunan
edessä hän riipaisi vanhasta vastasta varvun ja alkoi piiskata
poikaansa. Mutta tuskin oli ennättänyt kahta kertaa hotaista, kun
saunan ovi aukeni ja nyrkin kokoinen kivi lennähti Hetan hartioita
kohti. Kustaava huomasi kiven heiton ja kiljaisi: nyt se hullu… mutta
Heta makasi jo suullaan poikansa jaloissa. Kustaava alkoi huutaa ja
käski Veertin mennä kutsumaan isäänsä. Peljäten Jaakon heittävän
toisella kivellä, alkoi Kustaava kainaloista kannattaen vetää Hetaa
saunatietä pitkin tupaan päin. Rappusille päästessä tuli Kaspo
unenpöpperöisenä vastaan ja alkoi kysellä, mikä Hetalle on tullut.
Kustaava selitti, että Parta-Jaakko, hullu, heitti kivellä selkään.

— Missä heitti kivellä ja mistä syystä? tiedusteli Kaspo ihmetellen.

— Se oli Veertin kanssa tekemässä saunassa viulua, selitteli


Kustaava.
— Ja kun Heta särki viulun, niin silloin se…
— Se siitä sitten tuli, alkoi Kaspo kiukutella. — Mitä varten sinne
tarvitsi mennä. Olisi antanut hupelon pitää viulunsa.

Kustaavakin jo tuskastui.

— Se asia ei enää tule sen paremmaksi, hän sanoi. —


Tarpeellisempi on katsoa, miten kävi emännälle, jääneekö
henkiinkään. Ja pitäisi kaiketi sekin hupelo sitoa köysiin.

— Vaan minäpä en mene saamaan kiveä otsaani, niinkuin te


menitte.
Olkoon ja menköön minne hyvänsä.

Heta alkoi tointua sen verran, että sai jotain sanotuksi, vaikka veri
valui suusta. Kivi oli sattunut kylkeen ja nähtävästi runnellut
kylkiluita. Ettei toki henki mennyt, oli turkin ja kumaran aseman
ansio. Hänet täytyi viedä vuoteeseen, josta ei voinut nousta koko
kevännä eikä terveenä milloinkaan. Lapset ja kaikki jäivät Kustaavan
hoitoon.

Vasta aamupuoleen yötä nukkui Veertikin, itkettyään ensin itsensä


väsyksiin. Äidin surkeutta hän enimmän itki, mutta kyllä särjetty
viulu-rottelo muistui yhtä usein mieleen.

Samana yönä hävisi Parta-Jaakko Kivimäen kuuluvilta. Se oli


Kustaavalle ja Hetalle mieleinen tieto, mutta Kaspo käveli
harmissaan, kun meni palkaton työmies, eikä ollut toista saatavissa.
Kustaava oli vielä, mutta sillekin täytyi tästä puoleen antaa talon
ruoka.
VI.

Kaksi talvea ja yhden kesän oli Kustaava asunut Kivimäen talossa.


Toinen kesä oli kauneimmillaan. Heinäjärvi lekotti melkein tyynenä.
Ainoastaan sen verran kävi tuulen henki, että kukkiva ruispelto
hiukan nuojahteli, ja tähkistä irtautunut kukkaspöly leijaili savun
tavoin pellon päällä. Vanhettunut, harmaa kartano oli puoleksi
ruisvainion ympäröimänä. Pieni vaateaitta kekotti kivisellä kummulla
ruispellon laiteella.

Aitan ovi oli auki ja sen kynnyksellä istui Kustaava, laulaen


kaiuttomalla, surullisella äänellä: Nyt on meill' Herran sapatti.

Aitan sisäpuolelta sängystä kuului vähänväliin yskimistä. Siellä


lepäsi
Heta heikkona sairaana. Tämän pitkiä, ikäviä hetkiä viihdyttääkseen
oli
Kustaava tullut aitan kynnykselle istumaan ja sunnuntaivirttä
laulamaan.

Virren loputtua seurasi äänettömyys. Kuului vain pääskysten


suritusta räystään alta.
Sairas teki taas säännölliset yskähdyksensä ja sanoi heikolla
äänellä:

— Missähän lapsetkin lienevät, kun ei kuulu ääniä.

Kustaava nousi seisoalleen ja kuulosteltuaan lasten ääniä, vastasi:

— Ei niitä kuulu nyt, mutta kyllä ne äsken olivat Veertin mukana.

— Ei siihen Veertin hoitoon ole luottamista näin kesällä, sanoi


sairas. — Jos kävisit katsomassa, etteivät menisi metsään eksymään,
ja tule sitten tänne.

Kustaava laski kirjansa aitan kynnykselle ja lähti kiertelemään


huoneiden ympäristöä. Kun ei siellä näkynyt eikä kuulunut, niin
jatkoi etsimistään ruispellon pientarille.

Pellon takimainen reuna päättyi kiviröykkiöön, joista suurimmat


kivet olivat melkein uunin kokoisia ja lepäsivät longallaan pienempien
kivien päällä. Kivien välit kasvoivat vaarainten ja mansikkain varsia,
ja siksi se paikka oli lapsille hyvin tuttu. Nyt ei ollut vielä marjoja,
mutta Kustaava arveli, että Veerti ehkä oli mennyt katselemaan
marjain joutumista. Lähemmäksi tultua alkoikin kuulua pienempien
lapsien ääniä. Mutta näiden äänien lisäksi kuului vielä omituista
vingahtelemista ja kitinää. Kustaava hidastutti askeleitaan ja siirtäen
huivia korvansa päältä kuunteli, mitä se mahtoi olla. Ja nyt hänelle
selvisi, että vingahteleva ääni tuli huonosta viulusta ja tapaili jotain
tanssisäveltä.

Kustaava peljästyi. Hän oli sairaalle sunnuntaivirsiä veisatessaan


tullut vakaviin ajatuksiin. Ja kun hän nyt muisti, että kirkossa
parhaillaan vietetään jumalanpalvelusta ja heidän lapsensa
vinguttelevat viulua, niin hän aivan kauhistui. Kuka tietää, vaikka
Jumala näyttäisi minkälaisen kamalan ihmeen hyvänsä. Kuuluuhan
niitä ennenkin tapahtuneen. Hän otti jo muutamia kiireitä askelia
siepatakseen pois oman poikansa tällaista kuulemasta kirkonaikana,
mutta pysähtyi kumminkin ajattelemaan, mikä häiriö siitä syntyisi
lasten kesken. Veerti säikähtäisi, ja talon pienempi poika jäisi
itkemään leikkitoveriansa. Muistuipa mieleen tuokin toissa talvena
tapahtunut kohtaus saunassa. Jos hän nyt yhtäkkiä ilmaisee
tietävänsä Veertin viulusalaisuuden, niin siitä seuraa, että Veerti
alkaa peljätä häntä ja ehkä rupeaa vihaamaan hänen poikaansakin.
"Mitähän piti tehdä", ajatteli Kustaava. "Ei sitä ainakaan uskalla
Hetalle sanoa. Se tulisi siitä yhä enemmän ikävälle mielelle, eikä
paraneminen edistyisi ollenkaan."

Hän kulki kumarassa lähemmäksi lapsia ja asettui salaa


tarkastelemaan lasten toimia. Veerti istui suuren kiven kupeella,
hartaana hangaten omatekoisen viulunsa rihmakieliä. Pienemmät
laittelivat riviin pieniä mukulakiviä ja kävivät välillä pyytelemässä:
"Minä toitan, minä toitan," Mutta Veerti ei heitä kuunnellut, kitkutti
vain pysähtymättä ja kääntyili selin pyytäjiin, kun ne pyrkivät
sormillaan ramputtelemaan kieliä.

Kustaava ei hennonut häiritä heidän puuhiansa. "Eihän tuo


päreviululla kitkuttaminen mahtane olla kovin kauhea synti", hän
lohdutteli itseään. "Eikähän nuo toiset ymmärrä sitä peliksi eikä
miksikään."

Kustaava kääntyi takaisin, mutta katsahti vielä kävellessään


taivaanrannalle, ettei sieltä kohoaisi ukkospilvi, jonka salama
saattaisi iskeä tuonne kiven kupeelle ja surmata lapset. Mutta tyynen
ja kauniin näköinen oli taivaanranta.
Aitan ovea lähestyessä kuului Hetan heikkoa rykimistä.

— Löytyikö ne lapset? hän kysyi Kustaa van tultua.

— Löytyi, selitti Kustaava mennen sairaan sängynlaidalle istumaan.



Tuolla olivat ison kiven kupeella talosilla.

— Sinnekö ne jäivät?

— Sinne jätin. Kyllä Veerti pitää niistä huolen.

— Hyvähän on, kun malttaa olla niiden mukana. Mutta pitäisihän


Veertin lukeakin, ettei kesän aikana entinen aivan lopen unohtuisi.

— Kyllä se sitten talvella lukee sitä enemmän, lohdutteli Kustaava.

— Vaikeatapa se on ollut Veertille lukeminen talvellakin, valitti


Heta. — Tuleva talvi saattaa mennä aivan lukematta, kun en ole
enää käskemässä.

— Olet sinä toki, ehätti Kustaava sanomaan. — Minä laitan tästä


lähtien monesti päivään uusia hauteita rinnan päälle, ja kun otat
aina tervavettä, niin kyllä sinä paranet.

— Ei ne hauteet eikä muut enää auta, sanoi sairas. — Minä


tunnen, että loppu lähenee.

Kustaava tuli aivan levottomaksi ja huomautti:

— Mutta vielähän sinä eilenkin uskoit paranevasi.

— En minä ole enää pitkään aikaan uskonut, vaikka olen niin


sanonut, ettet hyvin hätäilisi, tunnusti Heta rauhallisesti.
— Tietääkö sen isäntä? kysyi Kustaava.

— Mitä se sillä tiedolla tekee.

— Kyllä se sille pitää sanoa, että menee viimeinkin noutamaan


rohtoja. Onhan se aivan hänen syynsä, jos sinä kuolet sen tautta,
ettei ole rohtoja.

— Ei ruveta ketään syyttelemään, kielteli sairas.

— Ollaan hätäilemättä tämä loppukin aika. Minun kuolemaani ei


ole kukaan syrjäinen syyllinen, vaan ehkä minä itse.

— Eihän oma mies ole syrjäinen, väitti Kustaava.

— Kyllä sen täytyy hakea rohtoja, vaikka menköön viimeiset


pennit, mutta eihän siltä menekään.

— Ei pakoteta, sillä syrjäinen se on ja joutaa olla syrjäisenä


loppuun asti.

— Mitä sinä nyt puhut, ihmetteli Kustaava. — Hourailuahan tuo on.

— En minä houraile, vakuutti sairas. — Minulla on selvempi


ymmärrys kuin milloinkaan ennen. Jos olisin ennen ollut näin selvällä
ymmärryksellä, niin minulla olisi mies, joka sairaana ollessani istuisi
tässä luonani eikä ainakaan sunnuntaina juoksentelisi tuohien
kiskonnassa.

— Tuohien kiskontaanko isäntä sanoi menevänsä? kysyi Kustaava.

— Niin. Ei kuulunut arkipäivinä joutavan. Olisi vienyt Veertinkin,


mutta heittihän, kun sanoin, ettei toki opettaisi lastansa noin julki
jumalattomaksi.
Kustaava ei tahtonut puhua pahaa isännän ahkeruudesta.

— Tokkopa tuo sunnuntaipäivänä kovin paljon kiskonee, hän


sanoi. — Se minusta on pahempi, kun ei raski ostaa rohtoja. Se ei
usko sinun kuolevan tähän tautiin: Kyllä se muuten rakastaa sinua,
ja kyllä sinäkin rakastaisit häntä, jos se ymmärtäisi ja tietäisi olla
luonasi. Vai etkö sinä ole rakastanutkaan, kun äsken sanoit, että jos
olisit ymmärtänyt, niin sinulla olisi mies, joka istuisi tässä?

— Niin sanoin ja niin olisi, myönnytti sairas.

— Vai niin, ihmetteli Kustaava. — Oliko se puhe sittenkin totta,


että sinä pidit Kurkisen Simosta?

— Saatanhan minä tuon nyt jo sinulle sanoa: totta se oli, hänestä


minä pidin.

— Sepä kummallista, ihmetteli Kustaava uudestaan. — Kaikki


ihmiset sanoivat silloin, että sinä hylkäsit Simon.

— En minä hylännyt, sanoi sairas. — Mutta minkä minä taisin, kun


Simo takertui Agaattaan.

— Siinä on varmaan tullut Simolle suora erehdys, päätti Kustaava.

— En tiedä, mikä lienee tullutkaan, mutta niin se päättyi, ja totta


oli niin päättyväkin, sanoi sairas huokaisten raskaasti.

— Niin on ollut, myönnytti Kustaava. — Ja kyllähän Kaspo on


kunnollinen mies. Tuskinpa Simo olisi osannut niinkään hyvästi
hoitaa taloa. Sanovat, että se ryyppäisikin, jos olisi varoja. Mutta
eihän Kaspo isäntä osta milloinkaan viinaa.
— Onhan siinä hyvääkin, myönnytti Heta ja kysyi: — Ottaisitko
sinä
Kaspon mieheksesi?

Kustaava aivan ällistyi.

— Minäkö? Mitä sinä nyt. Mikä otettava se on.

— Kyllä se on jo ensi kesänä, vahvisti sairas.

— Vaikka olisikin, sanoi toinen — niin mitä sinä mainitsetkaan


minusta, köyhästä akasta.

— Älä pahastu, pyyteli sairas. — En minä sano tätä leikillä enkä


kadehtien. Toivoisin vain, että lapseni saisivat sellaisen äitipuolen
kuin sinä olet.

Tämä oli kovin suuri luottamuksen osoitus Kustaavalle, ja häneltä


pääsi itku. Jos hän oli ennenkin pitänyt tästä asuntotalonsa
emännästä, niin nyt hän olisi tehnyt vaikka mitä sen mieliksi. Hän ei
osannut pitkään aikaan vastata mitään, itki vain ja siveli sairaan
jalkoja.

— Etkö tahtoisi olla minun lapsillani äitipuolena? kysyi sairas. —


Älä kysele tuollaista, kielteli Kustaava. —

Arvannethan tuon kysymättäkin, että mielelläni minä olisin ja


tekisin, mitä sinä vain toivot. Mutta jos sanotaan suoraan, niin Kaspo
on siksi rakas rahaan, että se etsii vaikka mistä asti sellaisen, jolla on
perintöä.

— Niin taitaa olla, myönnytti sairas huoahtaen. — Mutta lupaa


kumminkin minulle, että asut tässä niin kauvan, kuin vähänkin voit.
— Sen minä lupaan, sanoi Kustaava. — Mutta jos Kaspo käskee,
niin silloin minun täytyy muuttaa toiseen paikkaan.

— Älä muuta ensi käskylläkään, neuvoi Heta. — Minä puhun vielä


ennen kuolemaani Veertille, että sekin pitää sinun puoltasi ja
houkuttelee isäänsä.

Sairas oli tullut puhuneeksi niin paljon ja kiihkeästi, että sitä


seurasi kova rykimispuuska. Hiki valui suorastaan otsalta. Kustaava
auttoi syrjälleen kääntyessä ja pyyhki hikeä otsalta. Sitä tehdessä
kuohahti hänessä harmi niitä kohtaan, joita piti syyllisinä Hetan
sairauteen. Hän oli tähän asti uskonut, että ehkä on Kaspossa ollut
jotain miellyttävää, koska Heta on sen ottanut. Mutta kun hän nyt oli
kuullut, miten tuo asia oli tapahtunut, niin hyvät luulot loppuivat ja
hän sanoi:

— Kyllä minä vielä väitän, että sinä raukka kuolet tuon Kaspon
saituruuden tautta. Sitä hullua piti työmiehenä, ettei tarvitsisi
maksaa palkkaa, mutta kallis työmies siitä sittenkin tuli. Siitä
kivenheitostahan tämä tauti sai alkunsa.

— Sallittu se oli, huomautti sairas. — Ei se olisi heittänyt, jos


ymmärsin kohdella taitavammin.

— Ettäkö ei olisi saanut lyödä sitä viuluntekelettä kappaleiksi?

— Niin, ja vielä siinä oli sen edellä yksi asia, jota en ole sanonut
kellekään.

— Niinkö. Mikä se oli? uteli Kustaava.

— Ei se ole tarpeellinen tietää.


— Eikö? Vaan minäpä arvaan, sanoi Kustaava: — Parta-Jaakko oli
suuttunut sinuun minun tauttani, koska et sanonut silloin etkä sano
nytkään.

— Ei sinun tauttasi, vakuutti Heta.

— Aivan varmaan, vakuutti Kustaava huolestuneena. — Et sinä sitä


muuten salaisi. Mutta miksi se ei heittänyt minua sillä kivellä? Minä
olisin paljon paremmin joutanut kuolemaan.

— Entäs lapsesi? sanoi sairas.

— Herra on orpojen isä.

— Niin on minunkin lasteni, huokasi sairas. — Mutta ettet tyhjää


arvaileisi etkä huolehtisi, niin sanon senkin toisen asian: Parta-
Jaakko suuttui minuun siitä, kun nostin sinun poikasi hänen
tekemäänsä uuteen kätkyeeseen.

Kustaavan silmistä välähti viha Parta-Jaakkoa kohtaan, mutta se


meni pian ohitse, ja hän alkoi haikeasti valittaa, että hänen ja hänen
lapsensa piti olla syyllinen Hetan ennenaikaiseen kuolemaan.

— Älä voivottele suotta, sanoi Heta. — Ei se ole sinun syysi, eikä


voivotellen parane.

— Ei parane, ei parane, mutta kyllä tuo koskee, kun hyvästä


teostasi sait tuollaisen palkan. Millä minä sen sovitan?

— Jo se on sovitettu, lohdutteli sairas. — Ja jos tahdot vielä


sovittaa, niin hoidahan lapsiani, varsinkin nuorinta.
Kustaavalle oli tullut niin ikävä mieli, ettei jaksanut paljon
puhuakaan. Ja osoittaakseen, että hänellä on halu täyttää sairaan
pyyntö, lähti hän taas katsomaan kiven luona leikkiviä lapsia.
Mennessään hän jo kuuli oman poikansa kimakan itkun. Se oli
kaatunut kiveen ja loukannut otsansa, jota Veerti parhaillaan
hatullaan paineli. Siihen liittoon joutui Kustaavakin, ja kun Veerti
huomasi tämän huolestuneet kasvot, alkoi hän lohdutella, ettei
otsaan tullut verihaavaa.

— Mitäpä siitä, jos olisi tullutkin, sanoi Kustaava ottaen lapsen


syliinsä. — Taluta sinä veljeäsi, niin mennään lähemmäksi pihaa,
ettei äitisi tarvitse niin paljon huolehtia.

— Onko äiti nyt kipeämpi? kysyi Veerti katsoen Kustaavan silmiin.

— Ei ole tavallista kipeämpi, vastasi Kustaava odotellen, että Veerti


alkaisi taluttaa veljeänsä.

Mutta tällä oli huolenaan viulu, joka oli jäänyt huonoon


korjuuseen, ja hän koetti viihdytellä veljeänsä jäämään jälemmäksi,
että voisi Kustaavan huomaamatta käydä pistämässä varmempaan
piiloon. Kustaava ymmärsi asian ja sanoi:

— Käy vain korjaamassa talteen viulusi, en minä puhu siitä


kellekään.

Veertiä näytti hävettävän, kun kuuli, ettei se ollutkaan enää


salaisuus. Hän kävi kiireesti kätkemässä viulunsa ison kiven alle ja
palattuaan veljeään taluttamaan varmemmaksi vakuudeksi pyyteli:

— Älkäähän, hyvä Kustaava, sanoko äidille.


VII.

Kivimäen Heta kuoli kohta sen jälkeen, kun hän oli uskonut
salaisuutensa ja toivomuksensa Kustaavalle. Yhä suuremmalla
valppaudella Kustaava jatkoikin vainajan poikien vaalimista ja teki
muutakin työtä, niin paljon kuin jaksoi ja kerkesi. Moni syrjäinen
alkoi uskoa, että kiihoittimena tähän oli toivo päästä emännäksi.

Lipposen Annastiinakin tuli nyt entistä palvelustoveriansa


tervehtimään. Kustaava ei hänen tulostaan ihastunut, sillä hän
aavisti siitä seuraavan ikävyyksiä. Kun Kaspo oli epäillyt omaakin
vaimoaan, että se jakeli talon ruokavaroja kylän köyhille, niin
tottahan ventovieras joutui vielä enemmän epäilyksen alaiseksi.

Annastiina ei alkupuheista päättäen näyttänyt olevan oman voiton


pyynnöstä matkalla. Hän vain hymyili merkitsevästi Kustaavalle ja,
saatuaan kahdenkeskisen tilaisuuden, alkoi kiitellä:

— Sinulle on nyt taas onni tarjona, kun vain et anna luisua läpi
käsien.

— Onpa tämä hyväkin onni, sanoi Kustaava välinpitämättömästi.


— En ole ikipäivinä tarvinnut näin aamusta iltaan ahertaa kuin tässä.
— No jaksathan sinä tämän vähän ajan, puolen vuotta, aivan
valittelematta, lohdutteli Annastiina.

— Mikä helppo se sitten puolen vuoden perästä tulee? kysyi


Kustaava.

Annastiina tuuppasi Kustaavaa olkapäähän ja silmää iskien


supakalta soplatti:

— Katsos tätä, kun ei ole ymmärtävinään. Puolen vuoden


kuluttuahan miehet saavat ottaa toisen emännän.

— Ottakoon vain vaikka vähän ennenkin, sanoi Kustaava ääntänsä


alentamatta. — Tämän viran luovuttaa mielellään milloin hyvänsä.

— Älä sinä puhu leikilläsikään tuolla tavalla, supatti Annastiina. —


Hyvä tässä, velattomassa talossa, on olla emäntänä.

— Eivätpä tuon Heta vainajankaan päivät kovin kadehdittavilta


näyttäneet, sanoi Kustaava.

— Mitä tuosta Hetasta, virkkoi Annastiina halveksien. — Isältä


peritty koti ihmisellä ja sittenkin totteli Kaspoa niin, ettei keittänyt
kahviakaan kuin suurimpina juhlina.

— Mistäpä keittänee, jos ei isäntä tuo, sanoi Kustaava antaen


huomata, ettei ole nytkään kahvin toivoa.

— Sen nyt tietää, ettei Kaspo tuo, jos ei itse hanki. Mutta luulisi
tuon sinulle tuovan, kun tietää, että olet emäntänä ollessasi juonut
joka päivä.
— Missä pakossa se minua herkuttelisi enemmän kuin omaa
emäntäänsä. Ja hyvin näkyy tulevan toimeen ilmankin.

— No, eihän sinun auta siitä valittaminen, myönteli Annastiina. —


Mutta älä toki rapea riekkumaan yksinäsi kaikkia töitä ja olemaan
kahvitta, jos pääset tähän emännäksi.

Kustaava kiivastui.

— Mitenkä minä tähän pääsen, sillä jos isäntä ottaakin toisen


vaimon, niin ei se näin köyhää ota, ei vaikka…

— Älä puhu sillä lailla kellekään muille, sohisi Annastiina, — Sano


Hyttis-vainajan antaneen muiden tietämättä muutamia satoja, jotka
ovat velkana, niin ei Kaspo mene edempää etsimään.

Kustaavan täytyi nauraa, vaikka harmittikin.

— Ettäkö minä rupeaisin valehtelemaan. Ja uskoisiko sitä kukaan,


saati sitten Kaspo Haverinen.

— Annetaan asian kuulua muualta päin, niin kyllä uskoo, sanoi


Annastiina salaperäisesti. Ja iskien silmää hän lisäsi: — Sellainen
puhe on jo kiertämässä, ja arvannethan, kuka sen on alkanut.

Kustaava katsoi ihmetellen ja kysyi:

— Mutta arvaako Annastiina, mikä elämä siitä sitten seuraisi, kun


ei rahoja löytyisikään?

— Vieläpä siitä mikä. Ei sen tautta vihkimistä pureta. Sanot vain,


että ne ovat olleet ja menneet. Ei niiden itarain ukkojen kanssa
pääse eteenpäin, jos ei kaunistele asioita. Eikä sinun itsesi tarvitse
mainitakaan rahoista. Koeta vain saada Kaspo uskomaan, että sinun
ollessasi emäntänä talo rikastuu ihan silmin nähtävästi. Kahvistakin
voit sanoa, että jos tämä terveys pysyy tallella, niin ei keitetä
juhlinakaan. Kyllä sinä sillä keinolla voitat.

Kustaava vain kuunteli. Jos tämä neuvonantaja olisi ollut


luotettavampi ihminen, niin hän olisi tuntenut suurtakin iloa. Mutta
hän aavisti, että tälle hyvän toivojalle pitäisi olla jotain antamista, ja
mitäpä hänellä olisi. Vaatteetkin, ainoa omaisuus, olivat jo
vähentyneet ja kuluneet. Ei ollut hyvä luopua viimeisistään, kun
tarvitsi lapselleenkin. Kustaava toivoi, että Annastiina palaa
tyytyväisenä, kun sitä ystävällisesti puhuttelee.

— Onko isäntä ollut terveenä? hän kysyi tarkoittaen vanhaa


Lipposta.

— Mikä isäntä tuo on, vanha, taloton ruoti-ukko, tokaisi


Annastiina.

— Onhan se ollut isäntä, lohdutteli Kustaava. — Ja niin minä olen


kuullut, että sitä kaikissa taloissa kohdellaan ja hoidetaan kuin talon
vanhusta.

— Jospa hoitanevat, mutta mitäpä hyötyä siitä lienee minulle ja


pojalle.

— No, kyllähän Annastiina yhden lapsen kanssa tulee toimeen.

— Olenhan minä tähän asti tullut, mutta kun ottivat sen ukon
elättääkseen, niin nyt ne ympäristön emännät eivät anna kuin hyvin
toisinaan ja leipäainetta senkin. Nythän minä läksin kiertelemään
näissä laitataloissa, että jokainen osaltaan pistäisi pienenkään
kipenen voita talven varaksi.

"Nyt se on pula edessä", ajatteli Kustaava, mutta ääneen sanoi:

— Antanee nuo toki lehmilliset, ja voisihan tämänkin talon


isännältä kysyä.

— Siltä ei saa silmäänsäkään, jos et sinä anna, sanoi Annastiina.

— Enhän minä uskalla antaa toisen tavarata.

— Tuon verran, naulan tai puoli. Kuka sitä älyää, kun ottaa
viisaasti. Jos sitten kääräiset tuohilevyn sisään ja pistät tuonne
halkopinon päälle, niin ei kukaan huomaa minun saaneen mitään.

— Kyllä minä antaisin mielelläni, jos olisi, selitti Kustaava aivan


kuin anteeksi pyytäen. — Mutta minulla on sellainen luonto, etten voi
liikutella toisen tavarata.

— No, eihän sille sitten voi mitään, myönnytteli Annastiina.

Hänen kasvoistaan ja katseestaan huomasi, että ystävyys on


loppumaisillaan. Hän näki joutavansa pois ja asettaen äänensä
surulliseen sointuun alkoi puhella matkastaan.

— Pitääkin tästä lähteä kiertelemään tuolla Heinälahden mökeissä.


Siellä ovat ennen yksilehmäisetkin pistäneet voikipenen, ja jos ei ole
ollut voita, niin on niillä ollut jotain muuta, mitäpä milläkin. Ne
muistavat vielä, ettei minun kotonani tarvinnut käydä kuivin suin.

Kustaava ymmärsi yskän ja hänelle tuli vaikea olla.


— Jo piti sattua ikävästi, kun ei ollut kahviakaan, hän valitti aivan
vilpittömästi. — Ottaisiko Annastiina, jos hakisin miesvainajaltani
jääneen silkkisen kaulahuivin puoliskon?

— Mitäpä minä silläkään, sanoi Annastiina jurosti ja lähti matkalle.

Kustaava jäi taistelemaan omantuntonsa kanssa. "Olisiko sittenkin


pahasti, kun en antanut voita? Olisihan sen voinut mitata puntarilla
ja kuitata palkasta. Nyt jäi Annastiina pahalle mielelle, ja kuka tietää,
mitä se puhuu. Tuskin hänkään toivoo enää, että pääsisin tähän
emännäksi."
VIII.

Heinäjärven koillisen lahdelman pohjasta alkoivat kyläkunnan laajat


niityt, joiden takana oli muutamia mäkitupia ja torppia.
Heinänkorjuun aikana oli niityllä vilkasta liikettä, mutta muuna
aikana olivat nämä takaliston asukkaat erillään muusta maailmasta.
Sydäntalven aikana ei ollut pienempiin asuntoihin muuta tietä kuin
suksenlatu tai jalkapolku.

Tällaiseen torppaan oli Kustaavakin joutunut asumaan yksin


poikansa kanssa. Talvi oli parhaillaan. Kustaava kehräsi tappuroita, ja
poika Ville lukea jutisti käskyjä aapisestaan. Lukeminen alkoi poikaa
väsyttää, ja hän kysyi:

— Milloinka Olka tulee pois?

— Ei se tulekaan, oli vastaus.

— Minkätähden ei tule?

— No etkö sinä ole vielä päässyt sitä asiaa ymmärtämään? Olkan


isä ja äiti menivät pitkän matkan päähän asumaan, eivätkä ne tule
enää tähän.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

testbankfan.com

You might also like