C++ Programming From Problem Analysis to Program Design 8th Edition Malik Solutions Manual instant download
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Solutions Manual instant download
https://testbankdeal.com/product/c-programming-from-problem-analysis-to-
program-design-8th-edition-malik-solutions-manual/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-8th-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-6th-edition-malik-solutions-manual/
https://testbankdeal.com/product/accounting-for-decision-making-and-
control-7th-edition-zimmerman-test-bank/
https://testbankdeal.com/product/intermediate-algebra-for-college-
students-9th-edition-angel-solutions-manual/
https://testbankdeal.com/product/basic-business-statistics-12th-
edition-berenson-test-bank/
https://testbankdeal.com/product/macroeconomics-canadian-5th-edition-
mankiw-solutions-manual/
https://testbankdeal.com/product/fundamentals-of-
taxation-2017-edition-10th-edition-cruz-solutions-manual/
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 9-1
Chapter 9
Records (structs)
A Guide to this Instructor’s Manual:
We have designed this Instructor’s Manual to supplement and enhance your teaching
experience through classroom activities and a cohesive chapter summary.
This document is organized chronologically, using the same headings that you see in the
textbook. Under the headings, you will find lecture notes that summarize the section, Teacher
Tips, Classroom Activities, and Lab Activities. Pay special attention to teaching tips and
activities geared towards quizzing your students and enhancing their critical thinking skills.
In addition to this Instructor’s Manual, our Instructor’s Resources also contain PowerPoint
Presentations, Test Banks, and other supplements to aid in your teaching experience.
At a Glance
• Objectives
• Teaching Tips
• Quick Quizzes
• Additional Projects
• Additional Resources
• Key Terms
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 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
• Examine the difference between arrays and structs
• Discover how arrays are used in a struct
• Learn how to create an array of struct items
• Learn how to create structs within a struct
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.
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 9-3
1. Explain how to access the members of a struct using the C++ member access
operator.
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.
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 9-4
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.
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 9-5
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.
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.
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 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. Write a program that reads students’ names followed by their test scores. The program
should output each student’s name followed by the test scores and the relevant grade. It
should also find and print the lowest, highest, and average test score. Output the name
of the students having the highest test score.
Student data should be stored in a struct variable of type studentType, which has
four components: studentFName and studentLName of type string, testScore
of type int (testScore is between 0 and 100), and grade of type char. Suppose
that the class has 20 students. Use an array of 20 components of type studentType.
2. Write a program that lists all the capitals for countries in a specific region of the world.
Use an array of structs to store this information. The struct should include the
capital, the country, the continent, and the population. You might include additional
information as well, such as the languages spoken in each capital. Output the countries
with the smallest and largest populations.
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
C++ Programming: From Problem Analysis to Program Design, Eighth Edition 9-7
Additional Resources
1. Data Structures:
http://www.cplusplus.com/doc/tutorial/structures/
2. struct (C++):
https://msdn.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
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Discovering Diverse Content Through
Random Scribd Documents
“No,” replied Ethel, “unfortunately she isn’t!”
“She is—she’s very athletic. She made the school hockey team,
which is a big honor for a freshman. But Miss Allen made other
qualifications.”
By this time, the party had reached the gymnasium, and their
conversation was interrupted while Miss Phillips invited everybody to
dance. Before John had a chance to ask Ethel for the dance, David
Conner had claimed her, and he was forced to find another partner.
But they did not dance long, for Miss Phillips had some questions
she wished to ask the Boy Scouts. During the brief intermission that
followed, John again sought Ethel.
While he was turning over in his mind an easy way to bring the
conversation back to Marjorie, Lily approached with ice-cream and
cake.
Lily took Ethel’s place, and explained about her room-mate’s Latin.
After the young people had finished their ice-cream, Miss Phillips
asked everybody to move their chairs into a circle, so that the
conversation might become general. She asked John all sorts of
questions about the conducting of meetings, and troop affairs, and
the girls listened with interest to his replies.
“We would like a spirit of friendly rivalry between the troops,” he
said. “We might have contests in such things as signalling and knot-
tying.”
The girls exclaimed enthusiastically over the plan, and asked more
questions about the cabin.
“Do you have qualifications to join your troop like we do?” inquired
Lily.
“Except for the ghosts,” interrupted David. “Most all the boys
report that they saw something mysterious.”
“Most likely you have heard Marjorie speak of her. She’s a friend
from her town.”
“No, but I have heard Jack Wilkinson mention her. But she can’t
be a very intimate friend, for she wasn’t at the dance!”
“Good for her!” said John. “Well, I wish she was a Girl Scout. It’s
my last year at Episcopal, and if I don’t see her this year, I guess I
never will. Will you give her my regards?” he added, hesitatingly.
“Surely,” said Lily. “And what are you planning to do next year, Mr.
Hadley?”
“Tell me all about it,” said Marjorie; and Lily complied with her
request, carrying on one of those one-sided conversations about
“what he said,” that girls all love to hold with each other.
“But I didn’t tell him how soon you would be a Girl Scout,” she
concluded.
“Well, keep on studying, and it won’t be long now till the next
Latin test, and that will surely give you the chance you have been
waiting for!”
CHAPTER XIV
Now that the girls had seen the Boy Scouts’ demonstration, they
were more anxious than ever to get their own troop started. But
they did not have long to wait, for the following afternoon Miss
Phillips placed a typewritten list on the Bulletin Board in the main
hall.
“Who made it?” asked Marjorie, who was too far back in the crowd
to read the paper.
“Sophomores—Ethel Todd.
“Freshmen—Ruth Henry.
“That would be nice,” agreed Ruth, “but for the present I’m going
to be content with plain dives and long-distance swimming. Anyway,
I can swim well enough to be a First Class scout, if I pass the other
qualifications.”
“You have all seen the names of the girls on the swimming team,”
she said. “You know, too, that out of that list of eight girls, four are
already candidates for the Scouts.
“All this goes to prove,” she continued, “just what Miss Phillips and
I have always thought—the same girls go out for athletics over and
over again, and the rest of the school is content to let them do all
the work. Now what we hope the Girl Scout organization will do, is
to make interest more general.
“Of the remaining four girls on the swimming team, only one
stands high enough in her lessons to be selected as a candidate.
That girl is Ruth Henry!”
As soon as the girls had stopped clapping, Miss Allen went on with
the announcements. “The eight candidates—Dorothy Maxwell, Edith
Evans, Helen Stewart, Frances Wright, Ethel Todd, Marian Guard, Lily
Andrews, and Ruth Henry are to meet in my office to-morrow
afternoon at two o’clock to organize and to elect their Captain.”
After dinner was over, Marjorie sought Ruth. She was not jealous
of her friend’s triumph; Ruth deserved it, and she did not.
So, with genuine pleasure, she said, “I’m awfully glad you made it,
Ruth. Nobody deserves it more than you!”
Ruth bit her lip. To her, half the fun of belonging to the Girl Scouts
consisted in being able to write home and tell her parents and
friends that she had succeeded where Marjorie had failed. But she
said nothing to indicate her feelings to the other girl.
“The first thing we will do,” said Miss Allen, “is to vote for a
Captain. Then, if possible, we will invite the person you elect into the
meeting, and she can take charge, for I won’t have time myself.”
She asked Ruth to come forward and give out the paper for
voting. “Every Scout should be prepared with a pencil, but if any girl
needs one this time, I will lend her one.
“Write the name of the person you want on the paper; if there
isn’t a majority for any one candidate the first time, we will vote over
again between the two or three highest.”
But there was no cause for a second vote; Miss Phillips was
elected by an overwhelming majority. Lily was sent to the
gymnasium to tell her of the result of the election, and returned with
an invitation for the meeting to transfer its location to the
gymnasium.
In a few words, Miss Phillips thanked the girls for the honor they
had given her, and promised to live up to the Scout laws as faithfully
as she could.
Miss Phillips smiled. “Scout Andrews,” she replied, “after this when
you wish to ask a question, rise, salute me, and say ‘Captain Phillips.’
If I return the salute, then you ask your question. Now—let’s try
that!”
Lily did as she was requested, and Miss Phillips explained that the
duties of these officers were to get the girls out to the meetings,
lead the marching, conduct opening exercises, and so forth. Frances
Wright was elected patrol leader and Lily Andrews was made
corporal.
“Now,” said Miss Phillips, “open your handbooks to page 44, and
you will see the different ceremonies to be used. We will begin with
a simple one to-night.”
After she had read the instructions aloud, she blew a series of
short whistles and the girls assembled in line—with Frances at the
top, and Lily next. Lily was sent to the room next door for the flag,
and at the command of the Captain, the girls pledged allegiance.
Then they sang one stanza of “The Star-Spangled Banner,” standing
at attention. After this, led by Miss Phillips, they took the Scout oath.
With their right hands raised to their foreheads, they repeated:
“On my honor I will try
To be true to God and my country.
To help others at all times.
To obey the Scout laws.”
“No, not that,” she answered, “but each troop takes the name of a
flower—rose, daisy, violet, and so on. And each patrol takes the
name of a bird. Suppose some of you suggest the names you would
like, and we can vote upon the three most popular.”
After dues had been discussed and agreed upon, Miss Phillips said,
“I would like to suggest that we consider candidates only once a
month. It is nearly February now—and we are just starting. It would
make too much confusion if we take them in at every meeting. So I
think the best plan would be to get the list of those eligible from
Miss Allen at the end of each month, and take them in at the
following meeting.”
This suggestion was voted upon and passed.
Frances Wright rose and saluted Miss Phillips. “Captain,” she said,
“let’s wait until we get our uniforms.”
Helen Stewart’s face fell. She was one of the poorest girls in the
school—her mother was a widow, and it was about all she could
afford to do to pay the regular expenses. Helen did not know how
she would ever get her uniform.
“All right,” agreed the Captain, “but you all know you have to earn
the uniform. You aren’t allowed to write home and ask your parents
for the money. And what is more, you are supposed to make it!”
“It won’t hurt you, girls,” Miss Phillips said laughingly. “And to
encourage you,” she added, “I’ll earn mine, aside from my salary.”
“And we’ll make it a kind of race to see who can earn theirs first.
Let’s have a bank and a banker, and report each week on what we
have made.”
The girls approved of the plan, and Ethel Todd, the secretary, was
chosen banker.
“Now,” said Miss Phillips, “we will adjourn our business meeting for
Scout work. Open your handbooks to page 60; we are going over
the Tenderfoot test together.”
“Now,” continued the Captain, “let’s have some games. Next week
we’ll have military drill, but we won’t start that to-night. Let’s play
‘Boots without shoes.’ Does anybody know it?”
The girls shook their heads, and Miss Phillips requested all but
Frances to go into her office.
She explained the game to Frances, and told her to go and bring
one of the girls into the room. She returned with Lily.
“You want to belong to the Girl Scouts, don’t you, Lily?” asked
Miss Phillips, with mock solemnity.
“Yes!”
“Then will you promise to do as I do, but to say just what I tell
you to say?”
“I promise.”
“But that isn’t right!” protested Miss Phillips. “We’ll try over again.”
Miss Phillips sent her for the next girl, and they continued until all
the girls were initiated.
Before they separated for the evening, Miss Phillips taught the
girls the Scout yell—
“A-M-E-R-I-C-A
GIRL SCOUTS—GIRL SCOUTS—U.S.A”
and they yelled it joyfully, adding first “Miss Allen’s, Miss Allen’s,” on
the end, and then giving it over again in honor of Miss Phillips.
Lily ran up to find Marjorie, who had spent the first Friday evening
since Pledge-Day in her own room. Both girls were glad that there
was no secrecy about the Girl Scout meeting, which would prevent
them from discussing it together.
Ruth went over to her own room with equal haste, joyfully
anticipating the letter she would write to the folks at home to tell
them of her good fortune.
CHAPTER XV
“All the girls have handed in enough money for the khaki and
buttons, Captain,” Ethel Todd announced, after she had given the
usual salute. “And some have turned in more than was required.
Shall I give that to the treasurer?”
“No,” answered Miss Phillips, “we will keep up our banking system,
so that each girl can always have money on hand to purchase the
necessary equipment. Now,” she continued, turning to the troop, “I
want reports on how the individual Girl Scouts earned their money.”
All the girls agreed that the experience had been fun; even Lily
admitted that she did not mind it after she had once started.
“And what did you do, Captain Phillips?” she asked.
“Girls,” said the Captain, “I am going into the city to-morrow, and
I will order the uniforms—the kind that come cut out ready to sew.
Then we ought to receive them before next Saturday, and if we do,
we can meet up in the sewing-room and give up the day to making
them.”
“The following Saturday, I hope. You see the marks come out the
next Monday, and the Gym team will be selected; so new girls will be
eligible to the troop after that. And I want one hike by ourselves—as
a reward for the good work you have done.”
“How many new girls do you think we shall have?” asked Marian.
Ruth looked annoyed. Half the fun of being a Girl Scout was the
publicity of it—the fact that she was one of the eight distinguished
members—that she belonged to something Marjorie could not join.
“As soon as we get more girls into the troop,” announced Captain
Phillips, “we will give a play, to earn enough money to pay for our
camping trip this summer.”
The girls were so interested that Miss Phillips was forced to go into
details about the plans; they talked such a long time that it was
necessary to adjourn without the customary games.
Just as she was gathering her books into a neat pile for the night,
the door opened and Lily came in. She was full of the plans for the
hike, the play, and the camp; and she poured her news into
Marjorie’s eager ears.
When she stopped a moment for breath, the other girl exclaimed,
“I simply must make it! I’d love to be in the play, and go camping!
Just think of the fun! Of course, Miss Phillips will go with you this
summer?”
Just as she rose from her seat to hand in her paper, a messenger
entered from the office.
“Miss White, here is a telegram for you,” she said, handing her a
yellow envelope.
Ruth stood still, and the messenger withdrew. As Miss White read
the telegram, her face grew pale.
“What is it, Miss White? Oh, I hope nothing is wrong?” said Ruth.
Miss White smiled sadly, and handed Ruth the key. “You are a
dear, good girl, Ruth,” she said, as she opened the door.
Ruth began to straighten the papers, which the girls had piled one
by one on top of the teacher’s desk. As she picked them up, one
from the top of the pile fell to the floor. She stooped to pick it up. It
was Marjorie Wilkinson’s!
Suddenly, Ruth thought of the other girl’s house-party, and the
dance which she had witnessed through the lighted windows; she
remembered Marjorie’s indifference during the days that followed
her pledging to the sorority; and heard Lily exclaim over again that if
her room-mate made 90% in this Latin test, she would be a Girl
Scout.
This was the opportunity she had been waiting for; if she had
schemed and planned for it, it could not have been more perfect. If
she let this chance go by, she would probably never have another
like it. She would pay Marjorie back for what she had done in the
past.
Once she thought she heard a sound at the door; she quickly
dropped her pen, and pretended to straighten the papers. But no
one came in, and she finished her work of deceit. To the casual
observer, Marjorie’s paper looked no different; but to the Latin
student, it proved to be like the poor twisted poem of “Father
William” in “Alice in Wonderland,” “wrong from beginning to end.”
While she was locking Miss White’s desk, the risk of her act
occurred to her. What if the teacher should decide to return the
papers to the girls, contrary to her usual custom? What if Marjorie
should not be satisfied with her mark, and should ask Miss White to
go over the paper with her?
But it was too late now to think of the danger; the deed was done,
and she must take the consequences.
She decided on the whole that she would stand less chance of
detection if the teacher took the papers home with her to mark.
Accordingly, she unlocked the desk again and took out the pile, and,
leaving everything in good order, went over to Miss White’s room.
“Thank you, Ruth, you are so thoughtful. Here—I will put them in
my suitcase,” she said, taking them from the girl.
“Now I think I’m ready,” she concluded. “Here is a sweater for you
to wear to the station—and I guess your hands won’t get lost in
these gloves.”
After she came back from the station, she began to dress for
dinner, but said nothing to Ethel of the incident, lest in some way it
might throw suspicion on her.
All the rest of the week Marjorie felt the satisfaction of a person
whose task was well done. She looked eagerly forward to Monday
when her success would be announced, and the troop would claim
her as a candidate. She knew her Tenderfoot test already, and she
thought constantly of possible ways to earn money for her uniform.
The Friday evening before the term closed, ΦΑΒ girls met for the
last time. Two Juniors who had been chosen for the gym team, and
who were practically sure of making the Girl Scout troop, resigned;
and with only six members left, the sorority had to disband.
As Marjorie sat alone in her room that evening while Lily attended
the Scout meeting, she occupied herself by writing a long letter
home. And in this letter, she told her mother to expect a splendid
report from the school—with a mark in Latin that she would be
proud of. “And I think,” she concluded, “that this is the last Friday
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
testbankdeal.com