Download full Programming and Problem Solving with C 3rd Edition Edition Nell B. Dale ebook all chapters
Download full Programming and Problem Solving with C 3rd Edition Edition Nell B. Dale ebook all chapters
https://ebookfinal.com/download/problem-solving-with-c-the-object-of-
programming-fourth-edition-walter-j-savitch/
https://ebookfinal.com/download/introduction-to-java-and-software-
design-1st-edition-nell-b-dale/
https://ebookfinal.com/download/problem-solving-with-c-10th-edition-
walter-savitch/
https://ebookfinal.com/download/data-abstraction-problem-solving-
with-c-5th-edition-frank-m-carrano/
ADTs Data Structures and Problem Solving with C 2nd
Edition Larry R. Nyhoff
https://ebookfinal.com/download/adts-data-structures-and-problem-
solving-with-c-2nd-edition-larry-r-nyhoff/
https://ebookfinal.com/download/engineering-problem-solving-with-c-
united-states-edition-paperback-delores-m-etter/
https://ebookfinal.com/download/geotechnical-problem-
solving-1-edition-john-c-lommler/
https://ebookfinal.com/download/java-an-introduction-to-problem-
solving-and-programming-7th-edition-walter-savitch/
https://ebookfinal.com/download/101-activities-for-teaching-
creativity-and-problem-solving-1st-edition-arthur-b-vangundy-2/
Programming and Problem Solving with C 3rd Edition
Edition Nell B. Dale Digital Instant Download
Author(s): Nell B. Dale
ISBN(s): 9780763721039, 0763721034
Edition: 3rd Edition
File Details: PDF, 127.73 MB
Year: 2001
Language: english
h i r d Edition
Programming ond
Problem Solving with
1»^
dcifk iJ/rjad'hiPi
http://www.archive.org/details/programmingproblOOdale
Third Edition
Nell Dale
University of Texas, Austin
Chip Weems
University of Massachusetts, Amherst
Mark Headington
University of Wisconsin - La Crosse
p. cm.
ISBN 0-7637-2103-4
1. C++ (Computer program language) I. Weems, Chip. II. Headington, Mark R. III.
Title.
All rights reserved. No part of the material protected by this copyright notice may be reproduced or utilized
in any form, electronic or mechanical, including photocopying, recording, or any information storage or
retrieval system, without written permission from the copyright owner.
This book was typeset in Quark 4.1 on a Macintosh G4. The font families used were Rotis Sans Serif Rotis
Serif and Prestige Elite. The first printing was printed on 40# Lighthouse Matte.
M.H.
To quote Mephistopheles, one of the chief devils, and tempter of Faust,
J. W. von Goethe, Faust, Waher Kaufman trans., New York, 1963, 199.
As you study this book, do not let the logic of algorithms bind your
imagination, but rather make it your tool for weaving masterpieces of
thought.
two editions of Programming and Problem Solving with C++ have con-
first
The been among the best-seUing computer science textbooks in the United
sistently
States. Both editions, as well as the Pascal and Ada versions of the book, have
been widely accepted as model textbooks for ACM/lEEE-recommended curricula for
the CSl/ClOl course and for the Advanced Placement A exam in computer science.
Although this third edition incorporates new material, one thing has not changed:
our commitment to the student. As always, our efforts are directed toward making
the sometimes difficult concepts of computer science more accessible to all students.
This edition of Programming and Problem Solving with C++ continues to reflect
our experience that topics once considered too advanced can be taught in the first
course. For example, we address metalanguages explicitly as the formal means of
specifying programming language syntax. We introduce Big-0 notation early and
use it to compare algorithms in later chapters. We discuss modular design in terms of
abstract steps, concrete steps, functional equivalence, and functional cohesion. Pre-
conditions and postconditions are used in the context of the algorithm walk-through,
in the development of testing strategies, and as interface documentation for user-
written functions. The discussion of function interface design includes encapsulation,
control abstraction, and communication complexity. Data abstraction and abstract
data types (ADTs) are explained in conjunction with the C++ class mechanism, form-
ing a natural lead-in to object-oriented programming.
ISO/ANSI standard C++ is used throughout the book, including relevant portions
of the new C++ standard library. However, readers with pre-standard C++ compilers
are also supported. An appendix book and on the publisher's Web site)
(both in the
explains how to modify the textbook's programs to compile and run successfully
with an earlier compiler.
As in the second edifion, C++ classes are introduced in Chapter 1 1 before arrays.
This sequencing has several benefits. In their first exposure to composite types, many
students find it easier to comprehend accessing acomponent by name rather than by
position. With classes introduced in Chapter 1 1, Chapter 12 on arrays can rather eas-
ily introduce the idea of an array of class objects or an array of structs. Also, Chapter
Preface
13, which deals with the list as an ADT, can implement a list by encapsulating both the
data representation (an array) and the length variable within a class, rather than the
alternative approach of using two loosely coupled variables (an array and a separate
length variable) to represent the list. Finally, with three chapters' worth of exposure to
classes and objects, students reading Chapter 14, "Object-Oriented Software Develop-
ment," can focus on the more difficult aspects of the chapter: inheritance, composition,
and dynamic binding.
least one complete program in the main text, with several chapters having three
or four such programs.
Some educators reject the C family of languages (C, C++, Java) as too permissive and
too conducive to writing cryptic, unreadable programs. Our experience does not support
this view, provided that the use of language features is modeled appropriately. The fact
that the C family permits a terse, compact programming style cannot be labeled simply
Preface |
as "good" or "bad." Almost any programming language can be used to write in a style
that is too terse and clever to be easily understood. The C family may indeed be used in
this manner more often than are other languages, but we have found that with careful
instruction in software engineering and a programming style that is straightforward,
disciplined, and free of intricate language features, students can learn to use C++ to
produce clear, readable code.
It must be emphasized that although we use C++ as a vehicle for teaching computer
science concepts, the book is not a language manual and does not attempt to cover all
There are diverse opinions about when to introduce the topic of object-oriented
programming (OOP). Some educators advocate an immersion in OOP from the very
beginning, whereas others (for whom this book is intended) favor a more heterogeneous
approach in which both functional decomposition and object-oriented design are pre-
sented as design tools. The chapter organization of Programming and Problem Solving
with C++ reflects a transitional approach to OOP. Although we provide an early preview
of object-oriented design in Chapter 4, we delay a focused discussion until Chapter 14
after the students have acquired a firm grounding in algorithm design, control abstrac-
tion, and data abstraction with classes.
Synopsis
Chapter 1 is designed to create a comforiable rapport between students and the subject.
The basics of hardware and software are presented, issues in computer ethics are raised,
and problem-solving techniques are introduced and reinforced in a Problem-Solving
Case Study.
Chapter 2, instead of overwhelming the student right away with the various
numeric types available in C++, concentrates on two types only: char and string. (For
the latter, we use the ISO/ANSI string class provided by the standard library.) With
fewer data types to keep track of, students can focus on overall program structure and
get an eariier stan on creating and running a simple program. Chapter 3 then begins
with a discussion of the C++ numeric types and proceeds with material on arithmetic
expressions, function calls, and output. Unlike many books that detail all of the C++
data types and all of the C++ operators at once, these two chapters focus only on the
int, float, char, and string types and the basic arithmetic operators. Details of the
other data types and the more elaborateC++ operators are postponed until Chapter 10.
The functional decomposition and object-oriented design methodologies are a major
focus of Chapter 4, and the discussion is written with a healthy degree of formalism.
This early in the book, the treatment of object-oriented design is more superficial than
that of functional decomposition. However, students gain the perspective that there are
two-not one-design methodologies in widespread use and that each serves a specific
purpose. Chapter 4 also covers input and The eariy introduction of files permits
file I/O.
the assignment of programming problems that require the use of sample data files.
Students learn to recognize functions in Chapters and 2, and they learn to use
1
standard library funcnons in Chapter 3. Chapter 4 reinforces the basic concepts of func-
viii I Preface
tion calls, argument passing, and function libraries. Chapter 4 also relates functions to
the implementation of modular designs and begins the discussion of interface design
that is essential to writing proper functions.
Chapter 5 begins with Boolean data, but its main purpose is to introduce the con-
cept of flow of control. Selection, using If-Then and If-Then-Else structures, is used to
demonstrate the distinction between physical ordering of statements and logical order-
ing. We also develop the concept of nested control structures. Chapter 5 concludes with
a lengthy Testing and Debugging section that expands on the modular design discussion
by introducing preconditions and postconditions. The algorithm walk-through and code
walk-through are introduced as means of preventing errors, and the execution trace is
used to find errors that made it into the code. We also cover data validation and testing
strategies extensively in this section.
Chapter 6 is devoted to loop control strategies and looping operations using the
syntax of the While statement. Rather than introducing multiple syntactical structures,
our approach is to teach the concepts of looping using only the While statement. How-
ever, because many instructors have told us that they prefer to show students the syntax
for all of C++'s looping statements at once, the discussion of For and Do-While state-
ments in Chapter 9 can be covered optionally after Chapter 6.
By Chapter 7, the students are already comfortable with breaking problems into
modules and using and they are receptive to the idea of writing their
library functions,
own functions. Chapter 7 focuses on passing arguments by value and covers flow of
control in function calls, arguments and parameters, local variables, and interface
design. The last topic includes preconditions and postconditions in the interface docu-
mentation, control abstraction, encapsulation, and physical versus conceptual hiding of
an implementation. Chapter 8 expands the discussion to include reference parameters,
scope and lifetime, stubs and drivers, and more on interface design, including side
effects.
Chapter 9 covers the remaining "ice cream and cake" control structures in C++
(Switch, Do-While, and For), along with the Break and Continue statements. Chapter 9
forms a natural ending point for the first quarter of a two-quarter introductory course
sequence.
Chapter 10 begins a transition between the control structures orientation of the first
half of the book and the abstract data type orientation of the second half. examine We
the built-in simple data types in terms of the set of values represented by each type and
the allowable operations on those values. We introduce more C++ operators and discuss
at length the problems of floating-point representation and precision. User-defined sim-
ple types, user-written header files, and type coercion are among the other topics cov-
ered in this chapter.
We begin Chapter 1 1 with a discussion of simple versus structured data types. We
introduce the record (struct in C++) as a heterogeneous data structure, describe the
syntax for accessing its components, and demonstrate how to combine record types into
a hierarchical record structure. From this base, we proceed to the concept of data
abstraction and give a precise definition to the notion of an ADT, emphasizing the sepa-
ration of specification from implementation.The C++ class mechanism is introduced as
a programming language representation of an ADT. The concepts of encapsulation,
information hiding, and public and private class members are stressed. We describe the
1
Preface |
separate compilation of program files, and students learn the technique of placing a
class's declaration and implementation two separate files: the specification (.h) file
into
and the implementation file.
In Chapter 12, the array is introduced as a homogeneous data structure whose com-
ponents are accessed by position rather than by name. One-dimensional arrays are
examined in depth, including arrays of structs and arrays of class objects. Material on
multidimensional arrays completes the discussion.
Chapter 13 integrates the material from Chapters 11 and 12 by defining the list as
an ADT. Because we have already introduced classes and arrays, we can clearly distin-
guish between arrays and lists from the beginning. The array is a built-in, fixed-size
data structure. The list is a user-defined, variable-size structure represented in this
chapter as a length variable and an array of items, bound together in a class object.
The elements in the list are those elements in the array from position through posi-
tion length - 1. In this chapter, we design C++ classes for unsorted and soried list
ADTs, and we code the list algorithms as class member functions. We use Big-0 nota-
tion to compare the various searching and sorting algorithms developed for these
ADTs, Finally, we examine C strings in order to give students some insight into how a
higher-level abstraction (a string as a list of characters) might be implemented in terms
of a lower-level abstraction (a null-terminated char array).
Chapter 14 extends the concepts of data abstraction and C++ classes to an explo-
ration of object-oriented software development. Object-oriented design, introduced
briefly in Chapter 4, is revisited in greater depth. Students learn to distinguish between
inheritance and composition relationships during the design phase, and C++"s derived
classes are used to implement inheritance. This chapter also introduces C++ virtual
functions, which support polymorphism in the form of run-time binding of operations
to objects.
Chapter 15 examines pointer and reference types. We present pointers as a way of
making programs more efficient and of allowing the run-time allocation of program
data. The coverage of dynamic data structures continues in Chapter 16, in which we
present linked lists, linked-list algorithms, and alternative representations of linked lists.
Chapter 17 introduces C++ templates and exception handling, and Chapter 18 con-
cludes the text with coverage of recursion. There is no consensus as to the best place to
introduce these subjects. We believe that it is better to wait until at least the second
semester to cover them. However, we have included this material for those instructors
who have requested it. Both chapters have been designed so that they can be assigned
for reading along with eariier chapters. Below we suggest prerequisite reading for the
topics in Chapters 17 and 18.
Additional Features
Special Sections Five kinds of features are set off from the main text. Theoretical
Foundations sections present material related to the fundamental theory- behind various
branches of computer science. Software Engineering Tips discuss methods of making
programs more reliable, robust, or efficient. Matters of Style address stylistic issues in
the coding of programs. Background Information sections explore side issues that
enhance the student's general knowledge of computer science. May We Introduce
sections contain biographies of computing pioneers such as Blaise Pascal, Ada Lovelace,
and Grace Murray Hopper. Web Links appear in most of these Special Sections
prompting students to visit the companion Web site for expanded material.
Goals Each chapter begins with a list of learning objectives for the student. These
goals are reinforced and tested in the end-of-chapter exercises.
Testing and Debugging Following the case studies in each chapter, this section
considers in depth the implications of the chapter material with regard to thorough
testing of programs. The section concludes with a list of testing and debugging hints.
Quick Checks At the end of each chapter are questions that test the student's recall of
major points associated with the chapter goals. Upon reading each question, the student
immediately should know the answer, which he or she can then verify by glancing at
the answers at the end of the section. The page number on which the concept is
discussed appears at the end of each question so that the student can review the
material in the event of an incorrect response.
Exam Preparation Exercises These questions help the student prepare for tests. The
questions usually have objective answers and are designed to be answerable with a few
minutes of work. Answers to selected questions are given in the back of the book, and
the remaining questions are answered in the Instructor's Guide.
Preface I
Programming Warm-up Exercises This section provides the student with experience in
writingC++ code fragments. The student can practice the syntactic constructs in each
chapter without the burden of writing a complete program. Solutions to selected
questions from each chapter appear in the back of the book; the remaining solutions
may be found in the Instructor's Guide.
Case Study FoUow-Up Much of modern programming practice involves reading and
modifying existing code. These exercises give the student an opportunity to strengthen
this critical skill by answering questions about the case study code or by making
changes to it.
Supplements
Instructor's Guide and Test Bank The Instructor's Guide features chapter-by-chapter
teaching notes, answers to the balance of the exercises, and a compilation of exam
questions with answers. The Instructor's Guide, included on the Instructor's TookKit CD-
ROM, is available to adopters on request from Jones and Bartlett.
Instructor's ToolKit CD-ROM Available to adopters upon request from the publisher is
Programs The programs contain the source code for all of the complete programs that
are found within the textbook. They are available on the Instructor's ToolKit CD-ROM
and also as a freedownload for instructors and students from the publisher's Web site
www.problemsolvingcpp.jbpub.com. The programs from all the case studies, plus
complete programs that appear in the chapter bodies, are included. Fragments or
snippets of program code are not included nor are the solutions to the chapter-ending
"Programming Problems." The program files can be viewed or edited using any standard
text editor, but in order to compile and run the programs, a C++ compiler must be used.
The publisher offers compilers bundled with this text at a substantial discount.
A Laboratory Course in C++, Third Edition Written by Nell Dale, this lab manual
follows the organization of the third edition of the text. The lab manual is designed to
xii I Preface
allow the instructor maximum flexibility and may be used in both open and closed
laboratory settings. Each chapter contains three types of activities: Prelab, Inlab and
Postlab. Each lesson is broken into exercises that thoroughly demonstrate the concepts
covered in the chapter. The programs, program shells (partial programs), and data files
thataccompany the lab manual can be found on the Web site for this book,
www. problemsolvingcpp jbpub com. .
.
Student Lecture Notebook Designed from the PowerPoint presentations developed for
this text, the Student Lecture Notebook is an invaluable tool for learning. The notebook
is designed to encourage students to focus their energies on listening to the lecture as
they fill in additional details. The skeletal outline concept helps students organize their
notes and readily recognize the important concepts in each chapter.
Acknowledgments
We would like to thank the many individuals who have helped us in the preparation of
this third edition. We are indebted to the members of the faculties of the Computer Sci-
ence Departments at the University of Texas at Austin, the University of Massachusetts
at Amherst, and the University of Wisconsin-La Crosse.
We extend special thanks to Jeff Brumfield for developing the syntax template
metalanguage and allowing us to use it in the text.
For their many helpful suggestions, we thank the lecturers, teaching assistants, con-
sultants, and student proctors who run the courses for which this book was written, and
the students themselves.
We are grateful to the following people who took the time to offer their comments
on potential changes for this edition: Trudee Bremer, Illinois Central College; Mira Carl-
son, Northeastern Illinois University; Kevin Daimi, University of Detroit, Mercy; Bruce
Elenbogen, University of Michigan, Dearborn; Sandria Kerr, Winston-Salem State; Ali-
cia Kime, Fairmont State College; Shahadat Kowuser, University of Texas, Pan America;
Bruce Maxim, University of Michigan, Dearborn; William McQuain, Virginia Tech;
Xiannong Meng, University of Texas, Pan America; William Minervini, Broward Uni-
versity; Janet Remen, Washtenaw Community College; Viviana Sandor, Oakland Uni-
versity; Mehdi Setareh, Virginia Tech; Katy Snyder, University of Detroit, Mercy; Tom
Steiner, University of Michigan, Dearborn; John Weaver, West Chester University;
Charles Welty, University of Southern Maine; Cheer-Sun Yang, West Chester University.
We also thank Mike and Sigrid Wile along with the many people at Jones and
Bartlett who J. Michael Stranz and Anne Spencer. Our
contributed so much, especially
special thanks go to Amy Rose, our Development and Product Manager, whose skills
N. D.
C. W.
M. H.
f
^^mmmmmi^
Preface v
What Is Programming? 2
An Introduction to Namespaces 73
2.3 More About Output 74
Creating Blank Lines 74 I
Inserting Blanks Within a Line 75
2.4 Program Entry, Correction, and Execution 76
Entering a Program 76
Compiling and Running a Program 77
Finishing Up 78
Problem-Solving Case Study: Contest Letter 79
3 5 8 1
Contents | xv
Value-Returning Functions 1 1
Library Functions 1 1
Floating-Point Numbers 1 1
Files 161
Summary 191
Summary 249
Quick Check 249
Answers 250
Exam Preparation Exercises 250
Programming Warm-Up Exercises 254
Programming Problems 256
Case Study Follow-Up 259
Looping 261
6 6.1 The While Statement 262
6.2 Phases of Loop Execution 264
6.3 Loops Using the While Statement 265
Count-Controlled Loops 265
Event-Controlled Loops 267
Looping Subtasks 273
6.4 How to Design Loops 276
Designing the Flow of Control 277
Designing the Process Within the Loop 278
The Loop Exit 279
6.5 Nested Logic 280
Designing Nested Loops 284
Problem-Solving Case Study: Average Income by Gender 291
Functions 309
7 7.1 Functional Decomposition with Void Functions 310
When to Use Functions 311
Arrays 631
12 12.1 One-Dimensional Arrays 632
Declaring Arrays 634
Accessing Individual Components 635
Out-of-Bounds Array Indexes 638
Initializing Arrays in Declarations 638
(Lack of) Aggregate Array Operations 639
Examples of Declaring and Accessing Arrays 640
Passing Arrays as Arguments 645
Assertions About Arrays 648
LJsing Typedef with Arrays 648
12.2 Arrays of Records and Class Objects 649
Arrays of Records 649
Arrays of Class Objects 651
12.3 Special Kinds of Array Processing 652
Subarray Processing 652
Indexes with Semantic Content 652
Contents
Summary 816
Quick Check 816
Answers 818
Exam Preparation Exercises 819
Programming Warm-Up Exercises 822
Programming Problems 823
Case Study Follow-Up 824
Recursion 1017
18 18.1 What Is Recursion? 1018
18.2 Recursive Algorithms with Simple Variables 1022
18.3 Towers of Hanoi 1025
18.4 Recursive Algorithms with Structured Variables 1030
18.5 Recursion Using Pointer Variables 1032
Printing a Dynamic Linked List in Reverse Order 1032
Copying a Dynamic Linked List 1035
18.6 Recursion or Iteration? 1040
Problem-Solving Case Study: Converting Decimal Integers to
Binary Integers 1041
Index 1125
Overview of
Programming and
Problem Solving
To understand what a computer program is.
problem.
nm«<t<ana«anaa«iaamH«|niia«i
—
I
Chapter 1 : Overview of Programming and Problem Solving
Overview of Programming
1.1
In the box in the margin is a definition of computer. What a brief definition for some-
thing that has, in just a few decades, changed the way of Hfe in industrialized societies!
Computers touch all areas of our lives: paying bills,
that computes; specif, a programmable electronic device would be easier to list those areas of our lives that are
that can store, retrieve, and process data* not affected by computers.*
— •—'^ —'^— « —-— i^ J5 5a(j ^]^a^ a device that does so much good is
What Is Programming?
1. Lift hand.
5. Let go of page.
Think how many neurons must fire and how many muscles must respond, all in a cer-
tain order or sequence, to move your arm and hand. Yet you do it unconsciously.
Much of what you do unconsciously you once had to learn. Watch how a baby con-
centrates on putting one foot before the other while learning to walk. Then watch a
*By permission. From Merriam-Webster's Collegiate Dictionary: Tenth Edition. ® 1994 by Merriam-Webster
Inc.
1.1 Overview of Programming |
the programming of one of our tools, the Computer A programmable device that can store,
computer. retrieve, and process data.
Just as a concert program lists the order A sequence
Computer program of instructions to be
in which the players perform pieces, a com- performed by a computer.
puter program lists the sequence of steps the
Computer programming The process of planning a
computer performs. From now on, when we a computer to follow.
sequence of steps for
use the words programming and program, we
mean computer programming and computer
program.
The computer allows us to do tasks more efficiently, quickly, and accurately than
we could by hand-if we could do them by hand at all. In order to use this powerful
tool, we must specify what we want done and the order in which we want it done. We
do this through programming.
A computer is not intelligent. It cannot analyze a problem and come up with a solution.
A human (the programmer) must analyze the problem, develop a sequence of instruc-
tions for solving the problem, and then communicate it to the computer. What's the
advantage of using a computer if it Once we have written the
can't solve problems?
solution as a sequence of instructions for the computer, the computer can repeat the
solution very quickly and consistently, again and again. The computer frees people from
repetitive and boring tasks.
To write a sequence of instructions for a computer to follow, we must go through a
two-phase process: problem solving and implementation (see Figure 1-1).
Problem-Solving Phase
1. Analysis and specification. Understand (define) the problem and what the solution
must do.
2. General solution (algorithm). Develop a logical sequence of steps that solves the
problem.
3. Verify. Follow the steps exactly to see if the solution really does solve the prob-
lem.
Implementation Phase
r
Analysis
and
specification
i
Verify
Test
Maintenance phase
Vs.
Maintenance Phase
because all programs are algorithms. A program is simply an algorithm that has been
written for a computer.
An algorithm is a verbal or written description of a logical sequence of actions. We
use algorithms every day. Recipes, instructions, and directions are all examples of algo-
rithms that are not programs.
1.1 Overview of Programming I
When you start your car, you follow a step-by-step procedure. The algorithm might
look something like this:
5. If the engine starts within six seconds, release the key to the ignition position.
6. If the engine doesn't start in six seconds, release the key and gas pedal, wait ten seconds, and repeat Steps 3 through
Without the phrase "but not more than five times" in Step 6, you could be trying to
start the car forever. Why? Because if something is wrong with the car, repeating Steps
3 through 6 over and over again will not start it. This kind of never-ending situation is
called an infinite loop. If we leave the phrase "but not more than five times" out of Step
6, the procedure does not fit our definition of an algorithm. An algorithm must termi-
amount of time for all possible conditions.
nate in a finite
Suppose a programmer needs an algorithm to determine an employee's weekly
wages. The algorithm reflects what would be done by hand:
\t.
3. If the number of hours worked is less than or equal to 40, multiply the number of hours by the pay rate to calculate
regular wages.
4. If the number of hours worked is greater than 40, multiply 40 by the pay rate to calculate regular wages, and then
multiply the difference between the number of hours worked and 40 by 1- times the pay rate to calculate overtime
wages.
5. Add the regular wages to the overtime wages (if any) to determine total wages for the week.
6 I
Chapter 1 : Overview of Programming and Problem Solving
The steps the computer follows are often the same steps you would use to do the calcu-
lations by hand.
After developing a general solution, the programmer tests the algorithm, walking
through each step mentally or manually. If the algorithm doesn't work, the programmer
repeats the problem-solving process, analyzing the problem again and coming up with
another algorithm. Often the second algorithm is just a variation of the first. When the
programmer is satisfied with the algorithm, he or she
a«eg^-ir.-^.^^^^.^^.^....:^c->irr««^w.>,a«»^-«^ ttanslatcs it into a programming language. We use
Programming language A set of rules, symbols, and the C++ programming language in this book,
special words used to construct computer program. A programming language is a simplified form of
— '-""- "-" -'-
'
— —-— — ——~— —
'^-'^
a
- " ^
j
become obvious to you as you read this book, this kind of shortcut actually takes more
time and Developing a general solution before you write a program helps you
effort.
manage the problem, keep your thoughts straight, and avoid mistakes. If you don't take
the time at the beginning to think out and polish your algorithm, you'll spend a lot of
extra time debugging and revising your program. So think first and code later! The
sooner you start coding, the longer it takes to write a program that works.
Once a program has been put into use, it is often necessary to modify it. Modifica-
tion may involve fixing an error that is discovered during the use of the program or
changing the program in response to changes in the user's requirements. Each time the
program is modified, it is necessary to repeat the problem-solving and implementation
phases for those aspects of the program that change. This phase of the programming
1.1 Overview of Programming |
7
PROBLEM-SOLVING PHASE
Algorithm
Shortcut?
^ Program
IMPLEMENTATION PHASE
processis known as maintenance and actually accounts for the majority of the effort
implementing
In addition to solving the problem,
"**' ~"
'
Thenretiral Fnunriatinns
(ic-. Binary Representation of Data
their simplest form, are either on or off. Usually a circuit that is on is represented by the num-
ber 1 ; a circuit that is off is represented by the number 0. Any kind of data can be represented
by combinations of enough Is and Os. We simply have to choose which combination repre-
sents each piece of data we are using. For example, we could arbitrarily choose the pattern
11010001 10 to represent the name C++.
Data represented by Is and Os is in binary form. The binary (base-2) number system uses
only Is and Os to represent numbers. (The decimal [base-10] number system uses the digits
through 9.) The word bit (short for binary digit) often is used to refer to a single 1 or 0. The
pattern 1 1010001 10 thus has 10 bits. A binary number with 10 bits can represent 2^° (1024)
different patterns. A byte is a group of 8 bits; it can represent 2^ (256) patterns. Inside the
computer, each character (such as the letter A, the letter g, or a question mark) is usually rep-
resented by a byte. Four bits, or half of a byte, is called a nibble or nybble-a name that origi-
nally was proposed with tongue in cheek but now is standard terminology. Groups of 16, 32,
(continued) ^
Exploring the Variety of Random
Documents with Different Content
It would seem, however, that Providence was keeping its eye on the
Acacias. For the very next morning brought a solution of the
difficulty. The marquis wrote from Yorkshire to suggest that during
the following week, if convenient to himself, Mr. Lascelles should
come to Barne Moor, as previously arranged, to paint the fair
Priscilla.
It appeared that in the stress of circumstance both Jim and his
mother had forgotten the Yorkshire marquis and the fair Priscilla.
“And it means a cool five hundred, too,” said Jim, with a little
pardonable exultation. “The terms are already arranged, thanks to
that old sportsman who is the oddest mixture of a human being I
have ever met.”
And then Jim gave a groan, for he remembered that it was upon the
strength of this important commission he had made up his mind to
take the plunge with the Goose Girl. The next moment he was
cursing himself because his upper lip was so flabby.
“You will never be the least use in this world, James Lascelles, my
son,” was the burden of his reflections, “if you can’t learn to take a
facer or two. Every time they knock you down you have got to come
up smiling, or you will certainly never be a Velasquez.”
Mrs. Lascelles was overjoyed by the providential letter from
Yorkshire. She blessed the marquis and all his acres. She insisted
that Jim should write by the next post to announce his intention of
coming to Barne Moor on the following Monday. And, in order that
there should be no possible doubt about the matter, she put on her
hat, although it was raining hard, and sallied forth to the stationer’s
shop at the corner of Chestnut Road and invested one of her few
remaining sixpences in Bradshaw’s Guide.
CHAPTER XXXII
BARNE MOOR
THOMAS L. MASSON’S
THE VON BLUMERS
A sparkling picture of American life in the suburbs of
New York, full of insight and penetrating,
unostentatious humor. Illustrated by Bayard Jones,
$1.50.
CONSTANCE SMEDLEY’S
THE DAUGHTER
A vigorous, likeable novel of the modern suffragette
movement in England. Has an extremely interesting
plot, and moves rapidly from the start. 12mo. $1.50
CONFLICT
An unusually strong and fascinating story of English life
in some of its most up-to-date phases. Depicts a
modern business woman in a modern environment.
$1.50
ALICE McALILLY’S
THE LARKINS WEDDING
“An apotheosis of good humor and neighborly
kindness.”—The Outlook. 24 illustrations. $1.00.
EDEN PHILLPOTTS’S
THE VIRGIN IN JUDGMENT
Mr. Phillpotts never wrote a finer, sounder novel of
Dartmoor than this. It has characters that will live
long. 12mo. $1.50.
J. C. SNAITH’S
WILLIAM JORDAN, JUNIOR
“The most moving and fascinating piece of work the
author of ‘Broke of Covenden’ has yet given us.”—
Contemporary Review (London). $1.50.
JOHN TREVENA’S
FURZE THE CRUEL
“It is always difficult to define what constitutes
greatness in any form of art, but when greatness
exists it is easy to discern. This is a great book—
almost a masterpiece.”—London Academy. $1.50.
ELIZABETH ROBINS’S
THE MILLS OF THE GODS
One of Miss Robin’s most finished and brilliant stories.
Its flavor is almost medieval in quality, although the
period is to-day. A superb artistic story of
Continental life. 12mo. $1.50.
ANNULET ANDREWS’S
THE WIFE OF NARCISSUS
“A stroke of genius.”—Hartford Courant.
“Instinct with spring-like romance.”—Chicago Record-
Herald. 12 mo. $1.50.
ELEANOR TALBOT KINKEAD’S
THE INVISIBLE BOND
“Rises to fine heights and is inspired by fine ideals.”—
New York Tribune.
“A gripping, brainy story, revealing an artist in literature
of decided promise.”—Boston Herald. Illustrated.
$1.50.
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
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.
ebookfinal.com