100% found this document useful (2 votes)
10 views

C++ Programming From Problem Analysis to Program Design 8th Edition Malik Solutions Manual instant download

The document provides information about the solutions manual for the 8th edition of 'C++ Programming: From Problem Analysis to Program Design' by D.S. Malik, including links to download the manual and other related test banks and solution manuals. It outlines the structure of the instructor's manual, which includes teaching tips, objectives, and classroom activities aimed at enhancing the teaching experience. The content covers basic C++ programming concepts, data types, functions, and the importance of documentation in coding.

Uploaded by

tolenjirikey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
10 views

C++ Programming From Problem Analysis to Program Design 8th Edition Malik Solutions Manual instant download

The document provides information about the solutions manual for the 8th edition of 'C++ Programming: From Problem Analysis to Program Design' by D.S. Malik, including links to download the manual and other related test banks and solution manuals. It outlines the structure of the instructor's manual, which includes teaching tips, objectives, and classroom activities aimed at enhancing the teaching experience. The content covers basic C++ programming concepts, data types, functions, and the importance of documentation in coding.

Uploaded by

tolenjirikey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

C++ Programming From Problem Analysis to Program

Design 8th Edition Malik Solutions Manual


download

http://testbankbell.com/product/c-programming-from-problem-
analysis-to-program-design-8th-edition-malik-solutions-manual/

Find test banks or solution manuals at testbankbell.com today!


We have selected some products that you may be interested in
Click the link to download now or visit testbankbell.com
for more options!.

Solution manual for C++ Programming: From Problem Analysis


to Program Design, 6th Edition – D.S. Malik

http://testbankbell.com/product/solution-manual-for-c-programming-
from-problem-analysis-to-program-design-6th-edition-d-s-malik/

Test Bank for C++ Programming: From Problem Analysis to


Program Design, 6th Edition – D.S. Malik

http://testbankbell.com/product/test-bank-for-c-programming-from-
problem-analysis-to-program-design-6th-edition-d-s-malik/

Solution Manual for C# Programming: From Problem Analysis


to Program Design, 5th Edition, Barbara Doyle

http://testbankbell.com/product/solution-manual-for-c-programming-
from-problem-analysis-to-program-design-5th-edition-barbara-doyle/

Solution Manual for Marketing Management, 15th Edition


Philip T Kotler Kevin Lane Keller

http://testbankbell.com/product/solution-manual-for-marketing-
management-15th-edition-philip-t-kotler-kevin-lane-keller/
Strategic Management Concepts Competitiveness and
Globalization Hitt 11th Edition Solutions Manual

http://testbankbell.com/product/strategic-management-concepts-
competitiveness-and-globalization-hitt-11th-edition-solutions-manual/

Test Bank for Principles of Risk Management and Insurance,


12/E 12th Edition George E. Rejda, Michael McNamara

http://testbankbell.com/product/test-bank-for-principles-of-risk-
management-and-insurance-12-e-12th-edition-george-e-rejda-michael-
mcnamara/

Test Bank for Close Relations An Introduction to the


Sociology of Families, 4th Canadian Edition: McDaniel

http://testbankbell.com/product/test-bank-for-close-relations-an-
introduction-to-the-sociology-of-families-4th-canadian-edition-
mcdaniel/

Test Bank for Learning and Behavior Active Learning 6th


Edition by Chance

http://testbankbell.com/product/test-bank-for-learning-and-behavior-
active-learning-6th-edition-by-chance/

Test Bank for Financial Accounting Theory and Analysis:


Text and Cases, 11th Edition, Richard G. Schroeder, Myrtle
W. Clark, Jack M. Cathey
http://testbankbell.com/product/test-bank-for-financial-accounting-
theory-and-analysis-text-and-cases-11th-edition-richard-g-schroeder-
myrtle-w-clark-jack-m-cathey/
Test Bank for Personal Nutrition, 9th Edition

http://testbankbell.com/product/test-bank-for-personal-nutrition-9th-
edition/
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-1

C++ Programming From Problem


Analysis to Program Design 8th Edition
Malik Solutions Manual
Full download chapter at: https://testbankbell.com/product/c-programming-from-
problem-analysis-to-program-design-8th-edition-malik-solutions-manual/

Chapter 2
Basic Elements of C++
A Guide to this Instructor’s Manual:

We have designed this Instructor’s Manual to supplement and enhance your teaching
experience through classroom activities and a cohesive chapter summary.

This document is organized chronologically, using the same headings that you see in the
textbook. Under the headings, you will find lecture notes that summarize the section, Teacher
Tips, Classroom Activities, and Lab Activities. Pay special attention to teaching tips and
activities geared towards quizzing your students and enhancing their critical thinking skills.

In addition to this Instructor’s Manual, our Instructor’s Resources also contain PowerPoint
Presentations, Test Banks, and other supplements to aid in your teaching experience.

At a Glance

Instructor’s Manual Table of Contents


• Overview

• Objectives

• Teaching Tips

• Quick Quizzes

• Class Discussion Topics

• Additional Projects

• Additional Resources

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-2
• Key Terms

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-3

Lecture Notes

Overview
Chapter 2 teaches your students the basics of C++. Learning a programming language is
similar to learning to be a chef or learning to play a musical instrument. All three
require direct interaction with the tools; in other words, you cannot become proficient
by simply reading books on the topics. In this chapter, your students will begin
acquiring a fundamental knowledge of C++ by learning about data types, functions,
identifiers, assignment statements, arithmetic operations, and input/output operations.
They will then write and test programs using these concepts to verify their knowledge
of the material.

Objectives
In this chapter, the student will:
• Become familiar with the basic components of a C++ program, including functions,
special symbols, and identifiers
• Explore simple data types
• Discover how to use arithmetic operators
• Examine how a program evaluates arithmetic expressions
• Become familiar with the string data type
• Learn what an assignment statement is and what it does
• Learn about variable declaration
• Discover how to input data into memory using input statements
• Become familiar with the use of increment and decrement operators
• Examine ways to output results using output statements
• Learn how to use preprocessor directives and why they are necessary
• Learn how to debug syntax errors
• Explore how to properly structure a program, including using comments to document a
program
• Become familiar with compound statements
• Learn how to write a C++ program

Teaching Tips
Introduction
1. Define the terms computer program and programming.

2. Use the recipe analogy to give students an idea of the process of programming.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-4

A Quick Look at a C++ Program

1. Note that every C++ program must have a function called main. Use Example 2-1 to
illustrate a basic main function. Walk through this example and point out the meaning
of each line.

2. Discuss the purpose of an output statement and what it produces.

3. Point out the use of comments.

4. Briefly introduce the #include directive.

5. Use Figure 2-1 to describe the various parts of a C++ program.

Teaching Reassure students that although most of this example probably looks confusing,
Tip they will soon understand it and be comfortable with it.

6. Use Figures 2-2 and 2-3 to describe how memory is allocated and used to store values.

The Basics of a C++ Program


1. Explain that a C++ program is essentially a collection of one or more subprograms,
called functions. Note that although many functions are predefined in the C++ library,
programmers must learn how to write their own functions to accomplish specific tasks.

2. Define the terms syntax rules and semantic rules as they relate to a programming
language and explain the difference between the two.

Teaching Emphasize that compilers check for syntax but not semantic errors. Give an
Tip example of each type of error.

Comments

1. Use the program in Example 2-1 to describe the use and importance of comments.
Stress that comments are for the reader, not for the compiler.

2. Describe the two forms of comments shown in the textbook.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-5

The importance of documenting a program cannot be underestimated. It is highly


Teaching
important for ensuring that the next programmer to be responsible for
Tip
maintaining the code will be able to understand what the code is supposed to do.

Special Symbols

1. Explain that the C++ programming language consists of individual units called tokens,
and these are divided into special symbols, word symbols, and identifiers.

2. Go over some of the special symbols in C++, including mathematical symbols,


punctuation marks, the blank symbol, and double characters that are regarded as a
single symbol.

Reserved Words (Keywords)

1. Discuss the word symbols, or keywords, used in C++, using Appendix A as a guide.
Emphasize that C++ keywords are reserved and cannot be redefined for any other
purpose with a program.

Identifiers

1. Define the term identifier as a name for something, such as a variable, constant, or
function.

2. Discuss the rules for naming identifiers in C++. Also note that C++ is a case-sensitive
language.

