C++ Programming From Problem Analysis to Program Design 6th Edition Malik Solutions Manualpdf download
C++ Programming From Problem Analysis to Program Design 6th Edition Malik Solutions Manualpdf download
https://testbankdeal.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-malik-solutions-manual/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-6th-edition-malik-test-bank/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-7th-edition-malik-solutions-manual/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-8th-edition-malik-solutions-manual/
https://testbankdeal.com/product/sampling-design-and-analysis-
advanced-series-2nd-edition-lohr-solutions-manual/
Management Accounting Strategic Decision Making
Performance and Risk 2nd Edition Hunt Solutions Manual
https://testbankdeal.com/product/management-accounting-strategic-
decision-making-performance-and-risk-2nd-edition-hunt-solutions-
manual/
https://testbankdeal.com/product/derivatives-2nd-edition-sundaram-
solutions-manual/
https://testbankdeal.com/product/project-management-achieving-
competitive-advantage-3rd-edition-pinto-test-bank/
https://testbankdeal.com/product/fundamentals-of-multinational-
finance-6th-edition-moffett-solutions-manual/
https://testbankdeal.com/product/introduction-to-operations-and-
supply-chain-management-5th-edition-bozarth-test-bank/
Transformative Social Work Practice 1st Edition Schott
Test Bank
https://testbankdeal.com/product/transformative-social-work-
practice-1st-edition-schott-test-bank/
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-1
Chapter 9
Records (structs)
At a Glance
• Objectives
• Teaching Tips
• Quick Quizzes
• Additional Projects
• Additional Resources
• Key Terms
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-2
Lecture Notes
Overview
In Chapter 9, students will be introduced to a data type that can be heterogeneous. They
will learn how to group together related values that are of differing types using records,
which are also known as structs in C++. First, they will explore how to create
structs, perform operations on structs, and manipulate data using a struct.
Next, they will examine the relationship between structs and functions and learn
how to use structs as arguments to functions. Finally, students will explore ways to
create and use an array of structs in an application.
Objectives
In this chapter, the student will:
• Learn about records (structs)
• Examine various operations on a struct
• Explore ways to manipulate data using a struct
• Learn about the relationship between a struct and functions
• Discover how arrays are used in a struct
• Learn how to create an array of struct items
Teaching Tips
Records (structs)
1. Define the C++ struct data type and describe why it is useful in programming.
Discuss how previous programming examples and projects that used parallel
Teaching
arrays or vectors might be simplified by using a struct to hold related
Tip
information.
3. Using the examples in this section, explain how to define a struct type and then
declare variables of that type.
1. Explain how to access the members of a struct using the C++ member access
operator.
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-3
2. Use the code snippets in this section to illustrate how to assign values to struct
members.
Mention that the struct and class data types both use the member access
operator. Spend a few minutes discussing the history of the struct data type
and how it relates to C++ classes and object-oriented programming. Note that the
struct is a precursor to the class data type. Explain that the struct was
introduced in C to provide the ability to group heterogeneous data members
together and, for the purposes of this chapter, is used in that manner as well.
Teaching However, in C++, a struct has the same ability as a class to group data and
Tip
operations into one data type. In fact, a struct in C++ is interchangeable with
a class, with a couple of exceptions. By default, access to a struct from
outside the struct is public, whereas access to a class from outside the
class is private by default. The importance of this will be discussed later in the
text. Memory management is also handled differently for structs and
classes.
Quick Quiz 1
1. True or False: A struct is typically a homogenous data structure.
Answer: False
4. True or False: A struct is typically defined before the definitions of all the functions
in a program.
Answer: True
Assignment
1. Explain that the values of one struct variable are copied into another struct
variable of the same type using one assignment statement. Note that this is equivalent to
assigning each member variable individually.
Ask your students why they think assignment operations are permitted on
Teaching
struct types, but not relational operations. Discuss the issue of determining
Tip
how to compare a data type that consists of other varying data types.
Input/Output
1. Note that unlike an array, aggregate input and output operations are not allowed on
structs.
Mention that the stream and the relational operators can be overloaded to provide
Teaching
the proper functionality for a struct type and, in fact, that this is a standard
Tip
technique used by C++ programmers.
2. Illustrate parameter passing with structs using the code snippets in this section.
1. Using Table 9-1, discuss the similarities and differences between structs and arrays.
Spend a few minutes comparing the aggregate operations that are allowed on
Teaching structs and arrays. What might account for the differences? Use your previous
Tip exposition on the history of structs and memory management to facilitate this
discussion.
Arrays in structs
2. Using Figure 9-5, discuss situations in which creating a struct type with an array as a
member might be useful. In particular, discuss its usefulness in applications such as the
sequential search algorithm.
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-5
structs in Arrays
1. Discuss how structs can be used as array elements to organize and process data
efficiently.
Emphasize that using a structured data type, such as a struct or class, as the
Teaching element type of an array is a common technique. Using the vector class as an
Tip example, reiterate that object-oriented languages typically have containers such
as list or array types that in turn store objects of any type.
1. Discuss how structs can be nested within other structs as a means of organizing
related data.
2. Using the employee record in Figure 9-8, illustrate how to reorganize a large amount of
related information with nested structs.
3. Encourage your students to step through the “Sales Data Analysis” Programming
Example at the end of the chapter to consolidate the concepts discussed in this chapter.
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-6
Quick Quiz 2
1. What types of aggregate operations are allowed on structs?
Answer: assignment
3. True or False: A variable of type struct may not contain another struct.
Answer: False
Additional Projects
1. In Chapter 8, you were asked to write a program that keeps track of important birthdays.
Modify this program to store one person’s birthday information in a struct data type.
The struct should consist of two other structs: one struct to hold the person’s
first name and last name, and another to hold the date (day, month, and year). Consider
including other information as well, such as a vector of strings with a list of possible
gift ideas.
2. In Chapter 8, you were asked to write a program that listed all the capitals for countries
in a specific region of the world. Modify this program to use an array of structs to
store this information. The struct should include the capital, the country, and the
continent. You might include additional information as well, such as the languages
spoken in each capital.
C++ Programming: From Problem Analysis to Program Design, Sixth Edition 9-7
Additional Resources
1. Data Structures:
www.cplusplus.com/doc/tutorial/structures.html
2. struct (C++):
http://msdn2.microsoft.com/en-us/library/64973255.aspx
Key Terms
Member access operator: the dot (.) placed between the struct and the name of one
of its members; used to access members of a struct
struct: a collection of heterogeneous components in which the components are
accessed by the variable name of the struct, the member access operator, and the
variable name of the component
Other documents randomly have
different content
The Project Gutenberg eBook of Eighteenth
Century Waifs
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
JOHN ASHTON
AUTHOR OF
ETC., ETC.
IN ONE VOLUME.
LONDON:
AND BLACKETT, PUBLISHERS,
13, GREAT MARLBOROUGH STREET.
1887.
All Rights Reserved.
PREFACE.
JOHN ASHTON.
CONTENTS.
PAGE
A Forgotten Fanatic 1
A Fashionable Lady’s Life 17
George Barrington 31
Milton’s Bones 55
The True Story of Eugene Aram 83
Redemptioners 112
A Trip to Richmond in Surrey 131
George Robert Fitzgerald 135
Eighteenth Century Amazons 177
‘The Times’ and its Founder 203
Imprisonment for Debt 227
Jonas Hanway 254
A Holy Voyage to Ramsgate One Hundred Years Ago 278
Quacks of the Century 287
Cagliostro in London 333
Well out in the Atlantic Ocean, far west, indeed, even of the Western
Isles, stands the lonely island of St. Kilda, or Hirta, as it used to be
called, from h-Iar-tir, the Gaelic for West land, or West country. Its
rocky sides are inaccessible, except at one landing-place, at a bay on
the south-east, and it is the home and breeding-place of millions of
sea-birds, whose flesh and eggs form the main supply of food for
the inhabitants, and whose feathers, together with a few sheep and
cattle, and what little barley can be grown, or butter can be made,
pay the trifling rent required, and help to provide the bare
necessaries of civilized existence.
Lying out of the ordinary track of boats, even of yachts, it is, even
now, seldom visited, and in the last century no one except the
steward of Macleod (whose family have been the possessors of St.
Kilda for hundreds of years), who made an annual pilgrimage to
collect the rent, ever came near the place. Its loneliness was
proverbial, so much so that it was an article of faith that the arrival
of strangers brought with them a kind of influenza called boat-
cough, which was sometimes fatal. This singular disease does not
seem to be confined to St. Kilda, for Bates, in ‘The Naturalist on the
River Amazon,’ mentions certain tribes near Ega who are gradually
becoming extinct from a slow fever and cold, which attacks them
after they have been visited by civilised people. And in the ‘Cruise of
H.M.S. Galatea,’ in 1867-68, it says, ‘Tristran d’Acunha is a
remarkably healthy island; but it is a singular fact that any vessel
touching there from St. Helena invariably brings with it a disease
resembling influenza.’
This belief is amusingly illustrated in Boswell’s ‘Journal of a Tour to
the Hebrides.’ ‘This evening he (Dr. Johnson) disputed the truth of
what is said as to the people of St. Kilda catching cold whenever
strangers come. “How can there,” said he, “be a physical effect
without a physical cause?” He added, laughing, “The arrival of a ship
full of strangers would kill them; for, if one stranger gives them one
cold, two strangers must give them two colds, and so on in
proportion.” I wondered to hear him ridicule this, as he had praised
McAulay for putting it in his book,2 saying that it was manly in him
to tell a fact, however strange, if he himself believed it. They said it
was annually proved by Macleod’s steward, on whose arrival all the
inhabitants caught cold. He jocularly remarked, “The steward always
comes to demand something from them, and so they fall a-
coughing. I suppose the people in Skye all take a cold when——”
(naming a certain person) “comes.” They said he only came in
summer. Johnson—“That is out of tenderness to you. Bad weather
and he at the same time would be too much.”’
The first printed account of this poor lonely island is, probably, in a
little book by Donald Monro, High Dean of the Isles,3 1594. He there
says, ‘The inhabitants therof ar simple poor people, scarce learnit in
aney religion, but McCloyd of Herray,4 his stewart, or he quhom he
deputs in sic office, sailes anes in the zeir ther at midsummer, with
some chaplaine to baptize bairns ther, and if they want5 a chaplaine,
they baptize their bairns themselfes.’
Of the three chapels, one only seems to have been used, and this,
not being large enough to accommodate the islanders, the whole of
the inhabitants would assemble, on every Sunday morning, in the
churchyard, and there devoutly say the Lord’s Prayer, the Creed, and
the Ten Commandments. This form of worship was simple enough;
but it seems to have been of recent introduction—i.e., about the
beginning of the seventeenth century; when, somehow or other,
there was a man upon the island who passed for a Roman Catholic
priest, but who was so ignorant that he did not know the Lord’s
Prayer, the Creed, or the Decalogue correctly; and, consequently, he
taught the poor people an incorrect version, but to him they owed
the crucifix, and the observance of the Holy-days before mentioned,
and with this teacher they were content until the year 1641, when
one Coll McDonald, or Ketoch, fled from Ireland, and, with a few
men, landed at St. Kilda, where he lived in amity with the
inhabitants for nearly a year. He rebuked the so-called priest for his
ignorance, and he taught the poor simple folk the correct version of
the text of their very primitive worship—in fine, he was considered
so far superior to the priest, that the natives would fain have
deposed the latter; but this McDonald would not suffer.
Martin Martin,6 writing in 1698, describes the happy condition of the
islanders at that date. ‘The Inhabitants of St. Kilda are much happier
than the generality of Mankind, as being almost the only People in
the World who feel the sweetness of true Liberty: What the
Condition of the People in the Golden Age is feign’d by the Poets to
be, that theirs really is; I mean, in Innocency and Simplicity, Purity,
Mutual Love, and Cordial Friendship, free from solicitous Cares and
anxious Covetousness; from Envy, Deceit, and Dissimulation; from
Ambition and Pride, and the Consequences that attend them. They
are altogether ignorant of the Vices of Foreigners, and governed by
the Dictates of Reason and Christianity, as it was first delivered to
them by those Heroick Souls whose Zeal moved them to undergo
danger and trouble, to plant Religion here in one of the remotest
Corners of the World.’
This Eden, however, was doomed to have its Serpent, and these
simple folk were fated to be led into error by a man who seems to
have been physically above the average of the islanders, for he is
described as ‘a Comely, well-proportioned fellow, Red-hair’d, and
exceeding all the Inhabitants of St. Kilda in Strength, Climbing, &c.’
Naturally he was illiterate, for the means of culture were altogether
lacking in that lonely isle; but he was above his fellows, inasmuch as
he was a poet, and, moreover, he claimed to have the gift of ‘second
sight,’ a pretension which would naturally cause him to be looked up
to by these Gaelic islanders. These qualifications which Roderick (for
such was his name) claimed, naturally pointed to his becoming a
leader of some sort; and he seems to have entered upon his
vocation early in life, for, when we first hear of him in his public
capacity, he was but eighteen years of age.
We have read how strictly the islands kept the Sabbath, and
Roderick seems to have been the first to break through their
customs—by going fishing on that day. As, according to all moral
ethics, something dreadful will surely overtake the Sabbath breaker,
it is comforting to know that Roderick formed no exception to the
rule. One Sunday he committed the heinous and, hitherto, unknown
sin of fishing—and, on his return, he declared that, as he was
coming home, a ‘Man, dressed in a Cloak and Hat,’ suddenly
appeared in the road before him. Needless to say, this apparition
frightened him, and he fell upon his face before the supernatural
being, but the Man desired him not to be afraid, for he was John the
Baptist, who had come specially from Heaven, the bearer of good
tidings to the inhabitants of St. Kilda, and with a divine commission
to instruct Roderick in religious matters, which instruction he was to
impart to his neighbours for their spiritual welfare.
He kept up his connection with St. John, and used to assert that
every night, when the people were assembled, he heard a voice,
saying, ‘Come you out, and then he lost all control over himself, and
was constrained to go. Then would the Baptist meet him, and
instruct him in what he was to say to the people. St. John evidently
expected his disciple to exercise all his intelligence, for he would only
say his message once, and never could be got to repeat it. On one
occasion, Roderick could not understand it, or hardly remember a
sentence; so he naturally inquired of the Saint how he was to
behave. He got no comfort, however, only a brusque, ‘Go, you have
it,’ with which he was fain to be content, and, wonderful to relate, on
his return to his flock, he remembered every word he had been told,
and could retail it fluently—but, as a rule, his discourses were
discursive, and apt to send his auditors to sleep.
It was very simple: the husband hid himself until he judged proper
to appear—confronted the guilty man—spoke burning words of
reproof to him—thoroughly disorganised him, and brought him very
low—made him beg his pardon, and promise he would never so sin
again. But although a hollow peace was patched up between them,
and the injured husband even gave the greatest sign of friendship
possible, according to their notions (i.e., taking Roderick’s place as
sponsor at the baptism of one of his own children), yet the story
leaked out. The Prophet’s father plainly and openly told him he was
a deceiver, and would come to a bad end; and the thinking portion
of the community began to have serious doubts of the Divine origin
of his mission.
These doubts were further confirmed by one or two little facts which
led the people to somewhat distrust his infallibility, especially in one
case in which his cousin-german Lewis was concerned. This man
had an ewe which had brought forth three lambs at one time, and
these wicked sheep actually browsed upon the sacred bush! Of
course we know the Baptist had decreed their slaughter, and Lewis
was promptly reminded of the fact—but he did not see it in that
light. His heart was hard, and his sheep were dear to him. He
argued that, from his point of view, it was unreasonable to kill so
many animals, and inflict such serious damage to their proprietor, for
so trivial a fault—and, besides, he would not. Of course there was
nothing to be done with such an hardened sinner but to carry out
the law, and excommunicate him; which was accordingly done—with
the usual result. The poor simple folk, in their faith, looked for a
speedy and awful judgment to fall upon Lewis and his sheep.
And then they bethought them that, if it were their own case, they
might as well treat the matter as Lewis had done—seeing he was
none the worse, and four sheep to the good; and so his authority
over them gradually grew laxer and laxer: and, when the steward
paid his annual visit in 1697, they denounced Roderick as an
impostor, and expressed contrition for their own back-slidings.
The chaplain who accompanied the steward, and who was sent over
from Harris by Macleod, purposely to look into this matter, made the
Prophet publicly proclaim himself an impostor, compelled him to
commence with his own hands the destruction of the enclosure
round the sacred bush, and scatter the stones broadcast—and,
finally, the steward, whose word was absolute law to these poor
people, took him away, never to return. The poor credulous dupes,
on being reproved for so easily complying to this impostor, with one
voice answered that what they did was unaccountable; but, seeing
one of their own number and stamp in all respects endued, as they
fancied, with a powerful faculty of preaching so fluently and
frequently, and pretending to converse with John the Baptist, they
were induced to believe in his mission from Heaven, and therefore
complied with his commands without dispute.
Of his ultimate fate nothing is known, the last record of him being
that, after having been taken to Harris, he was brought before the
awful Macleod, to be judged, ‘who, being informed of this Fellow’s
Impostures, did forbid him from that time forward to Preach any
more on pain of Death. This was a great mortification, as well as
disappointment, to the Impostor, who was possessed with a fancy
that Mack-Leod would hear him preach, and expected no less than
to persuade him to become one of his Proselytes, as he has since
confessed.’ He was sent to Skye, where he made public recantation
of his errors, and confessed in several churches that it was the Devil,
and not St. John, with whom he conversed—and, arguing from that
fact, he probably was docile, and lived the remainder of his life in
Skye—a harmless lunatic.
‘I lie in Bed till Noon, dress all the Afternoon, Dine in the Evening,
and Play at Cards till Midnight.’
‘In Chit-Chat.’
testbankdeal.com