(Ebook PDF) Programming, Problem Solving and Abstraction With C
(Ebook PDF) Programming, Problem Solving and Abstraction With C
com
https://ebookluna.com/product/ebook-pdf-programming-problem-
solving-and-abstraction-with-c/
OR CLICK HERE
DOWLOAD NOW
https://ebookluna.com/download/programming-and-problem-solving-with-
python-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-problem-solving-with-c-10th-
edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-problem-solving-with-c-9th-
edition/
ebookluna.com
https://ebookluna.com/download/problem-solving-and-python-programming-
ebook-pdf/
ebookluna.com
Programming for Problem Solving- GTU 2018 - eBook PDF
https://ebookluna.com/download/programming-for-problem-solving-ebook-
pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-introduction-to-programming-
with-java-a-problem-solving-approach-3rd-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-7th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-8th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-matlab-a-practical-
introduction-to-programming-and-problem-solving-4th-edition/
ebookluna.com
Contents
Preface vii
3 Making Choices 29
3.1 Logical expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2 Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.3 Pitfalls to watch for . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4 Case study: Calculating taxes . . . . . . . . . . . . . . . . . . . . . 36
3.5 The switch statement . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4 Loops 45
4.1 Controlled iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.2 Case study: Calculating compound interest . . . . . . . . . . . . . 49
4.3 Program layout and style . . . . . . . . . . . . . . . . . . . . . . . 50
4.4 Uncontrolled iteration . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.5 Iterating over the input data . . . . . . . . . . . . . . . . . . . . . . 56
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
iii
PAGE X P ROGRAMMING , P ROBLEM S OLVING , AND A BSTRACTION
all of the Computer Science staff that worked at the University of Canterbury in New
Zealand during the period 1977–1979. Worth special mention is Tadao Takaoka: in
his own inimitable way, it was he who interested me in algorithms, and who served
as a role model for the academic life that I have pursued for thirty years.
Since then, it has primarily been academic colleagues at the University of Can-
terbury and at the University of Melbourne that have influenced me, by sharing their
knowledge and skills. I first taught introductory programming in 1982, and have done
so every year since then. The people that I have worked with on those subjects, or on
other academic projects, have all left a mark on this book. In roughly chronological
order, they include: Rod Harries, Robert Biddle, Tim C. Bell, Ian Witten, Ed Morris,
Rodney Topor, Justin Zobel, Liz Sonenberg, Lee Naish, Harald Søndergaard, Roy
Johnston, Peter Stuckey, Tim A.H. Bell, Bernie Pope, Peter Hawkins, Martin Sulz-
mann, Owen de Kretser, Michael Kirley, Lars Kulik, and Alan Blair. Many students
have pointed out errors or assisted in various ways, and will continue to do so into
the future; I thank them all.
Finally, there is family, and I gratefully acknowledge the long-ago input of my
parents, Duncan and Hilda Moffat; and the more recent encouragement supplied by
my wife Thau Mee, and our own children, Anne and Kate.
Alistair Moffat,
Melbourne, Australia
http://www.csse.unimelb.edu.au/˜alistair
November 28, 2012
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER XXI.
A CONSULTATION.
Mr. Sharp was seated in his office. A complacent smile played over
his features. Perhaps he was thinking of the adroit manner in which
he had secured one hundred dollars of the sum intrusted to him for
Robert Ford. The bottle and glass, on the table before him, testified
that his present occupation could hardly be considered of a
professional character.
While Mr. Sharp was holding up the glass before him, and admiring
the rich warm tint of its contents, Lewis Rand quietly opened the
door of the office and walked in. Had Mr. Sharp been consulted, he
would prefer to have been forewarned of the visit.
“Business driving as ever,” remarked Lewis, in his dry sarcastic way,
taking in at a quick glance the scene before him.
“Well, yes,” said Mr. Sharp, in some embarrassment, putting down
his glass, its contents untasted.
It may be remarked, that whenever Mr. Sharp was perplexed, it was
his habit to run his hands vigorously through his blushing locks, till
they stood upon his head erect, and bristled like so many porcupine
quills. By the time this was well over his faculties returned, and
“Richard was himself again.” To this he had recourse on the present
occasion, immediately after which he resumed his usual air of easy
assurance.
“I am, as you see,” he remarked affably, “taking my little symposium,
in humble imitation of the ancient Greeks and Romans,
—‘Champagne,’ as somebody has said, ‘is admirably calculated to
clear cobwebs from the brain.’”
“In that case,” dryly returned his client, who could not resist the
temptation of a hit at his coadjutor, “I advise you by all means to try
it.”
“Truly,” replied Mr. Sharp, who was dimly conscious of the covert
sarcasm, but deemed it politic not to notice it directly, “there is no
profession that racks the brain like mine, sir. The mightiest intellects
of ancient as well as of modern times——”
Mr. Sharp here assumed a standing posture, and was about to
pronounce a eulogy upon the different great men who had, during
the last twenty centuries, graced the profession which he adorned.
But the lawyer was saved the trouble of proceeding, by the
expression of a wish on the part of Lewis to attend to business.
“Certainly, by all means,” said Mr. Sharp, briskly resuming his seat,
and drawing before him a sheet of blank paper. “Business before
pleasure, or rather, with me, business is pleasure.”
“I have, as you know,” Lewis commenced, “lent the sum of three
hundred dollars to Robert Ford, through your agency.”
“And very liberal it was in you, I am sure,” said Mr. Sharp, with
benignant approval.
“By no means. I never professed to be a philanthropist, and I freely
acknowledge that in this act I was influenced by any but benevolent
motives. It was done solely with a view to promote my own
interests.”
Here he paused; and Mr. Sharp, while waiting for a further
explanation, rubbed his hands and nodded genially, as if to indicate
how thoroughly he indorsed the views of his principal.
“I need not remind you,” continued Lewis, not heeding this little
manifestation, “of how great importance it is to me that Robert Ford,
who is the only obstacle between me and his father’s fortune, should
be kept entirely out of the way of any possibility of meeting his
father. Such an encounter fortunately is not very probable, since
neither is aware of the other’s presence in the city. When, however I
consider how trifling a chance, such for instance as a glance at a
Directory, might lead to that knowledge, I feel more and more how
essential it is to my interests that some decisive step should be
taken. I may say in confirmation of this, that my uncle, whose health
is in a very critical state, has conceived a fancy, Heaven knows how,
that my cousin is still alive, notwithstanding the evidence of his
death in Chicago, which I placed in his hands.”
“That is awkward.”
“Yes, it is very awkward, especially as he has insisted on my drawing
up an advertisement for this precious cousin of mine, and having it
inserted in the daily papers.”
“And you have done so?”
“Not I. It would be suicidal. I drew up the advertisement, however,
as he requested, and he supposes that it has been inserted.”
Mr. Sharp surveyed Lewis with a glance of approval. It was a tribute
to superior rascality.
“Now I will explain to you,” pursued Lewis, “why I have lent money
to Robert Ford. My uncle is dangerously ill; he cannot live many
weeks at farthest. It is absolutely essential that some attempt should
be made to place my cousin where he cannot do me any harm. If
the laws permitted it, I would gladly have him imprisoned for debt.
That is, unluckily, out of the question. I have it in my power,
however, to annoy him in such a way as perhaps to drive him from
the city.”
“What do you propose to do?”
“Seize the furniture in execution, either with or without legal
sanction. Robert is far from being a man of the world, and there is
no risk in going to lengths with him, which would be dangerous with
others.”
“I have it,” said Sharp, eagerly.
“Well.”
“Your cousin is quite devoted to a heap of old machinery, out of
which he expects to make a flying machine or something of the kind.
To seize upon that would be the most serious blow you could inflict
upon him.”
“I believe you are right. Robert was always a visionary. If that should
prove insufficient to drive him away, I will authorize you to offer him
some pecuniary inducements in a guarded manner—some
remunerative employment which will call him elsewhere, and which
he will be the more tempted to undertake if his present occupation is
gone. Only let him be kept out of the way until——”
“You are called upon to lament the death of your venerable relation,”
suggested Sharp.
“Then,” pursued Lewis, “he may go where he pleases, so far as I am
concerned.”
“My dear sir, you should have been a lawyer. You would have been
an ornament to the profession,” said Mr. Sharp, with complimentary
emphasis.
“Rather an equivocal compliment, I am afraid,” returned Lewis, dryly.
“But in order to carry out this plan of ours, beyond a doubt, we must
ascertain that my cousin will be unable to pay the money when
called upon.”
“I think I may pledge you,” said the lawyer, “that you need entertain
no apprehensions on that score. From what I have seen I conjecture
that at the time of your loan he had but little money on hand, and I
know that he has expended a considerable sum since.”
“It is best to be certain, however.”
“Undoubtedly. I will myself call down there this afternoon, if you
think best, and ascertain this point without exciting his suspicions.”
“Do so; and should you find the prospect favorable, take measures
to have the demand presented to-morrow. If not discharged, you
know how to proceed.”
“You may rely upon my following your directions to the letter,”
returned the attorney, as sweeping his fingers once more through
his blushing locks, he bowed his client gracefully out.
CHAPTER XXII.
PREPARING THE WAY.
Mr. Bowers, the manager, sat at his desk in the little office adjoining
the stage, running his eye over a manuscript play presented for
examination by an ambitious young man in spectacles.
“Bah!” said the manager, tossing aside the play after a very brief
examination, “what can the man be thinking of? Two murders in the
first act, and a suicide in the first scene of the second! Such an
accumulation of horrors will never do. Here, Jeffries.”
The messenger made his appearance, and stood awaiting orders.
“Here,” said Mr. Bowers, tossing the play towards him, “just do this
thing up, and when the author calls this afternoon, tell him from me
that it is a very brilliant production, and so on, but, like Addison’s
Cato, for example, not adapted for dramatic representation. That will
sugar the pill.”
“Is it the tall young man, with a thin face?”
“Yes; his name is Ichabod Smith; but he writes under the nom de
plume of Lionel Percy.”
“Yes, sir; I have seen his name in the story papers. He has just
written one called ‘The Goblin Lover; or, The Haunted Tower.’”
“Any further orders, sir?” inquired Jeffries, deferentially.
“Has Miss Ford come?”
“No, sir; I think not.”
“Notice when she does, and request her to call at the office a
moment.”
“Yes, sir.”
“It is no more than fair that I should increase her salary,”
soliloquized Mr. Bowers. “She has really proved quite a card, and
richly deserves double what I have hitherto paid. Besides,” he
mused, for the manager was by no means neglectful of his own
interests, “I should not be surprised if another establishment should
try to entice her away by a larger offer. I must bind her till the end
of the season.”
At this moment Helen was announced by Jeffries.
She entered, not without a little feeling of embarrassment. She had
not often been brought into communication with Mr. Bowers, since
her engagement, and now the only reason that occurred to her to
account for this unexpected summons was, that she might in some
way have given dissatisfaction, although the applause which greeted
her nightly seemed hardly consistent with this idea.
Her apprehensions were at once dispelled by the unusually gracious
manner in which she was received.
“I am glad to see you, Miss Ford,” said Mr. Bowers, affably;
motioning her to a seat. “I have sent for you to say that your
services are in the highest degree acceptable to me and to the
public. The marks of approval which you receive nightly must be
very gratifying to you as they are to me.”
Quite overpowered by this extraordinary condescension on the part
of the manager, whom she had been accustomed to regard with a
feeling of distant awe and respect, Helen answered that she was
very glad that he was satisfied with her.
“To prove how highly I value your services,” continued Mr. Bowers, “I
have decided to double your weekly salary, provided you will sign an
engagement to remain with us till the end of the season.”
Helen, who had feared on being summoned to the manager’s
presence, that it was to be told that her services were dispensed
with, hardly knew how to express her gratitude for what was so far
beyond her expectations.
“It is very generous in you, sir,” she said, “to increase my salary
without my asking for it.”
“I always make it a point,” was the reply, “to recompense merit to
the extent of my means.”
“And now,” he added, pushing towards her a contract already drawn
up, “if you will sign this obligation to sing for me the remainder of
the season on these terms, I shall have no further cause to trespass
on your time.”
Helen wrote her name hastily, and withdrew from the manager’s
presence, it being already time for rehearsal.
“A very pretty little girl, and not at all aware of her own value,”
mused Mr. Bowers. “I am lucky to have secured her.”
Eager to communicate her increase of salary to her father and good
Martha Grey, who had always shown so warm an interest in her
welfare, Helen hastened home immediately after rehearsal.
Flushed with exercise, and with a bright smile playing over her face,
she danced into Martha Grey’s little room.
“O Martha!” she ejaculated, sinking into a chair, “I am all out of
breath running, I was so anxious to tell you of my good fortune. You
are the very first that I wanted to tell it to.”
“What is it, Helen?” inquired Martha, looking up from her never-
ceasing work with an expression of interest.
“What do you think it is? Guess now,” said Helen, smiling.
“I never was good at guessing, Helen. I think the shortest way will
be to tell me at once.”
“I have had my salary raised to twelve dollars a week; just think of
that, Martha: and all without my asking. I shall be able to buy ever
so many nice things for papa, now, that I couldn’t afford before; and
I mean to make you a present, besides, Martha; you’ve been so very
kind to me.”
“Thank you for the kind thought, my dear child. I will take the will
for the deed. But you mustn’t think yourself too rich. If you have any
money to spare you had better be laying it up against a time of
need. Remember the theatre will be closed for a time in the summer,
and your salary will stop. You will want to lay up money to carry you
through that time.”
“At any rate, Martha, if you won’t let me spend any money for you, I
shall insist on coming in now and then and helping you with your
work, so that you can gain time to walk out with me. I am afraid you
work too hard. You are looking pale.”
“It is long since I had much color,” said Martha. “You have enough
for us both.”
“Then you must go out and get some. But I mustn’t stop a minute
longer; I must go up and tell papa;” and she bounded up stairs with
a light heart, little suspecting what had taken place during her
absence.
What was her surprise to find her father listlessly looking out of the
window into the little court below, and otherwise quite unoccupied.
“What is the matter, papa?” inquired Helen, in apprehension; “and
where,” for the first time noticing the absence of the work which
usually engaged her father,—“where is your machine?”
“It is gone, my child,” said Mr. Ford, despondently.
“Gone! what do you mean, papa? You have not got discouraged, and
sent it away?”
“Discouraged! No, Helen; on the contrary, I never felt nearer success
than I did a few hours since. But all is changed now.”
“What has become of it, papa?” questioned Helen, in increasing
alarm.
“It has been seized for debt, Helen.”
“For debt?”
“Yes; for the note which I gave Mr. Sharp. I had not the money to
pay it, so they carried off my machine for security.”
“Is it possible he has been so cruel and unfeeling?” exclaimed Helen,
indignantly.
“Do not blame him, my child. I am convinced that it is far from his
intention to trouble or distress us. But he parted with the note a day
or two since, as he himself told me, on the express condition that it
should not be presented for payment, and this stipulation has been
disregarded.”
“And how large was this note, papa?”
“For three hundred dollars.”
“Three hundred! I thought it was only two hundred that were lent
you.”
“That was my own impression,” said Mr. Ford, with an air of
perplexity. “But you know,” he continued, with a melancholy smile,
“that I have no head for business. I have been so occupied in other
ways. It is quite possible that I have made a mistake.”
“I am afraid,” said Helen, gravely, “that Mr. Sharp is not so much
your friend as you imagine.”
“Not my friend, Helen? He offered to lend me this money voluntarily,
without any expectation of immediate return. I am certain that when
he hears of this affair, he will hasten to make it right.”
“Perhaps I do him wrong,” said Helen, thoughtfully, “and indeed I do
not know what good it would do him to annoy us. But, papa, there is
one thing I haven’t told you,—a piece of great good news. I have
had my salary doubled at the theatre. I shall earn twelve dollars a
week. Think of that, papa.”
“But are you not working too hard, Helen?”
“I, working hard! It is only a pleasure for me to sing. I am very lucky
in being paid for what I would rather do than not. It is different with
poor Martha. She doesn’t earn more than four dollars a week, and
has to sit at her sewing from morning till night. I wish I could do
something to help her. She looks so tired and pale all the time.”
“God has favored you, my child, in bestowing upon you so choice a
gift. I hope you do not fail to thank him for this goodness.”
“Never, papa. I thank him every night.”
“How much money have you left, papa?” she inquired, after a pause.
“I don’t know exactly how much. I had better give it to you to help
pay our daily expenses.”
“There are one hundred and twenty dollars,” said Helen, counting it.
“Then we shall need one hundred and eighty to make up the
balance of the sum mentioned in the note.”
“Surely, I cannot have expended that sum,” said Mr. Ford, with a
perplexed look. “If I could see Mr. Sharp?”
“I will go and see him, papa.”
“Perhaps it will be best.”
In five minutes Helen was on her way to the lawyer’s office.