3. Use Table 2-1 to review the rules of identifier naming.

Discuss the difference between C++ conventions and rules. For example, it is a
Teaching
rule that a mathematical symbol cannot be used in an identifier name. However,
Tip
it is a convention to begin an identifier with a lowercase letter.

Whitespaces

1. Explain that whitespaces (which include blanks, tabs, and newline characters) are used
to separate special symbols, reserved words, and identifiers.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-6

Data Types
1. Explain that C++ categorizes data into different types in order to manipulate the data in
a program correctly. Although it may seem cumbersome at first to be so type-conscious,
emphasize that C++ has these built-in checks to guard against errors.

Explain that C++ is called a strongly typed language because it checks for
Teaching operations between inconsistent data types. This results in more robust and error-
Tip free programs. Demonstrate how C++ checks for data types with a simple
program that attempts to add a string and a numeric value.

2. Define the term data type as a set of values together with a set of operations.

3. Mention that C++ data types fall into three categories: simple data types, structured data
types, and pointers. Only the first type is discussed in this chapter.

Simple Data Types

1. Describe the three categories of simple data types in C++: integral, floating-point, and
enumeration.

2. Mention the eleven categories of integral data types. Explain why C++ (and many other
languages) has so many categories of the same data type. In addition, discuss the rules
involving the use of integral types.

4. Explain the purpose of the bool data type.

5. Discuss the char data type, including its primary uses. Mention commonly used ASCII
characters and their predefined ordering. Explain that a char data type is enclosed in
single quotation marks, and note that only one symbol may be designated as a character.

6. Use Table 2-2 to summarize the three simple data types. Point out the difference in the
amount of memory storage required, but inform students that this is system-dependent.

Floating-Point Data Types

1. Use Table 2-3 to explain how C++ represents real, or floating-point, numbers. Mention
the three categories of data types to represent real numbers (float, double, and
long double), and explain when to use each type.

2. Define the terms precision, single precision, and double precision.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-7

Demonstrate how to find the values of float and double on a particular


Teaching system by running the program with the header file <cfloat> in Appendix F.
Tip Encourage students to try running this program on their own computers and
comparing the results.

Quick Quiz 1
1. What is an enumeration type?
Answer: C++’s method for allowing programmers to create their own simple data types

2. The maximum number of significant digits in a number is called the


.
Answer: precision
3. The data type has only two values: true and false.
Answer: bool

4. The data type, the smallest integral data type, is used to


represent characters.
Answer: char

Data Types and Variables, and Assignment Statements


1. Explain that the declaration of a variable requires that the data type be specified.

2. Explain the concept and syntax of an assignment.

Arithmetic Operators, Operator Precedence, and Expressions


1. Discuss the five arithmetic operators in C++ that are used to manipulate integral and
floating-type data types.

2. Define the terms unary and binary operators, and discuss the difference between them.

Order of Precedence

1. Review operator precedence rules, as C++ uses these rules when evaluating
expressions. Explain that parentheses can be used to override the order of operator
precedence.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-8

Expressions

1. This section discusses integral and floating-point expressions in detail.

2. Describe the three types of arithmetic expressions in C++.

3. Use Examples 2-6 and 2-7 to clarify how C++ processes expressions.

Mixed Expressions

1. Discuss the two rules for evaluating mixed expressions and illustrate these rules in
practice using Example 2-8.

Quick Quiz 2
1. A(n) operator has only one operand.
Answer: unary

2. You can use to override the order of precedence rules.


Answer: parentheses

3. Describe the associativity of arithmetic operators.


Answer: Unless there are parentheses, the associativity of arithmetic operators is said to
be from left to right.

4. An expression that has operands of different data types is called a(n)


.
Answer: mixed expression

Type Conversion (Casting)


1. Explain how C++ avoids the hazards that result from implicit type coercion, which
occurs when one data type is automatically changed into another data type.

2. Illustrate the form of the C++ cast operator using Example 2-9.

Students may feel a bit overwhelmed after the discussion of the static_cast
operator. Ask them to run the program from Example 2.9. They should
Teaching
experiment with removing the static_cast operator from various statements,
Tip
as well as changing the variable values. Ask them to report on any unpredictable
results.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-9

string Type

1. Introduce the C++ data type string, which is a programmer-defined data type
available in the C++ library. Define a string as a sequence of zero or more characters.

2. Define the terms null string or empty string.

3. Discuss how to determine the length of a string, as well as the position of each character
in a string.

Teaching Emphasize that the first position of a character in a string is 0, not 1. This will be
Tip helpful when manipulating both strings and arrays later on the text.

Variables, Assignment Statements, and Input Statements


1. Explain that data for a C++ program must be input into main memory. Mention the two-
step process to store data in the computer’s memory.

Allocating Memory with Constants and Variables

1. Emphasize that when allocating memory, the programmer must instruct the computer
which names to use for each memory location as well as what type of data to store in
those memory locations.

2. Define the term named constant and describe the syntax for declaring a named constant.
Use Example 2-11 to illustrate the naming conventions for named constants. Explain
why named constants are used in programs.

3. Define the term variable and use Example 2-12 to illustrate the syntax for declaring
single and multiple variables.

4. Give a formal definition of a simple data type.

Putting Data into Variables

1. Mention the two ways you can place data in a variable in C++.

Assignment Statement

1. Discuss the C++ assignment statement, including its syntax, variable initialization, and
the associativity rules of the assignment operator.

2. Step through Example 2-13 to illustrate how assignment statements operate in C++.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-
10
3. Use Example 2-14 to discuss the importance of doing a walk-through (tracing values
through a sequence of steps) when writing code.

Teaching Building a table showing the values of variables at each step of the program is
Tip very helpful for students to understand the nature of variables.

Saving and Using the Value of an Expression

1. Explain the steps involved in saving the value of an expression using Example 2-15.

Declaring and Initializing Variables

1. Explain that when a variable is declared, C++ may not automatically put a meaningful
value in it.

2. Emphasize that it is a good practice to initialize variables while they are being declared.
Use one or more examples to illustrate how to do this in C++.

Input (Read) Statement

1. This section teaches your students to read data into variables from a standard input
device. Define and explain the use of the C++ object cin and the stream extraction
operator >>.

2. Step through Examples 2-16 through 2-18 to illustrate how to read in numeric and string
data.

Variable Initialization

1. Reiterate that a variable can be initialized either through an assignment statement or a


read statement. Explain why the read statement option is more versatile. Use Example
2-19 to illustrate both types of initialization.

Programmers (and instructors) have various approaches or preferences regarding


variable declaration and initialization. Share your views on the topic. Do you
Teaching
think the best approach is to always initialize variables for consistency? Do you
Tip
prefer initializing variables directly before the block of code that uses them, or
initializing them during declaration?

Quick Quiz 3
1. What is a named constant?

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Visit https://testbankbell.com
now to explore a rich
collection of testbank,
solution manual and enjoy
exciting offers!
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-10

Answer: A memory location whose content is not allowed to change during program
execution

2. What is the syntax for declaring single or multiple variables?


Answer: dataType identifier, identifier, …;

3. True or False: If you refer to an identifier without declaring it, the compiler will
generate an error message.
Answer: True

4. A variable is said to be _ the first time a value is placed in it.


Answer: initialized

Increment and Decrement Operators

1. Explain the purpose of the C++ increment (++) and decrement (--) operators.

2. Discuss how pre and post versions of these operators affect the results in a program.
Use Example 2-20 to help explain the difference between these versions.

Verify that students are comfortable with using pre- and post-
Teaching
increment/decrement operators correctly, as it will be useful when working with
Tip
control structures.

Output

1. Review how the C++ output statement is coded with the cout object and stream
insertion operator (<<). Review the role of the endl manipulator in output statements
as well.

2. Discuss the use of escape characters (see Table 2-4), such as the newline character, to
format output. Demonstrate how to format output with Examples 2-21 through 2-26.

Outputting strings can be confusing at first. Talk about the various methods to
Teaching deal with several lines of string output, and give your opinion as to the best
Tip approach. Emphasize that the Enter key cannot be used to break up a long string
into two lines.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-11

Preprocessor Directives
1. Explain the role of the preprocessor in C++. Discuss the use of header files and the
syntax for including them in a C++ program.

Teaching Show your students some of the available operations in the <cmath> header.
Tip Here is one Web site with a description:
http://www.cplusplus.com/reference/cmath/

