C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 1TF

Mark the following statements as true or false.

  1. All members of a struct must be of different types. (1)

  2. A struct is a definition, not a declaration. (1)

  3. A struct variable must be declared after the struct definition. (1)

  4. A struct member is accessed by using the operator :. (2)

  5. The only allowable operations on a struct are assignment and member selection. (2)

  6. Because a struct has a finite number of components, relational operations are allowed on a struct. (2)

  7. Some aggregate input/output operations are allowed on a struct variable. (2)

  8. A struct variable can be passed as a parameter either by value or by reference. (4)

  9. A function cannot return a value of the type struct. (4)

  10. An array can be a member of a struct. (6, 7)

  11. A member of a struct can be another struct. (8)

a)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

False

Explanation of Solution

Given Information: All members of a struct must be of different types.

Explanation:In the C++ programming language, the struct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components. These components can be of different types. It means that a struct has both same type and different type component/members.

Conclusion:All Component/members of a struct can be of same types and can be of different types.Hence, the given statement is false.

b)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

true

Explanation of Solution

Given Information: Astruct is a definition, not a declaration.

Explanation:In the C++ programming language, struct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components of both same and different types.To use the struct, an instance/pointer/variable is declared and memory is allocated for the instance/pointer/variable of thestruct when they declared.

Conclusion: Astruct is used to define a structure. Hence, the given statement is true.

c)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

False.

Explanation of Solution

Given Information: A structvariable must be declared after the struct definition.

Explanation:In the C++ programming language, struct is a reserved keyword. This keyword is used to define a structure. To use the struct, an instance/pointer/variable is declared and memory is allocated for the instance/pointer/variableof the struct when they declared.

Conclusion: An instance/pointer/variable of the structcan be declared when required.

Hence, the given statement is false.

d)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

false

Explanation of Solution

Given Information: A structmember is accessed by using the operator (:).

Explanation:In the C++ programming language, the dot (.) operator is used to access the member of a struct. This operator is also known as member access operator.

Conclusion: Toaccess the member of a struct a member access operator (.) is used.

Hence, the given statement is false.

e)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

true

Explanation of Solution

Given Information: The only allowable operations on a struct are assignment and member selection.

Explanation:In the C++ programming language, Theassignment and member access operations are the two built in operations for astruct. The arithmetic and relational operations are not allowed on struct.

Conclusion: The assignment and member selectionoperations are the only allowableoperations on a struct.

Hence, the given statement is true.

f)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

false

Explanation of Solution

Given information: As a struct has a finite number of components, therefore, relational operations are allowed on a struct.

Explanation:In the C++ programming language, Thestruct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components. These components can be of different types. It means that a struct has both same type and different type component/members.The assignment and member access operations are the two built in operations for a struct. The arithmetic and relational operations are not allowed on struct.

Conclusion: The relational operations are not allowed on a struct.

Hence, the given statement is false.

g)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

False

Explanation of Solution

Given Information: Some aggregate input/output operations are allowed on a struct variable.

Explanation:In the C++ programming language, Thestruct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components. These components can be of different types. It means that a struct has both same type and different type component/members. The assignment and member access operations are the two built in operations for a struct. The arithmetic and relational or other aggregate input/output operations are not allowed on struct.

Conclusion: The aggregate input/output operations are not allowed on a struct.

Hence, the given statement is false.

h)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

True

Explanation of Solution

Given Information: A struct variable can be passed as a parameter either by value or by reference.

Explanation:In the C++ programming language, struct is a reserved keywordused to define a structureof fixed number of components of same or different types. Astruct can be passed as a parameter to a functioneither by value or by reference.

Conclusion: A struct variable can be passed as a parameterto a function either by value or by reference.

Hence, the given statement is true.

i)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

False

Explanation of Solution

Given Information: A function cannot return a value of the type struct.

Explanation:In the C++ programming language, struct is a reserved keyword used to define a structure of fixed number of components of same or different types. A struct can be passed as a parameter to a function either by value or by reference. A function can also return a value of structtype.

Conclusion: A function can return a value of struct type.

Hence, the given statement is false.

j)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

True

Explanation of Solution

Given Information: An array can be a member of a struct.

Explanation:In the C++ programming language, the struct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components/members. These components can be of different types. The component/member can be of array type, struct type, integer type, float type, char type, string type, char type, or Boolean type.

Conclusion:An array can be a member of a struct.

Hence, the given statement is true.

k)

Expert Solution
Check Mark
Program Plan Intro

To find whether given statement is true or false.

Program Description Answer

true

Explanation of Solution

Given Information: A member of a struct can be another struct.

Explanation:In the C++ programming language, the struct is a reserved keyword. This keyword is used to define a structure. A structure is a collection of fixed number of components/members. These components can be of different types. The component/member can be of array type, struct type, integer type, float type, char type, string type, char type, or Boolean type.

Conclusion: A struct can be a component/member of another struct.

Hence, the given statement is true.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Why would a programmer use overload operators over standard member functions to do the same objectives as a normal member function?
Why would a programmer use overload operators to achieve the same job instead of regular member functions?
Why would a programmer utilize overload operators instead of normal member functions to accomplish the same tasks?
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY