Programming problem solving abstraction with C Moffat pdf download
Programming problem solving abstraction with C Moffat pdf download
https://ebookname.com/product/programming-problem-solving-
abstraction-with-c-moffat/
https://ebookname.com/product/problem-solving-with-c-ninth-
edition-walter-savitch/
https://ebookname.com/product/programming-and-problem-solving-
with-java-1st-edition-edition-nell-b-dale/
https://ebookname.com/product/adts-data-structures-and-problem-
solving-with-c-2nd-edition-nyhoff/
https://ebookname.com/product/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell/
Unsilencing the Past Track Two Diplomacy and Turkish
Armenian Reconciliation 1st Edition David L. Phillips
https://ebookname.com/product/unsilencing-the-past-track-two-
diplomacy-and-turkish-armenian-reconciliation-1st-edition-david-
l-phillips/
https://ebookname.com/product/celibacy-in-crisis-a-secret-world-
revisited-1st-edition-sipe/
https://ebookname.com/product/climate-change-in-the-polar-
regions-1st-edition-john-turner/
https://ebookname.com/product/dairy-microbiology-a-practical-
approach-1st-edition-photis-papademas/
https://ebookname.com/product/three-dimensional-partonic-
structure-of-the-nucleon-1st-edition-edited-by-m-anselmino/
Nelson Essentials of Pediatrics Seventh Edition Karen
J. Marcdante
https://ebookname.com/product/nelson-essentials-of-pediatrics-
seventh-edition-karen-j-marcdante/
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 IV P ROGRAMMING , P ROBLEM S OLVING , AND A BSTRACTION
7 Arrays 99
7.1 Linear collections of like objects . . . . . . . . . . . . . . . . . . . 99
7.2 Reading into an array . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.3 Sorting an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
7.4 Arrays and functions . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.5 Two-dimensional arrays . . . . . . . . . . . . . . . . . . . . . . . . 109
7.6 Array initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
7.7 Arrays and pointers . . . . . . . . . . . . . . . . . . . . . . . . . . 113
7.8 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.9 Case study: Distinct words . . . . . . . . . . . . . . . . . . . . . . 121
7.10 Arrays of strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
7.11 Program arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8 Structures 129
8.1 Declaring structures . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.2 Operations on structures . . . . . . . . . . . . . . . . . . . . . . . 131
8.3 Structures, pointers, and functions . . . . . . . . . . . . . . . . . . 135
8.4 Structures and arrays . . . . . . . . . . . . . . . . . . . . . . . . . 137
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
PAGE V
12 Algorithms 203
12.1 Measuring performance . . . . . . . . . . . . . . . . . . . . . . . . 203
12.2 Dictionaries and searching . . . . . . . . . . . . . . . . . . . . . . 205
12.3 Hashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
12.4 Quick sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
12.5 Merge sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
12.6 Heap sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
12.7 Other problems and algorithms . . . . . . . . . . . . . . . . . . . . 225
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Index 241
PAGE VI P ROGRAMMING , P ROBLEM S OLVING , AND A BSTRACTION
Preface to the Revised Edition
When I commenced this project in 2002, I was motivated by twenty years of teaching
programming to first-year university students, watching their reactions to and behav-
ior with a range of texts and programming languages. My observations at that time
led to the following specification:
• Value for money: Students are (quite rightly) sceptical of $100 books, and will
often commence the semester without owning it. Then, if they do buy one, they
sell it again at the end of the semester, in order to recoup their money. I sought
to write a book that students would not question as a purchase, nor consider
for later sale. With the cooperation of the publishers, and use of the “Pearson
Original” format, this aim has also been met.
• Readability: More than anything else, I wanted to write a book that students
would willingly read, and with which they would engage as active learners.
The prose is intended to be informative rather than turgid, and the key points
in each section have been highlighted, to allow students to quickly remind
themselves of important concepts.
encouraged to actively question the facts they are being told, to better cement
their own understanding.
• Excitement: Last, but certainly not least, I wanted a book that would enthuse
students, and let them see some of the excitement in computing. Few programs
can match the elegance of quick sort, for example.
Those thoughts led to the first edition, finalized in late 2002, and published in early
2003. Now it is nearly 2013, and another decade has gone by. I have used this book
every year since then in my classes, and slowly built up a list of “I wish I hadn’t done
it that way” issues. Those “I wishes” are all addressed in this revised edition. Most of
the changes are modest, and I think I have remained true to the original goals. (One
of the more interesting changes is that I have removed all mention of floppy disks!)
The idea is to show the students not just the end result of a programming exercise
as an abstract object, but to also show them, with a running commentary, how that
result is achieved. That the presentation includes the occasional dead end, judicious
backtracking and redesign, and sometimes quite puzzling behavior, is all grist for
the mill. The students engage and, for example, have at times chorused out loud at
my (sometimes deliberate, sometimes inadvertent) introduction of errors. The web
also helps with this style of teaching – the programs that are generated in class can
be made accessible in their final form, so students are free to participate, rather than
frantically copy.
Running a lecture in this way requires a non-trivial amount of confidence, both
to be able to get it right, and to deal with the consequences of sometimes getting it
wrong. More than once I have admitted that I need to go and read a manual before
coming back to them in the next class with an explanation of some obscure behav-
ior that we have uncovered. But the benefits of taking these risks are considerable:
“what will happen if. . . ” is a recurring theme in my lectures, and whether it is a
rhetorical question from me, or an actual interjection from a student, we always go to
the computer and find out.
Supervised laboratory classes should accompany the lecture presentations. Stu-
dents learn the most when trying it for themselves, but need to be able to ask questions
while they do. Having students work on programming projects is also helpful. The
exercises at the end of each chapter include broader non-programming questions, for
use in discussion-based tutorial classes.
Acknowledgements
I learned programming in the first half of the 1970s as a secondary school student in
Wellington, New Zealand, and will always be grateful to my two maths teachers, Bob
Garden and Ron Ritz, for their vision and enthusiasm. Our programming involved
a dialect of Fortran, and was carried out with a bent paper clip; special preprinted
cards that you popped chads out of; and a bike ride to the local bank branch to drop
the completed programs into a courier bag for transmission to their “Electronic Data
Processing Center”. Each compile/execute cycle took about three days, so we quickly
learned to be accurate.
My interest in computing was deepened during my University study, and I thank
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
Another Random Document on
Scribd Without Any Related Topics
Mais si les feux spirituels du purgatoire étaient d'un bon rapport,
combien les flammes visibles et temporelles étaient plus sûres
encore de faire impression et de tirer l'argent des poches! Qui peut
dire ce que rapporta au Saint-Siége la terreur de l'Inquisition? En
Allemagne, deux moines envoyés par Innocent VIII dans un petit
pays, le diocèse de Trêves, brûlèrent six mille hommes comme
sorciers. Nous avons parlé de l'Espagne. Quiconque se sentait en
péril courait à Rome, mettait ses biens aux pieds du pape. Que
faisait celui-ci? L'avide Sixte IV, si sanguinaire en Italie, se fit doux et
bon en Espagne, rappelant à l'Inquisition l'histoire du bon pasteur.
Alexandre VI, au contraire, bien plus intelligent, comprit que plus
elle brûlerait d'hommes, plus on aurait besoin du pape. Il loua les
inquisiteurs, fut cruel en Espagne, clément en Italie; les juifs et
Maures, contre lesquels il jetait feu et flammes, le trouvaient chez lui
le meilleur des hommes, s'établissaient sous sa protection et
apportaient leurs capitaux.
Fils d'une femme de Servie, Gem avait l'air d'un chevalier chrétien,
une très-noble figure, triste et pâle, un nez de faucon, les yeux d'un
poète et d'un mystique. Nos gentilshommes lui trouvaient des
manières vraiment royales, avec un mélange de fierté et de grâce
flatteuse qui n'appartient qu'à l'Orient. Le malheureux n'alla pas loin.
Prisonnier depuis treize années, l'air, le jour, le ciel italien, l'affluence
aussi de l'armée qui l'admirait et le fêtait, purent lui être fatales.
Charles VIII débuta à Naples par une mesure qui eût gagné le
peuple s'il y avait eu un peuple: il réduisit l'impôt à ce qu'il était du
temps de la maison d'Anjou. La réduction n'allait pas à moins de
deux cent mille ducats.
«Le 6 juillet, l'an 1495, environ sept heures du matin, le roi monta
à cheval et me fit appeler, dit Commines. Je le trouvai armé de
toutes pièces et sur le plus beau cheval que j'aye vu de mon temps,
appelé Savoie; c'étoit un cheval de Bresse qui étoit noir et n'avoit
qu'un œil; moyen cheval, mais de bonne grandeur pour celui qui
étoit dessus. Et sembloit que ce jeune homme fût tout autre que sa
nature ne portoit, ni sa taille, ni sa complexion; car il étoit fort
craintif à parler (ayant été nourri en grande crainte et avec petites
gens). Et ce cheval le montroit grand; il avoit le visage bon et de
bonne couleur, et la parole audacieuse et sage. Il sembloit bien que
frère Hieronyme (Savonarole) m'avoit dit vray, que Dieu le conduiroit
par la main, et qu'il auroit bien à faire au chemin, mais que
l'honneur lui en demeureroit.»
Des deux côtés, les hommes d'armes donnèrent des lances avec
une extrême vigueur; toutefois, il y avait cette différence que les
chevaux des Italiens étaient plus faibles, leurs lances légères et
souvent creuses. Après le premier choc, ils n'avaient plus rien que
l'épée.
La perte des Italiens fut énorme, trois mille cinq cents morts en
une heure. Cela tint à ce que les valets français, armés de haches,
taillèrent et mirent en pièces tout ce qui était à terre. Il n'y eut pas
de prisonniers.
CHAPITRE IV
RÉSULTATS GÉNÉRAUX—LA FRANCE SE CARACTÉRISE—L'ARMÉE
ADOPTE ET DÉFEND PISE, MALGRÉ LE ROI.
1496
Quoi donc! qu'avons-nous vu? Une jeune armée, un jeune roi qui,
dans leur parfaite ignorance et d'eux-mêmes et de l'ennemi, ont
traversé l'Italie au galop, touché barre au détroit, puis non moins
vite et sans avoir rien fait (sauf le coup de Fornoue), sont revenus
conter l'histoire aux dames.
Rien que cela, c'est vrai. Mais l'événement n'en est pas moins
immense et décisif. La découverte de l'Italie eut infiniment plus
d'effet sur le XVIe siècle que celle de l'Amérique. Toutes les nations
viennent derrière la France; elles s'initient à leur tour, elles voient
clair à ce soleil nouveau.
«N'avait-on pas cent fois passé les Alpes?» Cent fois, mille fois.
Mais ni les voyageurs, ni les marchands, ni les bandes militaires
n'avaient rapporté l'impression révélatrice. Ici, ce fut la France
entière, une petite France complète (de toute province et de toute
classe), qui fut portée dans l'Italie, qui la vit et qui la sentit et se
l'assimila, par ce singulier magnétisme que n'a jamais l'individu.
Cette impression fut si rapide que cette armée, comme on va voir, se
faisant italienne et prenant parti dans les vieilles luttes intérieures du
pays, y agit pour son compte, même malgré le roi, et d'un élan tout
populaire.
Pour résumer l'obstacle, ce n'était pas qu'il n'y eût rien, qu'on
n'eût rien fait pendant deux siècles. C'était qu'on eût fait quelque
chose, créé, fondé la platitude, la sottise, la faiblesse en tout.
Il n'est pas facile de deviner, quand cela eût fini, si elle n'eût
pourtant, dans un vif mouvement de jeunesse et d'instinct, sauté le
mur des Alpes, et ne se fût jetée dans un monde de beauté, tout au
moins de lumière, où rien n'était médiocre. Elle retrouva, à ce
contact, quelque chose de sa nature originaire; elle y reprit la faculté
du grand.
Milan n'était pas médiocre sous Vinci et Sforza, dans son bassin
sublime, cerné des Alpes, Alpe elle-même par sa cathédrale de
neige, éblouissante de statues; Milan sur le trône des eaux
lombardes, dans sa centralisation royale des arts, des fleuves et des
cultures.
Cela n'était pas médiocre. Quand notre armée rentra, elle rapporta
de Rome une histoire peu commune, propre à faire oublier tout ce
que la France gauloise trouvait piquant, tous les enfantillages des
Cent-Nouvelles et des vieux fabliaux.
On attendit trente ans pour trouver le vrai nom d'un tel monde. Ni
Luther ni Calvin n'y atteignirent. Rabelais seul, le bouffon colossal, y
réussit. Antiphysis, c'est le mot propre, qu'il a seul deviné (l'envers
de la nature). Par le beau, par le laid, le monde fut illuminé; et il
rentra dans le sens poétique, dans le sens de la vérité, des réalités
hautes et de la grande invention.
Tel est le résultat général. Mais notons aussi le spécial, qui n'en a
pas moins une importance profonde.
CHAPITRE V
ABANDON DU PARTI FRANÇAIS À FLORENCE—MORT DE
SAVONAROLE[21]
1498
«C'est le ciel qui combat; les saints de l'Italie, les anges, sont avec
les barbares. Ce sont eux qui les ont appelés, qui ont mis la selle aux
chevaux. L'Italie est toute brouillée, dit le Seigneur, elle sera vôtre
cette fois. Et le Seigneur vient au-dessus des saints, des
bienheureux qui se rangent en bataille, et tous sont dans les
escadrons... Où vont-ils? Saint-Pierre marche en criant: À Rome! à
Rome! Et saint Paul, saint Grégoire s'en vont criant: À Rome! Et
derrière eux marchent le glaive, la peste, la famine. Saint Jean, saint
Antonin, disent: Sus, sus, à Florence! Et la peste les suit. Saint
Antoine: Sus, en Lombardie! Saint Marc: Allons vers cette ville qui
s'élève au-dessus des eaux! Les saints patrons de l'Italie vont
chacun dans leur ville pour la châtier, saint Benoît dans ses
monastères, saint Dominique dans les siens, et saint François contre
les Frères. Et tous les anges du ciel, l'épée à la main, et toute la cour
céleste marchent à cette guerre.
«Ô ingrate Florence! J'ai fait pour toi ce que je n'ai pas voulu faire
pour mes frères selon la chair. Je n'ai parlé pour eux à aucun prince,
quoique les princes m'en priassent (j'en ai leurs lettres). Et pour toi,
cependant, j'allai au roi de France... Que t'ai-je fait, mon peuple?...
Eh bien, crucifie-moi, lapide-moi... Je souffrirai tout pour l'amour de
toi.» (Prediche soprà li salmi, éd. 1539, p. 24.)
Mais le pape, plus habile, toucha ensuite une corde sensible. Il fait
savoir aux Florentins que s'ils méprisaient l'excommunication, il
autoriserait la confiscation de leurs marchandises dans tous les pays
étrangers. La boutique frémit. Il ne fallait plus qu'un prétexte pour
livrer à la mort un homme qui compromettait Florence dans ses
intérêts les plus chers.
Il s'écria qu'il n'était pas besoin que Savonarole entrât dans les
flammes, que le moindre de ses disciples suffisait à faire ce miracle,
que Dieu le sauverait tout aussi bien, et dit: «Ce sera moi.»
Le pape se hâta d'écrire pour approuver la chose. Chose horrible!
Cette Rome sceptique, dans cette Italie raisonneuse, permettait,
ordonnait une de ces épreuves barbares où la folie antique bravait la
nature, tentait Dieu! Féroce comédie! Un athée affectant d'attendre
un miracle pour brûler un saint!
Le lugubre cortége entra dans une loge séparée en deux, d'où l'on
devait partir, tous les moines en psalmodiant, et derrière, force gens
portant des torches, non pas pour éclairer, car il restait six heures de
jour.
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.
ebookname.com