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
- 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
- Either a member function or a normal function may be used to handle overloaded operators. Falsearrow_forwardTRUE or FALSE - Calling a non-constant member function on a constant object is a syntax error. Select one: a.TRUE b.FALSEarrow_forwardTrue or false The arguments passed to member functions by reference are considered as data members of class.arrow_forward
- Car Class Write a C++ program that create a class named Car that has the following private member variables: model: a string that holds the car’s model make: a string that holds the make of the car speed: an int that holds the car’s current speed In addition, the class should have the following constructor and public member functions: A constructor with two parameters that accept the car’s year mode, and make as arguments. These values should be assigned to the object’s model and make member variables. The constructor should also assign 0 to the speed member variable. Three Accessor functions (i.e., get functions) to get and return the values stored in an object’s model, make,and speed member variables respectively. A member function named accelerate that adds 5 to the speed member variable each time it is called. This function does not return any value. A member function named pressbrake that subtract 3 from the speed member variable each time it is called. In this member function,…arrow_forwardPlease help me C++ languagearrow_forwardWhat is the difference between a friend function of a class and a member function of a class? (3)arrow_forward
- Mark the following statements as true or false. The member variables of a class must be of the same type. (1) The member functions of a class must be public. (2) A class can have more than one constructor. (5) A class can have more than one destructor. (5) Both constructors and destructors can have parameters. (5)arrow_forwardAssume the definition of class houseType as given in Exercise 11. Answer the following questions. (1, 2, 3, 5, 7) a. Write the definition of the member function set so that private members are set according to the parameters. b. Write the definition of the member function print that prints the values of the data members. c. Write the definition of the constructor of the class houseType so that the private member variables are initialized to according to the parameters. d. Write a C++ statement that prints the value of the object newHouse. e. Write a C + + statement that declares an object house of type newHouse, and initializes the member variables of house to "Ranch", 3, 2, 2, 2005, 1300, 185000, and 3600.0, respectively. f. Which function members are accessors and which are mutators?arrow_forwardTwo data members: feet(int) and inches(float) Two overloaded constructors: one that takes no argument and the other that takes two arguments. Zero argument constructor initializes data members from 0 whereas two argument constructor initializes data members from the passed arguments. Two getters and two setters corresponding to two data members. A member function named toDecimal that converts a distance to decimal, e.g., if a distance equals 2 feet and 6 inches then it would become 2.5 in decimal. A member function named toString that returns a string representation of a distance, e.g., if a distance equals 2 feet and 6 inches then the corresponding string representation should be 2’-6”. by using C++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