BTE320 Chapter 9
36. The following statement defines a struct houseType with a total of ____________________ member(s). struct houseType { string style; int numOfBedrooms; int numOfBathrooms; int numOfCarsGarage; int yearBuilt; };
ANSWER: 5
2. In structs, you access a component by using the struct name together with the relative position of the component. a. True b. False
ANSWER: False
5. Relational operations can be used on struct variables. a. True b. False
ANSWER: False
7. A function can return a value of the type array. a. True b. False
ANSWER: False
9. Aggregate input/output operations are allowed on a struct variable. a. True b. False
ANSWER: False
1. You can declare struct variables when you define a struct. a. True b. False
ANSWER: True
3. 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). a. True b. False
ANSWER: True
4. You can use an assignment statement to copy the contents of one struct into another struct of the same type. a. True b. False
ANSWER: True
6. Data in a struct variable must be read one member at a time. a. True b. False
ANSWER: True
8. A function can return a value of the type struct. a. True b. False
ANSWER: True
12. 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; };
ANSWER: a
16. The syntax for accessing a struct member is structVariableName____. a. .memberName b. *memberName c. [memberName] d. $memberName
ANSWER: a
14. 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
ANSWER: b
15. An array name and index are separated using ____. a. curly brackets b. square brackets c. a dot d. a comma
ANSWER: b
17. 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
ANSWER: b
18. In C++, the ____ symbol is an operator, called the member access operator. a. :(colon) b. .(dot) c. ,(comma) d. $ (dollar sign)
ANSWER: b
19. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect; b. cin >> bigRect.length; c. perimeter = 2 * (length + width); d. area = length * width;
ANSWER: b
20. Consider the following statements: 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;
ANSWER: b
22. 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
ANSWER: b
26. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect.length >> width; b. cout << bigRect.length; c. cout << bigRect; d. cout << length;
ANSWER: b
29. Which of the following is an allowable aggregate operation on a struct? a. Arithmetic b. Assignment c. Input/output d. Comparison
ANSWER: b
10. A struct is typically a ____ data structure. a. simple b. dynamic c. heterogeneous d. linked
ANSWER: c
13. 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();
ANSWER: c
31. Consider the following function prototype: int seqSearch(const listType& list, int searchItem); The actual parameter cannot be modified by ____. a. seqSearch b. listType c. list d. searchItem
ANSWER: c
32. Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following best describes applianceList? a. It is a multidimensional array. b. It is a struct. c. It is an array of structs. d. It is a struct of arrays.
ANSWER: c
34. Consider the following statements: struct supplierType { string name; int supplierID; }; struct paintType { supplierType supplier; string color; string paintID; }; paintType paint; What is the data type of paint.supplier? a. string b. paintType c. supplierType d. struct
ANSWER: c
11. The components of a struct are called the ____ of the struct. a. variables b. identifiers c. elements d. members
ANSWER: d
21. 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;
ANSWER: d
23. To compare struct variables, you compare them ____. a. by reference b. by value c. index-wise d. member-wise
ANSWER: d
24. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; rectangleData smallRect; Which of the following statements is legal in C++? a. if (bigRect == smallRect) b. if (bigRect != smallRect) c. if (bigRect.length == width) d. if (bigRect.length == smallRect.width)
ANSWER: d
25. Consider the following statements. struct circleData { double radius; double area; double circumference; }; circleData circle; Which of the following statements is valid in C++? a. cin >> circle.radius; circle.area = 3.14 * radius * radius; b. cin >> circle.radius; circle.area = 3.14 * circle.radius * radius; c. cin >> circle; d. cin >> circle.radius;
ANSWER: d
27. A struct variable can be passed as a parameter ____. a. only by const b. only by reference c. only by value d. either by value or by reference
ANSWER: d
28. Which of the following aggregate operations can be executed on array variables? a. Arithmetic b. Assignment c. Function returning a value d. Parameter passing by reference
ANSWER: d
30. A list has two items associated with it: ____. a. the length and the references b. the values and the references c. the indexes and the length d. the values and the length
ANSWER: d
33. Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following statements correctly initializes the cost of each appliance to 0? a. applianceList.cost = 0; b. applianceList.cost[25] = 0; c. for (int j = 1; j < 25; j++) applianceList.cost[j] = 0; d. for (int j = 0; j < 25; j++) applianceList.cost[j] = 0;
ANSWER: d
37. Memory is allocated for struct variables only when you ____________________ them.
ANSWER: declare
35. A struct is a(n) ____________________, not a declaration.
ANSWER: definition
39. Consider the following struct definition: const int ARRAY_SIZE = 1000; struct listType { int listElem[ARRAY_SIZE]; int listLength; }; The statement that declares intList to be a struct variable of type listType is ____________________.
ANSWER: listType intList;
38. Arrays are passed by ____________________ only.
ANSWER: reference
40. If a variable is passed by ____________________, then when the formal parameter changes, the actual parameter also changes.
ANSWER: reference