namespace and Using cin and cout in a Program

1. Briefly explain the purpose of the namespace mechanism in ANSI/ISO Standard


C++. Discuss the std namespace and how it relates to the <iostream> header
file.

2. Review the using namespace std; statement and its usefulness in programs
using cin and cout statements.

Using the string Data Type in a Program

1. Mention that the <string> header must be included in C++ programs using the
string data type.

Creating a C++ Program

1. Discuss the role of the function main in a C++ program. Go over the syntax of a main
function, including declaration, assignment, executable, and return statements. Mention
that named constant definitions and preprocessor directives are written before the main
function.

2. Spend some time stepping through Examples 2-27 through 2-29. Verify that students
understand each line of code in Example 2-29.

Debugging: Understanding and Fixing Syntax Errors


1. Review the sample program on page 84 and the compiler output that is generated when
compiling the program. Walk through the various syntax errors and explain how each
one should be fixed. Note that a syntax error on one line may be the cause of a compiler
error on the following line.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-12

Debugging is one of the most important skills a professional programmer


Teaching
acquires. Stress to students the importance of learning how to debug their own
Tip
programs, including the verification of the results.

Program Style and Form


1. This section covers basic C++ syntax and semantic rules. Review these rules with your
students in order for them to feel comfortable writing a complete functioning C++
program.

Syntax

1. Remind students that syntax rules define what is legal and what is not.

2. Discuss some common syntax errors. Emphasize that syntax errors should be corrected
in the order in which the compiler lists them.

Use of Blanks

1. Discuss when blanks should and should not be used in a C++ program.

Use of Semicolons, Brackets, and Commas

1. Explain the purpose and meaning of semicolons, brackets, and commas in C++
programs. Define the term statement terminator.

Semantics

1. Define the term semantics.

2. Reiterate that a program may run without compiler errors and still have semantic errors
that generate incorrect results. Use the example in the text to illustrate.

Naming Identifiers

1. Mention the conventions for naming identifiers, including self-documenting identifiers


and run-together words.

Prompt Lines

1. Define the term prompt lines.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-13

2. Explain why well-written prompt lines are essential for user input.

Documentation

1. Discuss why documenting a program through comments is critical to understanding and


modifying the program at a later time.

Form and Style

1. Explain the purpose behind formatting and indentation conventions in source code. Use
Example 2-30 to illustrate.

As with naming conventions, discuss your own preferences in terms of form and
Teaching style in programming. Use the programming examples at the end of the chapter
Tip to talk about various stylistic elements. Discuss the value of the “art” of
programming.

Quick Quiz 4
1. True or False: The semantic rules of a language tell you what is legal and what is not
legal.
Answer: False

2. The semicolon is also called the .


Answer: statement terminator

3. How can you make run-together words easier to understand?


Answer: Capitalizing the beginning of each new word; or inserting an underscore before
each new word

4. Why are comments important in a program?


Answer: A well-documented program is easier to understand and modify, even a long
time after you originally wrote it. You use comments to document programs. Comments
should appear in a program to explain the purpose of the program, identify who wrote
it, and explain the purpose of particular statements.

More on Assignment Statements


1. Define the terms simple assignment statement and compound assignment statement.

2. Define the C++ compound operators (+=, -=, *=, /=, and %=) and explain how and
why compound assignment statements are used in C++ programs. Use Example 2-31 to
illustrate this.

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-14

3. Step through the “Convert Length” and “Make Change” Programming Examples to
help the students consolidate all the information from this chapter.

Class Discussion Topics


1. As mentioned in this chapter, C++ predefined identifiers such as cout and cin can be
redefined by the programmer. However, why is it not wise to do so?

2. The text mentioned that the char data type can be cast into an int. What are some
possible uses of this functionality?

Additional Projects
1. Learn and report on various compiler errors by modifying one or two of the programs in
this chapter. Try to compile the program. What happens when you fail to initialize a
value for a named constant? What are the error messages when you use a numeric or
string constant in an expression without first giving it a value? Finally, what happens
when you initialize a char data type with a character enclosed in double quotes?

2. Use one of the programs in this chapter to test for invalid user input. The program
should compile with no errors. What happens when you enter an unexpected value
(such as an incorrect data type) when prompted for user input? Test with several sets of
invalid data and document your findings.

Additional Resources
1. C++ Examples:
https://developers.google.com/edu/c++/getting-started

2. Basic Input/Output:
http://www.cplusplus.com/doc/tutorial/basic_io/

3. C++ Programming Style Guidelines:


http://geosoft.no/development/cppstyle.html

4. Strong vs. Weak Typing:


http://www.artima.com/intv/strongweak.html

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-15

Key Terms
Arithmetic expression: an expression constructed using arithmetic operators and
numbers
Assignment operator: =; assigns whatever is on the right side to the variable on the left
side
Associativity: the associativity of arithmetic operators is said to be from left to right
Binary operator: an operator that has two operands
Cast operator (type conversion, type casting): used to explicitly convert one data type
to another data type
Character arithmetic: arithmetic operation on char data
Collating sequence: a predefined ordering for the characters in a set
Compound assignment statement: statements that are used to write simple assignment
statements in a more concise notation
Computer program: a sequence of statements whose objective is to accomplish a task
Data type: a set of values together with a set of operations
Declaration statements: statements that are used to declare things, such as variables
Decrement operator: --; decreases the value of a variable by 1
Double precision: values of type double
Enumeration: a user-defined data type
Executable statements: statements that perform calculations, manipulate data, create
output, accept input, and so on
Floating-point: a data type that deals with decimal numbers
Floating-point (decimal) expression: an expression in which all operands in the
expression are floating-point numbers
Floating-point notation: a form of scientific notation used to represent real numbers
Function (subprogram): a collection of statements; when activated, or executed, it
accomplishes something
Identifier: a C++ identifier consists of letters, digits, and the underscore character (_); it
must begin with a letter or underscore
Implicit type coercion: when a value of one data type is automatically changed to
another data type
Increment operator: ++; increases the value of a variable by 1
Initialized: the first time a value is placed in the variable
Input (read) statement: a statement that places data into variables using cin and >>
Integral: a data type that deals with integers, or numbers, without a decimal part
Integral expression: an expression in which all operands are integers
Keyword: a reserved word
Mixed expression: an expression that has operands of different data types
Named constant: a memory location whose content is not allowed to change during
program execution
Null (empty) string: a string containing no characters
Operands: numbers appearing in an arithmetic expression
Output statement: an output on the standard output device via cout and <<

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 2-16

Post-decrement: has the syntax variable--


Post-increment: has the syntax variable++
Precision: the maximum number of significant digits
Pre-decrement: has the syntax –-variable
Predefined (standard) function: a function that is already written and provided as part
of the system
Pre-increment: has the syntax ++variable
Preprocessor: a program that carries out preprocessor directives
Programming: the process of planning and creating a program
Programming language: a set of rules, symbols, and special words
Prompt lines: executable statements that inform the user what to do
Reserved words (keywords): word symbols in a programming language that cannot be
redefined in any program
Run-together word: an identifier that is composed of two or more words that are
combined without caps or underscores
Self-documenting identifiers: identifiers that describe the purpose of the identifier
through the name
Semantic rules: rules that determine the meaning of the instructions
Semantics: a set of rules that gives meaning to a language
Simple assignment statement: a statement that uses only the assignment operator to
assign values to the variable on the left side of the operator
Simple data type: the variable or named constant of that type can store only one value
at a time
Single precision: values of type float
Source code: consists of the preprocessor directives and program statements
Source code file (source file): a file containing source code
Statement terminator: the semicolon
Stream extraction operator: >>; takes information from a stream and puts it into a
variable
Stream insertion operator: <<; takes information from a variable and puts it into a
stream
String: a sequence of zero or more characters
Syntax rules: rules that describe which statements (instructions) are legal, or accepted
by the programming language, and which are not legal
Token: the smallest individual unit of a program written in any language
Unary operator: an operator that has only one operand
Variable: a memory location whose content may change during program execution
Walk-through: the process of tracing values through a sequence

© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Chapter 2
1. a. false; b. false; c. true; d. true; e. false; f. false; g. true; h. true; i. false; j. false; k. true; l. false
2. b, d, e, f
3. b, e
4. A keyword is a reserved word and is defined by the system. A keyword cannot be redefined in a
program. A user-defined identifier can be redefined.
5. The identifiers quizNo1 and quizno1 are not the same. C++ is case sensitive. The fifth letter of
quizNo1 is uppercase N while the fifth character of quizno1 is lowercase n. So these identifiers
are different
6 . a. 22
b. 2
c. 14
d. 8
e. 7.00
f. 21
g. 20
h. 0.00
i. 15.50

7. a. 7
b. 5.50
c. -1.00
d. Not possible. Both the operands of the operator % must be integers. y + z is of type double. Both
operands, y + z and x, of %V must be integers.
e. 13.50
f. 1
g. Not possible. Both the operands of the operator % must be integers. Because the second operand, z,
is a floating-point value, the expression is invalid.
h. 3.00

8. a, b, c, e, i, j, and k are valid;


d, f, and g are invalid because the left side of an expression must be a variable. h is invalid because the
operands of the mod operator must be integers.
9. x = 9, y = 5, z = 3, w = -3
10. Variable declarations in Lines 1, 6, and 7 are correct.
Variable declaration in Line 2 is incorrect. Now, B+ is a string, so it must be enclosed in double
quotes mark. Also, grade is a char variable and a string cannot be assigned to a char variable. A
correct declaration is:

7
char grade = 'B'; //Line 2

Variable declaration in Line 3 is incorrect because the left side of the assignment operator must be a
variable, and the semicolon at the end of the statement is missing. A correct declaration is:
double num = 28.5; //Line 3

The variable declaration in Line 4 is incorrect because strings are enclosed in double quotation marks.
A correct declaration is:
string message = "First C++ course"; //Line 4

The variable declaration in Line 5 is incorrect because the value assigned to age must be an int value.
A correct declaration is:
int age = 18; //Line 5

11. a and c are valid


12. a. int x, y;
x = 25;
y = 18;
b. int temp = 10;
char ch = 'A';
c. x = x + 5;
d. double payRate = 12.5;
e. tempNum = firstNum;
f. temp = x;
x = y;
y = temp;
g. cout << x << " " << y << " " << x + 12 / y - 18 << endl;
h. char grade = 'A';
i. int num1, num2, num3, num4;
j. x = static_cast<int>(z + 0.5);

13. a. 9.0 / 5 * C + 32
b. static_cast<int>('+')
c. static_cast<int>(x + 0.5)
d. str = "C++ Programming is exciting"
e. totalInches = 12 * feet + inches
f. i++, ++i, or i = i + 1;
g. v = 4 / 3 * (3.1416 * r * r *r);
h. s = 2* (3.1416 * r * *r) + 2 * (3.1416 * r) * h;
i. a + (b – c) / d * (e * f – g * h)
j. (–b + (b * b – 4 * a * c)) / (2 * a)

8
14. x = 1
y = 102
z = 15
w = 44
15. x = 101
y = 11
z = 104
w = 159.00
t = 81.50
16. a. x = 18, y = 5, z = 4
b. 5 * x - y = 85
c. Product of 18 and 4 is 72
d. x - y / z = 17
e. 18 square = 324

17. a. 1000
b. 42.50
c. 1.25
d. 11.00
e. 9
f. 88.25
g. -2.00

18. a. cout << endl; or cout << "\n"; or cout << '\n';
b. cout << "\t";
c. cout << "\"";

19. a and c are correct


20.
a. char grade = '*';
b. double salesTax = 0.05;
c. int numOfJuiceBottles = 0;
d. double billingAmount = 0.0;
e. double gpa = 0.0;

9
Visit https://testbankbell.com
now to explore a rich
collection of testbank,
solution manual and enjoy
exciting offers!
21. a. int num1;
int num2;
b. cout << "Enter two numbers separated by spaces." << endl;
c. cin >> num1 >> num2;
d. cout << "num1 = " << num1 << ", num2 = " << num2
<< ", 2 * num1 – num2 = " << 2 * num1 – num2 << endl;

22. A correct answer is:


#include <iostream>
#include <string>

using namespace std;

const double DECIMAL = 5.50;


const string blanks = " ";
double PAY_RATE = 10.75;

int main()
{
int height, weight;
double discount;
double billingAmount;
double bonus;
int hoursWorked = 45;
double price;

height = 6;
weight = 156;

cout << height << " " << weight << endl;

discount = (2 * height + weight) % 10;


price = 49.99;

billingAmount = price * (1 - discount) - DECIMAL ;


// DECIMAL = 7.55;

cout << price << blanks << "$" << billingAmount << endl;

bonus = hoursWorked * PAY_RATE / 50;

cout << "Bonus = " << bonus << endl;

return 0;
}

23. A correct answer is:


#include <iostream>

using namespace std;

const char STAR = '*';


const int PRIME = 71;

10
int main()
{
int count, sum;
double x;

int newNum; //declare newNum

count = 1;
sum = count + PRIME;
x = 25.67; // x = 25.67;
newNum = count * 1 + 2; //newNum = count * ONE + 2;
sum++; //(x + sum)++;
sum = sum + count; //sum + count = sum;
x = x + sum * count; // x = x + sum * COUNT;
sum += 3; //sum += 3--;
cout << " count = " << count << ", sum = " << sum
<< ", PRIME = " << PRIME << endl;
return 0;
}

24. A correct answer is:

#include <iostream>
#include <string>

using namespace std;

int main()
{
int num1, num2;
string str1;

cout << "Enter a string without any blanks in it : ";


cin >> str1;
cout << endl;

cout << "Enter two integers: ";


cin >> num1 >> num2;
cout << endl;

cout << str1 << " "


<< "num1 * num2 = " << num1 * num2 << endl;

return 0;
}

25. An identifier must be declared before it can be used.


26. b.
27. a. x += 5;
b. x *= 2 * y
c. totalPay += currentPay;
d. z *= (x + 2);

11
e. y /= x + 5;

28. a. x = x + 5 – z;
b. y = y * (2 * x + 5 – z);
c. w = w + 2 * z + 4;
d. x = x – (z + y – t);
e. sum = sum + num;
29.
a b c
a = (b++) + 3; 8 3 und
c = 2 * a + (++b); 8 2 12
b = 2 * (++c) – (a++); 9 -3 11

30.
a b c sum
sum = static_cast<int>(a + b + c); 6 3 2.2 11
b += c * a; 6 16 2.2 11
c -= a; 6 16 -3.8 11
a *= 2 * b - c; 214 16 -3.8 11

31. (The user input is shaded.)


firstNum = 62
Enter three numbers: 35 10.5 27

The numbers you entered are 35, 10.5, and 27


z = 33
Enter grade: B

The letter that follows your grade is: C

32. (The user input is shaded.)


Enter last name: Miller

Enter a two digit integer: 34

Enter a decimal number: 62.5

Name: Miller
Id: 34
Mystery number: -5.14286
33.
#include <iostream>
#include <string>

using namespace std;

12
const double X = 13.45;
const int Y = 18;
const char STAR = '*';

int main()
{
string employeeID;
string department;
int num;
double salary;

cout << "Enter employee ID: ";


cin >> employeeID;
cout << endl;

cout << "Enter department: ";


cin >> department;
cout << endl;

cout << "Enter a positive integer less than 80: ";


cin >> num;
cout << endl;

salary = num * X;

cout << "ID: " << employeeID << endl;


cout << "Department " << department << endl;
cout << "Star: " << STAR << endl;
cout << "Wages: $" << salary << endl;
cout << "X = " << X << endl;
cout << "X + Y = " << X + Y << endl;

return 0;
}

34. The program requires four inputs in the following order:


string decimal_number decimal_number integer

13
Random documents with unrelated
content Scribd suggests to you:
piece of ribbon in his hand made this day one beyond all others; it
called him from his sleep to be king in a beautiful world.
He realized now that, though he had felt sure before, there had
nevertheless been something lacking—and here it was. All was
certain now. And the joyous possibilities of the future seemed
unbounded. He sat there now for hours, deep in his dreams, twining
the ribbon round his fingers, one after another—none must be
forgotten—and at last round his neck.
Suddenly he started at the sight of his father approaching, and put
away the ribbon hastily. He got up in some embarrassment; it
occurred to him suddenly that Ormarr might perhaps have noticed
the ribbon himself at first. The thought left him utterly at a loss.
Ormarr came up and sat down quietly, as if unaware of anything
typo.
“A fortunate thing about the lamb,” he said. “Coming back
unharmed like that. All sorts of accidents might have happened to
it.”
“Yes,” said Ørlygur, trying to speak calmly.
“Have you time to help me today with the mangers in the big
stable?—or were you thinking of going somewhere else?”
Ørlygur felt suddenly that it was most urgent he should go
somewhere else, though he had no clear idea as to where. There
was something in Ormarr’s voice that seemed to suggest he was not
expected to remain at home.
He did not answer at once. Ormarr sat waiting for an answer, but
without impatience, as if realizing something of what was passing in
the young man’s mind.
When Ørlygur spoke, it was with a calmness that surprised
himself.
“Yes—I was going for a walk ... over towards Bolli. I thought of
giving the lamb—to the widow there. She would be glad of it, no
doubt; then she could kill one of her own sheep instead.”
Ormarr apparently found nothing in this proposal beyond an
ordinary act of charity; he simply said:
“Yes, give it to her. Or perhaps to her daughter. Then you may be
sure it would be well looked after.”
“That is true.”
Ørlygur had now completely regained his composure, but was still
somewhat at a loss to understand his foster-father’s attitude in the
matter.
“You can bring them greeting from me,” said Ormarr, as he rose
and walked away.
Ormarr was both glad and sorry. But he knew it was best not to
let Ørlygur’s love affairs become a matter of dissension between
them. They of Borg had need to hold together well; he had made his
sacrifice—all that remained now was to prepare his wife.

When Ørlygur arrived at Bolli, with the lamb trotting contentedly


behind him, he found the widow outside the gate.
She looked at him, and then at the lamb. She had noticed that
morning that it was missing, but had merely thought it had been
found and taken away earlier in the day.
“Good morning,” she said in answer to his greeting. “Your lamb
seems loth to leave us.”
Bagga had told her mother before that the lamb always came
back every time she had essayed to drive it off with other stray
sheep.
“It seems so,” Ørlygur agreed. “Can I have a word with Snebiorg?”
There was a lump in his throat; he could hardly speak the name.
“She is not at home just now. We had a stranger here last night,
and she has gone out to see him a little on his way. How far, I do
not know. Can you guess who the stranger was?”
“I think so. Guest the One-eyed, was it not?”
“Oh—then you knew he was here?”
“Yes. I was the first to meet him. When I left him yesterday he
was on his way to you.”
“Why did you not come with him, then, and fetch your lamb?
When did you fetch it?”
“I did not fetch it at all.”
“But—it was here last night, and this morning it was gone.”
Suddenly Ørlygur understood what had happened. And he flushed
at the thought.
“That may be so,” he answered vaguely. He hardly knew what to
say.
The widow looked at him, as if somewhat offended at his tone.
“Won’t you come in and sit down for a while?”
“Thanks,” said Ørlygur. And they went indoors.
He had never been inside the house before. The little room was
furnished with two beds; he looked immediately at the one which
was evidently Bagga’s. Her hat hung on a nail at the head of the
bed, her knife and fork were in a little rack close by. On a shelf lay
her Bible and Prayer Book, with some other volumes. He dared not
take them up to see what they were—they looked like collections of
the Sagas. The bed was neatly made, and a knitted coverlet of many
colours spread over.
He sat down on the other bed with a strange sense of being an
intruder here. His thoughts were vague, but he was dimly conscious
that the place was filled with the spirit and life of the girl herself.
Here she lived; the little trifles in the room were things she daily
touched.
The widow, entering behind him, invited him to sit on the other
bed. He did so, feeling dazed, and seating himself uncomfortably on
the very edge. The widow suggested that he need not be afraid of
lying down if he were tired, but he declined the offer with some
abruptness.
The woman sat knitting, and for a long time neither spoke, only
glancing across at each other from time to time.
The widow was not altogether pleased with this visit. She was at a
loss to think what Ørlygur à Borg could have to say to her daughter,
but as he did not speak, she was not inclined to ask him. Also, she
remembered her promise to Guest the One-eyed the day before.
They sat thus all day, exchanging only an occasional word. Once
the widow went out and made some coffee, which they drank in
silence.
At length she remarked:
“You are very patient to wait so long.”
“Yes,” he replied.
A little later she brought him some food and a drink of milk. She
herself had eaten her meal in the larder, as was her wont. While he
ate, she sat with her knitting, glancing at her guest now and again.
“Bagga must soon be here.”
Ørlygur nodded.
The widow pointed to the bookshelf. “You might take a book, if
you care to, and pass the time. You must be tired of waiting.”
“I am not tired of waiting,” said Ørlygur.
Dusk was falling when Bagga at last returned. As soon as her
mother heard her footsteps outside, she rose and left the room.
Ørlygur remained seated. Something was about to happen—
something wonderful, incredible, beyond his control. He was to see
her—hear her voice, perhaps—even speak to her himself. He felt
unable to move. The thing must happen. And then—what then?
The widow exchanged a hasty greeting with her daughter, and
told her that one was waiting to speak with her.
Bagga was overcome with confusion, a wave of warmth swept
through her body, and her hands grew moist.
“Me—to speak with me—who is it, then?”
“Go in and see.”
The widow disappeared into the kitchen.
Bagga could hardly find strength to walk the few steps through
into the room. When at length she entered and saw Ørlygur standing
there, she stood and stared at him without a word. Ørlygur, too, was
unable to speak.
She offered her hand, and he took it, but the greeting was equally
awkward on both sides. At last Ørlygur plucked up courage to speak:
“Will you have my lamb?” he asked. “I have brought it with me.”
The girl smiled, but did not look up. “Thank you,” she said simply.
For a long time they stood facing each other without a word,
hardly daring to breathe. Ørlygur felt he had much to say, but could
find no words. At last he offered his hand again.
“Good-bye,” he said.
She took it hesitatingly, but this time their clasp was one of
lingering affection. They stood breathing heavily; then suddenly she
leaned forward with her forehead against his shoulder; her hot
cheek touched his. For a moment he pressed her to him, and passed
his hand caressingly over her hair.
With a sigh she slipped from his arms, pressed his hand once
more, and turned away. Then quietly Ørlygur left the room.
He went out of the house without taking leave of the widow. The
latter, returning a little later to the room, asked if he had gone.
“Yes,” said the girl.
“What did he come for?”
“He gave me his lamb.”
“Nothing more?”
“Yes.”
There was a long pause.
“Does he love you?”
Bagga turned her face away. “Yes,” she whispered.
“And you love him too?”
The girl burst into tears. “Yes, mother.”
The widow took her daughter in her arms. “God’s blessing, my
child. No need to be sorry for that. By the look of him, he is not one
to change.”
CHAPTER XI

