Concept explainers
Mark the following statements as true or false.
All members of a struct must be of different types. (1)
A struct is a definition, not a declaration. (1)
A struct variable must be declared after the struct definition. (1)
A struct member is accessed by using the operator :. (2)
The only allowable operations on a struct are assignment and member selection. (2)
Because a struct has a finite number of components, relational operations are allowed on a struct. (2)
Some aggregate input/output operations are allowed on a struct variable. (2)
A struct variable can be passed as a parameter either by value or by reference. (4)
A function cannot return a value of the type struct. (4)
An array can be a member of a struct. (6, 7)
A member of a struct can be another struct. (8)
a)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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)
To find whether given statement is true or false.
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?
Chapter 9 Solutions
C++ Programming: From Problem Analysis to Program Design
- Why would a programmer utilize overload operators instead of normal member functions to accomplish the same tasks?arrow_forwardC++ The class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockType by adding a member variable to store the time zone called timeZone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write a test program to test your class. Header file //clockType.h, the specification file for the class clockType #ifndef H_ClockType #define H_ClockType class clockType { public: void setTime(int hours, int minutes, int seconds); //Function to set the time. //The time is set according to the parameters. //Postcondition: hr = hours; min = minutes; // sec = seconds // The function checks whether the values of // hours, minutes, and seconds are…arrow_forwardC++ True/False: a member function in a class can access all of its class's member variables, but not if the variables are private.arrow_forward
- Why would a programmer use overload operators over standard member functions to do the same objectives as a normal member function?arrow_forwardWhy would a programmer use overload operators to achieve the same job instead of regular member functions?arrow_forwardWhat do you understand by static data member and static memberfunction?arrow_forward
- C++arrow_forwardLanguage: C++ APlayer class should be derived from the TournamentMember class. It holds additional prop- erties such as number, position, number of goals scored, and whether the player is left-footed or right-footed. For each property appropriate setter (except the number of goals scored) and getter methods need to be provided as inline methods, and it should not be possible to manipulate data directly. An appropriate constructor to set all properties on creation should be provided as well as a copy constructor that creates a correct copy of a player, and a destructor. Also all construc- tors and the destructor should print a short informational message on the screen such that you can see which is being called when. Also the following methods are required: • a method which prints all the information of a player on the screen, • a method which increments the number of goals scored by a player. Add code to the files TournamentMember.h, TournamentMember.cpp, and write a testing program…arrow_forwardc++ languagearrow_forward
- What is the primary distinction between a struct and a class?arrow_forwardThe distinction between a class's static and non-static data members is as follows: Give an example of real-world application where you think a static data member would be useful.arrow_forwardIn C++, if a member of a class is private, we cannot access it outside the class, but what if the member variable is protected?arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT