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://testbankfan.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-malik-solutions-manual/
We believe these products will be a great fit for you. Click
the link to download now, or visit testbankfan.com
to discover even more!
https://testbankfan.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-malik-test-bank/
https://testbankfan.com/product/c-programming-from-problem-
analysis-to-program-design-7th-edition-malik-solutions-manual/
https://testbankfan.com/product/c-programming-from-problem-
analysis-to-program-design-8th-edition-malik-solutions-manual/
https://testbankfan.com/product/biology-now-2nd-edition-houtman-
test-bank/
Intermediate Algebra For College Students 10th Edition
Angel Test Bank
https://testbankfan.com/product/intermediate-algebra-for-college-
students-10th-edition-angel-test-bank/
https://testbankfan.com/product/mastering-modern-psychological-
testing-theory-and-methods-1st-edition-reynolds-test-bank/
https://testbankfan.com/product/contemporary-corporate-finance-
international-edition-12th-edition-mcguigan-solutions-manual/
https://testbankfan.com/product/strategic-management-concepts-
and-cases-competitiveness-and-globalization-10th-edition-hitt-
solutions-manual/
https://testbankfan.com/product/college-physics-strategic-
approach-with-mastering-physics-2nd-edition-knight-test-bank/
Educational Psychology Theory and Practice 11th Edition
Slavin Test Bank
https://testbankfan.com/product/educational-psychology-theory-
and-practice-11th-edition-slavin-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
Random documents with unrelated
content Scribd suggests to you:
abrazó bajo la suave tibieza de las mantas. El prosiguió, hablando casi con
el aliento:
—Acabo de pasar un rato malísimo. ¿Sabes lo que soñaba?... Pues que
don Gil Tomás, enamorado de ti y creyéndome ausente, había entrado en
este cuarto á seducirte.
Precipitadamente doña Fabiana hubo de meterse un trozo de sábana en la
boca para sofocar un grito.
—¡Ignacio!—balbuceó la mujer, empavorecida—Ignacio... ¿Qué es
esto?... Yo he soñado lo mismo.
El señor Martínez empezó á temblar.
—¿Es posible?
—Sí.
En un reloj lontano sonaron las cinco. El veterinario sintió que algo
viscoso, frío, como una mano muerta, recorría su espalda. Efectivamente,
había en aquella coincidencia un soplo sobrenatural, un estremecimiento de
otra vida. Prosiguió:
—Nosotros nos hallábamos acostados aquí, tú á mi derecha, según
estamos ahora, cuando ese hombre llegó. Le encontré un poco raro: el
semblante más flaco, más amarillo; el resto del cuerpo no se distinguía
bien... parecía borroso... ¿Le soñaste tú así?...
—Lo mismo—repuso doña Fabiana, persignándose—; lo mismo...
—Entró deslizándose por entre ambos batientes de la puerta...
—Eso es.
—Y avanzó por detrás de la butaca...
—Exacto.
—Hasta detenerse á los pies del lecho de la niña...
—Exacto, justo—repetía doña Fabiana que sentía helarse su carne de
pavura.
Continuó don Ignacio:
—No dijo palabra don Gil, ni yo me incomodé en preguntarle á qué
venía, pues en su frente, como en un libro, leí su intención. De un brinco le
salí al encuentro; recuerdo que por ese lado, por la derecha, y me abalancé
sobre él.
—Es verdad. Yo le había hecho señas de que se fuera, para que tú no le
vieses, pero no me entendió.
—Luchando á brazo partido caimos los dos al suelo; mas él quedó
debajo, y yo, teniéndole bien sujeto con mis rodillas, empecé á
estrangularle. ¡Ah, qué placer, cuando le cogí por el cuello, sintieron mis
manos!... El perneaba, quería morderme, luego me pareció que vidriaba los
ojos...
Doña Fabiana interrumpió á su marido.
—Sí, sí... ¡qué espanto! Todo eso lo he visto yo... ¡lo juro!... lo he visto...
¡lo he visto, como si realmente hubiese sucedido!... Entonces fué cuando di
un grito y la niña me despertó.
—Indudablemente—repuso don Ignacio—porque yo oí ese grito y tu
figura empezó á desdibujarse hasta desaparecer.
—¿Dejaste de verme?
—Completamente; y entonces oí tu voz y desperté.
La señora de Martínez, devotamente, tornó á persignarse.
—¡Ay, Ignacio!... Tengo un miedo horrible. Yo juraría que, hace unos
instantes, el alma de don Gil Tomás ha entrado aquí.
—Creo lo mismo.
—¿Estará ese hombre enamorado de mí? Hay en todo esto como una
brujería.
—¡Quién sabe!... Tal vez...
No hablaron más y durmieron sosegadamente hasta el otro día.
A la mañana siguiente corrió por el pueblo la noticia de que el hombre
pequeñito había muerto. Sus criadas, cuando fueron á llevarle el desayuno,
le hallaron tendido en su cama, frío y blanco. Los médicos á quienes el juez,
don Niceto Olmedilla, encargó reconocer el cadáver, no hallando en éste
nada anormal, certificaron que don Gil había fallecido de un derrame
seroso. El parte facultativo añadía que la muerte debió de ocurrir aquella
madrugada, entre cuatro y cinco...
Madrid, Junio 1914.
FIN
*** END OF THE PROJECT GUTENBERG EBOOK EL MISTERIO DE
UN HOMBRE PEQUEÑITO: NOVELA ***
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.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.