G uest the One-eyed felt both ill and tired when, after bidding
farewell to Bagga, he limped up towards the farm.
An old man, evidently the master of the place, was busy with
some men thatching a hayrick with slabs of turf. The turf lay rolled
up and set in piles about on the ground, a couple of hundred rolls,
perhaps, in all. It had been a laborious task to cut the pieces thin
and even at the edge; the strips were about ten feet long. Two men
were busy on the stack, preparing it for the roof, the highest point
carefully set so as to give an even slope on all sides. Others were
lifting the rolls, taking great care to avoid a break. The farmer
himself did but little of the work, being chiefly occupied with looking
on and giving orders.
The arrival of a stranger caused a momentary pause in the work.
Those on the ground gathered round him, and the two men on the
stack leaned over to see.
“Who are you?” asked the farmer curtly.
“A beggar,” answered the newcomer, seating himself on one of the
rolls of turf.
“I thought as much,” grumbled the man. “Can’t you sit on the
ground, instead of spoiling my turf?” And, turning angrily to the
men, he shouted:
“Well, what is there to stare at? Get to your work.”
Guest the One-eyed sat down, and for a while was left to himself.
A dog came trotting up, sniffed at him, and curled up dog-fashion at
his feet, apparently satisfied of being in decent company.
At length the farmer turned to him again.
“Well, old Greybeard, what news from anywhere?”
“There’s little news I can tell.”
“I daresay. All you think of is the meals you get—in other folks’
kitchens.”
“There’s many things a man can think of. Will you give me shelter
for the night?”
“I’ve no beds for lazy vagabonds. But you can sleep in the barn if
you like, though I warn you it’s draughty. I take it you can do some
tricks or tell a story or something in return?”
Guest the One-eyed smiled and, looking up at him, said:
“Have you ever heard the story of the rich man and Lazarus?”
The farmer turned pale with rage. “You cursed bundle of rags!” he
shouted. “You dare ... I’ll have you taken up before the sheriff for
begging if you don’t mind your words!”
The men looking on smiled. The local authority was Ormarr à
Borg, and all knew there would be little gained by an angry man
who came to him demanding the punishment of some poor
wanderer for begging. It would, indeed, be about the best thing that
could happen to the culprit himself.
“What is your name?” demanded the farmer, striding towards him
with a threatening mien.
“I am called Guest the One-eyed,” answered the old man, with his
quiet smile.
The farmer was taken aback. “Guest the One-eyed! Impossible.
He never comes this way. Guest the One-eyed....”
He looked at the beggar again, shifted his feet, and stood in some
confusion. “God’s blessing,” he stammered out at last. “Forgive me—
I did not know. Come—come up to the house with me.”
And clumsily he helped the wanderer to rise; his hands were little
used to helping others.
“Let me take your sack,” he said.
“Nay—a beggar carries his own,” answered Guest the One-eyed,
and hoisted it on his back. Then suddenly he smiled and, swinging
down the sack once more, handed it to the farmer, who took it as if
it were a favour granted him.
Guest the One-eyed glanced at him mischievously.
“’Tis strange to see you with a beggar’s pouch. None would have
thought you could ever come to that.”
The farmer cast a sidelong glance at his men, and was about to
make an angry retort, but restrained himself and gave a forced
laugh. Then he said:
“If I were to fill the sack with more than you could carry—what
then?”
“Then I should let it lie.”
The farmer was evidently anxious to make much of his visitor; the
latter, however, seemed to care little for his hospitality, and would
not even accept the bed that was offered him. The farmer assured
him that it was a bed reserved for personages of distinction; bishops
and high officials had lain in it. But Guest the One-eyed preferred to
sleep in the barn, and all that the farmer could do was to have the
cracks in the walls stopped as far as possible, and a fresh layer of
hay laid over the rotting stuff that strewed the floor.
Before retiring, the beggar brought up the subject of Sera Ketill.
“That scoundrel!” cried the farmer angrily. “Ay, a scoundrel he
was.” And a murmur from those around showed that he had voiced
the general feeling. “He duped them all. Not a man but was on his
side. I remember him, and his lying sermons and his talk—and I was
no wiser than the rest, to doubt my old friend. Ørlygur à Borg, he
was a true man, and Sera Ketill that killed him—his own father.... I
shan’t forget! And his poor wife, the Danish Lady at Hof—ruined for
life. Twenty years now she’s lived at Borg, and never got back to
sense nor wit. ’Tis a comfort to think he’ll suffer for it all, or there’s
no justice in heaven. The Devil must have marked him from the first
—and took and kept him, and best he should. If I met Sera Ketill at
the gates of Paradise, I’d turn and go another way.”
And the farmer laughed, pleased with his own wit and confident of
his own salvation.
Guest the One-eyed had listened with pale face to the outburst of
hatred and scorn. At last he rose heavily to his feet and said:
“It is time a weary man went to his rest.”
The farmer went with him to the barn.
“If you will sleep here,” he said. “Though why you should, with a
fine bed waiting, I can’t see.”
“’Tis best to seek a place that’s not above one’s deserts,” said the
other mildly. And he added, “Though, for some, it may be hard to
find.”

Left to himself, the wanderer lay staring into the darkness. And his
lips moved in an inaudible prayer.
“My God, my God—if only I might dare to hope for forgiveness at
the last; only one gleam of Thy mercy to lighten my heart. I am
weighed down with the burden of my sin, and long has been my
penance, but what is all against the evil I have done? Yet I thank
Thee, Lord, that I alone am let to suffer; that Thy wrath has not
been visited on that innocent child.”
During the night his fever increased. He could not sleep, and lay
tossing uneasily from side to side, murmuring often to himself:
“Lord, I feel now that Death is near. Good that it comes at last,
and yet I fear it. What will Death mean for me? Some hell more
terrible than I have lived through all these years? Thy will be done!
It will not be tonight, I think. Another day, and then ... Death....
Lord, Thy will be done!”
He lapsed into a state of drowsy helplessness, murmuring still to
himself:
“Lord, Lord ... two children were granted me of Thy grace. And to
the one was given Thy peace in death; the other has found
happiness in life.... I thank Thee, Lord....”
He lay bathed in perspiration; dust and fragments of hay clung to
his face and hands.
“Two Women ... Lord, forgive me.... Mercy, Lord....”
He flung himself over on his side and hid his face.
“Father, how often have I sinned against Thee! And knowing my
sin, yet hardening my heart. Even then I suffered, but I would not
heed, and persevered in sin. Forgive me, Lord.”
For a while he lay still, then turned again. He strove to raise
himself, but his strength failed him, and, sinking back, he cried
aloud:
“Forgive me, Lord—forgive me, Lord....”
His words were lost in the darkness, and he lapsed into
unconsciousness.
He woke some hours later, exhausted and parched with thirst. But
he could not rise to seek for water, and at length he sank into a
restless, feverish sleep.

Early next morning he was awakened by the entry of the farmer.


At first he hardly realized where he was. He was ill, with a racking
pain in his head. But he strove to appear as if nothing were amiss.
“Good morning,” said the farmer. “And how do you feel today?
Was it very draughty up here?”
“Good morning. I have slept well, and I thank you.”
The farmer laughed at sight of his visitor’s face, which was
plastered with scraps of hay. “You’ve enough hay about you to feed
a sheep through the winter,” he said with a laugh.
Guest the One-eyed had risen. As he stepped out into the cold
morning air, his teeth chattered audibly. “The sun is not up yet, it
seems,” he murmured.
Never before had he so longed for the rising of the sun. He stood
now staring towards the east; it seemed to him a miracle that he
should be suffered to see the sun rise once more.
“The blessed sun,” he murmured to himself.
The sky showed a dull blue between hurrying banks of cloud. The
farmer yawned, and observed carelessly, “It’s cold in the mornings
now. Come in; there will be coffee ready soon.”
Guest the One-eyed went into the cowshed, washed himself at the
drinking-trough, and dried his face and hands on his coat, the
farmer watching him the while.
“You’re one for cleanliness, I see,” he said. “I never trouble to
wash myself, these cold mornings.”
The wanderer produced a piece of comb, and tidied his hair and
beard; it was a matter of some difficulty to get rid of the scraps of
hay.
“Why not stay here for the day and have a good rest?” suggested
the farmer. And with a sly glance he added: “I daresay we can afford
to give you a bite of food.”
“I thank you. But I must go on.”
“Ay, there’s always haste with those that have nothing to do,” said
the farmer, with a touch of malice.
He walked down a little way with his guest, some of the farm
hands accompanying them. The wanderer bade farewell to each in
turn, and all answered with a blessing. Then they turned back, the
farmer alone going on a few steps more.
“Have you not some good word to leave with me?” he asked a
little awkwardly.
Guest the One-eyed looked at the man from head to foot; the
burly fellow stood as timidly before him as a child that had done
wrong.
“It would be well if you were oftener to take the beggar’s bag
upon your shoulders,” he said. And, having shaken hands in parting,
he walked away.
“God be with you,” said the farmer, and stood for some moments
watching the beggar as he limped along. For the first time in his life
he began to feel that perhaps after all wealth and security were not
the only things worth coveting. There were other things—other
feelings than the sense of material gain or loss.
He walked back to the house somewhat humbled in mind, and,
going into his room, sat down on the bed with his head bowed in his
hands. For long hours he sat there, seemingly in thought. In the
evening, he roused himself with a sigh, and went out to where the
men were working. His tone seemed harsher than his wont as he
ordered them about.
But Guest the One-eyed went on his way, shivering and muttering
to himself:
“Haste—yes, for today. But tomorrow? Who knows? Who asks?
What do we know of it all? Life ... and mortals playing at joy and
sorrow; a little life ... a long life ... playing at life ... playing with
others’ hearts and with our own. And thinking it all in earnest. And
the end? The grave, the grave. Cold earth, dark earth, where the
sun cannot reach, though its grace be spread all above. My God, my
God, what are my thoughts? Not earnest? Is it not earnest, all our
life? Lord, forgive me. Thoughts, thoughts that come and go—but
not for long. Thoughts fearing to end, to die under the earth, and
never reach to heaven. My soul—Lord God, where is my soul? Is
there a soul that is mine? Lord, Lord, forgive me! This is the last day
Thy grace allows me; the last day of life on earth, of life and the
blessing of the sun for me; the last day granted me to feel joy in the
light. Joy? But my days have been pain, pain. And yet there is joy....
The last day ... Lord, here am I, Thy servant. Let Thy wrath be
turned away from me, O Lord, and see my heart that repents,
repents. Forgive me, Lord....”
He crouched down beside a rock, and laid his head upon the
stone.
“God in heaven, I can feel Thy presence. Or is it that God is far
away? Is it mercy or God’s judgment that comes? Forgive me, Lord,
if there can be forgiveness.... Thy will be done!”
He rose, and limped along his painful way.
CHAPTER XII

