BTE 320 Ch. 9 (structs) Flashcards
(34 cards)
A function can return a value of the type struct
True
Aggregate input/output operations are allowed on a struct variable
False
You can decalre struct variables when you define a struct
True
In structs, you access a component by using the struct name together with the relative position of the component
False
To access a structure member (component), you use the struct variable name together with the member name; these names are separated by a dot (period)
True
You can use an assignment statement to copy the contents of one struct into another struct of the same type
True
Relational operations can be used on struct variables
False
Data in a struct variable must be read one member at a time
True
A function can return a value of the type array
False
struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect;
Which of the following statements is valid in C++?
a. cin»_space; bigRect.length»_space; width;
b. cout «_space;bigRect.length;
c. cout «_space;bigRect;
d. cout «_space;length;
b
- A struct is typically a ____ data structure.
a. simple b. dynamic
c. heterogeneous d. linked
c. heterogenenous
The components of a struct are called the ____ of the struct.
a. variables b. identifiers
c. elements d. members
b. identifiers
Which of the following struct definitions is correct in C++? a. struct studentType { int ID; };
b. struct studentType { string name; int ID; double gpa; }
c. int struct studentType
{
ID;
}
d. struct studentType
{
int ID = 1;
};
a.
Consider the following struct definition: struct rectangleData { double length; double width; double area; double perimeter; }; Which of the following variable declarations is correct?
a. rectangle rectangleData;
b. struct rectangleData();
c. rectangleData myRectangle;
d. rectangleData rectangle = new rectangleData();
c. rectangleData myRectangle;
Typically, in a program, a struct is defined ____ in the program.
a. in the main function
b. before the definitions of all the functions
c. after the definitions of all the functions
d. in any function
b. before the definitions of all the functions
An array name and index are separated using ____.
a. curly brackets b. square brackets
c. a dot d. a comma
b. square brackets
The syntax for accessing a struct member is structVariableName____.
a. .memberName b. *memberName
c. [memberName] d. $memberName
a. .memberName
Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements correctly initializes the component length of bigRect?
a. bigRect = {10};
b. bigRect.length = 10;
c. length[0]= 10;
d. bigRect[0]= 10
b. bigRect.length = 10;
In C++, the ____ symbol is an operator, called the member access operator.
a. :(colon)
b. .(dot)
c. ,(comma)
d. $ (dollar sign)
b. .(dot)
struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++?
b. cin»_space; bigRect.length;
struct personalInfo { string name; int age; double height; double weight; }; struct commonInfo { string name; int age; }; personalInfo person1, person2; commonInfo person3, person4;
Which of the following statements is valid in C++?
a. person1 = person3;
b. person2 = person1;
c. person2 = person3;
d. person2 = person4;
b. person2 = person1;
Consider the following statements: struct studentType1 { string name; int ID; double gpa; }; studentType1 student1, student2; struct studentType2 { string name; int ID; double gpa; }; studentType2 student3, student4; Which of the following statements is valid in C++?
a. student2 = student3;
b. student1 = student4;
c. student2.ID = ID;
d. student1.ID = student3.ID;
d. student.ID = student3.ID;
You can assign the value of one struct variable to another struct variable of ____ type.
a. a simple data
b. the same
c. an array
d. any
b. the same
To compare struct variables, you compare them ____.
a. by reference
b. by value
c. index-wise
d. member-wise
member-wise