G uest the One-eyed wandered far that day. He felt that it was
fated to be his last.
Fever burned in his veins; fever in his soul. It seemed a painful
task to end this life. And he was tormented by dread lest his
sufferings should after all not suffice to atone for his sin.
Sun and rain and hail took turns to follow him on this the hardest
of all his wandering days. Clouds and sheets of hail passed before
the face of the sun, making strange shadows on the hillsides, the
contrast being more pronounced where dark stretches of lava and
the lighter hue of cornfields alternated. One moment the sun’s rays
warmed him, the next he was stung by the sudden lash of hailstones
in his face. It was a day of contest between the powers of sun and
shadow—a giant’s battle where summer and life were pitted against
autumn and death. And the earth over which it raged was marked
by each in turn.
His beggar’s staff changed constantly from a dry, gleaming white
to a dripping grey. He swung it at each step, as it were a distorted
extra limb. And the figure of the man standing against the changing
background of the sky seemed hardly human; more like some
fantastic creation of Nature herself.
And this man’s soul, maybe, was rugged and misshapen as his
body. But the soul of a man is not so easy to see....
The first homestead he came to on this day’s march was a little
place. A peasant and his wife came out to meet the stranger, the
rest of their people following. They were at home today, by reason
of the weather, and had, moreover, expected his arrival. All the
district knew by now that Guest the One-eyed had come amongst
them. The peasant and his household received him kindly, with
many blessings. He felt their kindness without any need of words,
and marked how they were glad to have him with them.
And talking with them, he spoke the name of Sera Ketill, once
their priest, whom all remembered now with execration. Here, too,
the tongues that had been ready with blessing for himself were
quick to curse at the mention of that name; to their minds, Sera
Ketill was a monster, a thing of dread. His very name made them
shudder as if at the touch of some loathsome thing. He was a
murderer, a hypocrite, and a cheat; they could not find in him the
slightest link of charity and affection with his fellow-men. Even his
death had been the act of a despicable creature, in that he had
endeavoured to secure their regard by leaving all he had to the poor,
and then flinging himself over the cliffs into the sea. This last was
not even a fine thought of his own—a young poet had been the first
to go that way, and by that very spot.
But the Devil had taken his body, and his soul, if any shred of soul
he had, had doubtless gone with it. A thing of no use upon earth! He
had not even had the courage to face the consequences of his acts.
He was a stain upon mankind; in justice, he should have been
burned at the stake before his soul went on its way to hell.
Guest the One-eyed listened pale as death to the bitter words.
Strange, how a man’s character could thus outlive him in the
memory of his fellows. Twenty years had not sufficed to bring
oblivion for the wrongs this man had done. His body might have
been reduced to ashes in a moment, but the fire of hate burned still
about his memory.
The wanderer looked at the faces of those about him—faces that
one moment shone with kindly pleasure and the next glowed fiercely
with hate. He could not but smile, though his heart was heavy. Poor
mortals, poor unseeing men, seeing good and evil as things
absolute, unalterable.
But while his thoughts were busy, his soul cried all the time to
God, praying forgiveness....
Thoughts within thoughts, and thoughts again.
For they were right, after all, these men. They themselves had the
power of being good or evil, of loving or hating without reserve.
It was their hatred he was feeling now, fuel added to the furnace
of his own remorse; he was passing through a purgatory of
maledictions.
One moment he saw himself as Guest the One-eyed, beggar and
wanderer—a figure clear enough. Then he was the doomed soul on
the verge of death, doubting everything, doubting even his own
doubt, torn asunder to his innermost being, a living cry of anguish
seeking Heaven. And then, too, he was the penitent, believing and
trusting in God—yet even so unable to wrench himself free from the
spectres of doubt and mockery and scorn that clung to him.
Something prompted him to rise and speak to these his fellows
gathered round him. There were many now; for folk had come from
places near to see the man of whom they had heard so much. Yes,
let them see him and judge him by what he had been and what he
was now, and act as they were prompted to do. It was not enough
that they received Guest the One-eyed with blessings, and cursed
the name of Sera Ketill; he longed to bring both before them as one.
But the impulse reached no further than his thought.
As they cursed the man that he had been, he sat silent, with eyes
cast down. He made no movement, only sighed. Then at last he
rose, and stood a moment trying to collect his thoughts.
“I must go,” he said. “I have a long way before me today.”
And he bade farewell to each in turn, confused thoughts passing
through his mind the while.
“They give me their hands—but I am stealing what they give. If
they knew me, they would spit on me. Stone me, perhaps. Would
they, I wonder—would they do so now? But I steal what they give
because I need it; it is because I must. Soon my hand will be cold,
and then my soul will have no link with any other soul—no way to
feel their love and innocent kindness. Yes, I must let them give me
their hands—as many as I can. And after that, the grave. Lord,
remember that this is my last day ... the very last. But I will be
patient ... Lord, Thy will be done!”
And he went on his way, with blessings from all. The people stood
silently watching him as he went; their hearts had been moved
beyond their daily wont by the sight of this unhappy wanderer, and
their thoughts followed him now in sympathy along his sorrowful
way.
The wanderer’s heart was suffering more than all. His soul ached
with loneliness—he felt as if already he were confined within the
cold walls of the grave. It seemed a marvel to him that he could
endure this and live.
On and on he went, thinking—thinking....
“If no man can forgive me, if no human heart can realize my
atonement, can then God ever forgive? The blessings they have
given me—can they ever outweigh the curses that were meant for
me as well? Lord, if only one might cross my path to know me, and
forgive. One who could take my hand and know and pardon all....
Lord, Thy will be done....”
He was taking the road towards the trading station. On the way
he entered a house here and there, and was greeted kindly as ever.
But at the mention of Sera Ketill’s name, all who heard it had but
curses; eyes that had looked on him in kindliness lit now with hatred
of the man he named.
“I have done more evil even than I thought,” he muttered to
himself as he went on his way, refusing those who would have
shared the road. “To have planted so much hatred in all their hearts;
to be the cause of all those evil thoughts beyond my own; things
grown in the dark from evil seed of my sowing. Lord, who shall ever
tear them up and destroy them that they may not rise again? Lord,
can it be that the fruits of sin never cease, when good comes to an
end at last? Lord, Lord, now I see the greatness of my sin—more
than I had dreamed. And now I am come to the verge of death and
have no strength even to suffer more. Only Thy mercy, Lord—grant
me Thy mercy, that hast denied me the forgiveness of men.”
The trading station had grown considerably in the twenty years
that had passed. There were many new houses in the place. And the
wanderer looked in vain for the turf huts that had formed the
outskirts of the settlement when he knew it. They were gone, and
modern buildings stood where they had been.
He limped from door to door, bearing with him each time blessings
for Guest the One-eyed and curses for the name of Sera Ketill. At
the last house, he asked:
“Where do the poor live now?”
There was still a glimmer of hope in his heart that there, among
the poorest, he might find one single heart to bless Ketill the priest
for what he had given.
“There are no poor here now,” was the reply.
“Are all in Hofsfjordur grown rich?”
“There is a poor widow living out at Bolli, a lonely place at the foot
of the hills. But ’tis her own fault that she lives as poorly as she
does. She might have taken the help that was offered her. But it was
the Devil Priest’s money, and she would not take it.”
“The Devil Priest?”
“Sera Ketill was his name. But we call him the Devil Priest.”
“Good-bye,” said Guest the One-eyed.
“Peace go with you.”
On his way out from the trading station, he passed by a shed from
which came the sound of voices within. The door stood half-open,
and, looking in, he saw in the half-dark four strange figures—three
men and a woman, ragged and wild-looking; evidently these were
vagabonds like himself.
The woman was shouting a ribald song; one of the men sat
crouched on the floor rocking with laughter. The other two men were
fighting, the stronger chuckling at each successful blow, while the
other fought in silence, waiting his chance.
The man on the floor called out to the others with an oath to
come and listen. “Give over, you fools, and come and hear. ’Tis a
new song—one of Gudda’s best. Ay, Gudda, she can make a song, if
she’s not as young as she used to be....” And he came shambling
over towards them.
He was a tall fellow, bigger than either of his two companions, still
young, with reddish-yellow hair and a pasty face. The two sprang
away as he came up.
“Mind your own business, Luse-Grimur!” cried the one nearest.
This was a dark man of slender build, known as the Bishop, from a
way he had of mimicking the tones of a priest, and repeating
fragments of an indecent parody of the marriage service whenever a
couple came together. “Keep away, and don’t bring your lice near
me.”
“You’ll have my hands nearer than you care for in a minute,”
answered Grimur, with a leer. “Go on, Gudda.”
Gudda was known for her talent in making songs. She was a
powerfully built woman getting on in years, with a coarse voice in
keeping with her coarse face and heavy build. Her skirt reached
hardly below her knees, showing a pair of muscular legs; her
stockings were of rough material, and clumsily darned. One
redeeming feature she had—her large blue eyes. Children feared her
until she looked them full in the face, when the glance of her eyes
seemed to draw them to her.
She was one of the few women vagabonds in the country, and
was known far and wide for her vulgar songs.
Looking towards the door, she caught sight of the stranger, and
called to him to come in. Guest the One-eyed limped over to the
group.
“God’s peace,” he said as he entered.
“God’s peace with you,” returned the others, somewhat abashed.
Suddenly the youngest of the party stepped forward. This was Jon
Gislason, a short, thick-set fellow who had some claim to good
repute, being known to work at times, and trusted to carry letters
and parcels from place to place. He strode up to the newcomer, and
looked him in the face.
“He’s one of our sort,” he said. “It is Guest the One-eyed.”
There was a shout of welcome at this, and Grimur took out a flask
from his pocket.
“Best corn brandy,” he declared, handing the bottle to Guest.
“Good stuff, you can take my word for it.” Then, in a slightly altered
tone, he went on: “I daresay, now, you think us rather a rough lot,
you being more gentle like. But it’s just our way. Rap out an oath
without thinking like.”
“’Tis not such words that do the worst of harm,” said Guest the
One-eyed. And he took a sip from the flask.
Then with a grimace he spat it out. “I thought it might do me
good,” he said. “But I can’t swallow it, all the same.”
“Oh, you swine!” shouted Grimur as he saw the precious liquid
wasted. “There, I’m sorry,” he went on. “That’s no way to speak to a
godly man. But the stuff’s too good to waste. Leastways, to my
thinking.”
Guest the One-eyed offered his hand.
“No harm, brother,” he said. “Each to his own ways.”
“‘Brother,’” repeated Grimur thickly. “Calls me brother—shakes
hands. Nobody ever called me brother before. My own folk won’t
touch me, call me Luse-Grimur, and keep far out of reach of vermin.
Ay, it’s true enough what they say of you, Guest One-eyed. God’s
blessing, man.”
“We’ll have Grimur drowning his lice in floods of tears,” grumbled
the Bishop. “See them swimming around and saying their prayers,
Amen!”
“You, Bishop,” said Grimur warningly—“well for you this good
man’s here. If it weren’t for him, I’d send you swimming and saying
your prayers in earnest for less than you’ve said.”
“Filthy beast,” said Gudda scornfully, and spat at the Bishop, who
only laughed.
Guest the One-eyed turned to him with a keen glance.
“Have you ever thought,” he said quietly, “that one day must be
your last—that your tongue may be silent for ever after any word
you have spoken?”
“Ho, yes. And I’ve got it all ready what I’m going to say. When I
get to the Gates of Heaven—if the Devil hasn’t pinched my soul all
hot on the way—I’ll say to the Lord: ‘Here you are; Behold the Son
of Man!’ That’s my words.”
“You also are my brother,” said Guest the One-eyed. And he held
out his hand.
The Bishop spat in it.
Guest the One-eyed stood silent gazing at his extended hand.
Then he sat down and sobbed.
The Bishop’s laugh of derision died away. He stood for a moment
breathing heavily, then slunk out of the shed and went away.
The other three stood silently watching, afraid to look at each
other, uncertain what to do.
After a little Guest the One-eyed regained his self-control, and,
looking up at them, he said quietly:
“Friends, do not hate him; believe that he is not worse than
others. Only, the way to his heart is longer and harder to find.”
“I have far to go,” he said, after a pause. “Good-bye.”
“God’s blessing,” murmured the others as he left.
He stood for a moment outside the shed, uncertain which way to
turn. He would have liked to go to Hof, to the vicarage on the other
side of the fjord, but it was too far to walk. This was his last day,
and already a good part of it was gone, though he had lost no time.
He hobbled down to the beach to see if there might chance to be
a boat going across. Just as he neared the slope, he perceived a
little group of people gathered round something he could not see.
Close by, a small rowing-boat was drawn up on the sand. Going
closer, he saw a man bending over a heap of clothes. Presently the
man rose up, and said:
“He is dead.”
Those near bared their heads and made the sign of the cross.
Guest the One-eyed needed but a glance at the ragged heap to
recognize it—it was the body of the Bishop.
“And only a moment since I was with him,” he said.
“We were too late,” said a fisherman. “Saw him throw himself into
the sea, and hurried after. But he held on to some weed down below
—look, there’s some of it in his hand still.”
And, true enough, the dead hand clutched a tangle of weed.
“So he is gone already to stand before the Lord,” he murmured.
“Poor soul—God grant him peace.” And he made the sign of the
cross above the body.
The men were running the boat out. He went up to them and
asked:
“Are there many going across?”
“Only myself,” answered a young man. “I am working at the
vicarage, and going back there now.”
“Will you take me with you to the other side of the fjord?”
“Gladly,” answered the young man, and flushed with pleasure.
The day was fine now, but clouds were racing across the sky. Rain
and hail had ceased, only the shadows of the clouds darkened the
water as they passed.
Guest the One-eyed sat still, gazing around him as the boat shot
out into the fjord. His eyes took in the landscape; there, nestling in
the valley, lay the homestead of Borg.
The sight of it moved him; this was the place that had been his
home. Strange to think of it now. There his infant limbs had learned
to walk, and thither he turned now, for the last steps on his road of
life.
He was roused from his meditations by the youth, who nodded
over towards a steep cliff rising from the water.
“That was where Sera Ketill killed himself,” he said. “You’ve heard
of Sera Ketill?”
“Yes. I knew him. Better, perhaps, than many did.”
“A monster of wickedness he must have been,” said the young
man, as if inviting the other to tell what he knew.
For the moment, Guest the One-eyed was dull to the pain which
condemnation of Sera Ketill usually caused him. He was about to
answer absently, “Judge not ...” but checked himself and sat gazing
vacantly across the water.
“I never thought to sail on the sea again,” he said, as if to himself.
“Again?”
“Yes. I have sailed far in my time, and seen many lands.”
The young man seemed to take this as a jest.
“You mean in thought, I take it?” he suggested.
Guest the One-eyed looked at him. “You are not without sense,”
he remarked. “Do you travel in thought yourself?”
The young man laughed, and shook his head. “Not much. But I
am going to America this winter.”
“Do not do that,” said the other quietly.
“Why not? There is good money to be made there.”
“True. But it is easiest to die in the place where one was born.”
“I have not thought of dying just yet.”
“Maybe not. But life leads only to death. Death is the only thing
we can be certain of gaining; perhaps the only gain.”
“I had heard that Guest the One-eyed preached the Gospel of
Life,” said the young man seriously.
“And you are disappointed to find that Guest the One-eyed is only
human after all?”
The young man did not reply, and they went on in silence. They
were more than half-way across the fjord by now. Guest the One-
eyed sat thinking of the strange currents beneath the smooth
surface, and the marvels of life in the hidden depths. All seemed
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

testbankbell.com

You might also like