CSC102 Ch 9 Quiz – Flashcards
Unlock all answers in this set
Unlock answersquestion
T/F? A function can return a value of the type array.
answer
False
question
T/F? A function can return a value of the type struct.
answer
True
question
A list has two items associated with it: ____.
answer
the values and the length
question
A struct is a(n) ____________________, not a declaration.
answer
definition
question
A struct is typically a ____ data structure.
answer
heterogeneous
question
A struct variable can be passed as a parameter ____.
answer
either by value or by reference
question
T/F? Aggregate input/output operations are allowed on a struct variable.
answer
False
question
An array name and index are separated using ____.
answer
square brackets
question
Arrays are passed by ____________________ only.
answer
reference
question
Consider the following function prototype: int seqSearch(const listType& list, int searchItem); The actual parameter cannot be modified by ____. a. list b. seqSearch c. searchItem d. listType
answer
list
question
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 * circle.radius * radius; b. cin >> circle.radius; c. cin >> circle.radius; circle.area = 3.14 * radius * radius; d. cin >> circle;
answer
cin >> circle.radius;
question
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 = person4; c. person2 = person3; d. person2 = person1;
answer
person2 = person1;
question
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.length = 10; b. bigRect[0]= 10 c. bigRect = {10}; d. length[0]= 10
answer
bigRect.length = 10;
question
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
cin >> bigRect.length;
question
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 == smallRect.width) d. if (bigRect.length == width)
answer
if (bigRect.length == smallRect.width)
question
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 << length; c. cout << bigRect; d. cout << bigRect.length;
answer
cout << bigRect.length;
question
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. student1.ID = student3.ID; b. student2.ID = ID; c. student2 = student3; d. student1 = student4;
answer
student1.ID = student3.ID;
question
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 of arrays. c. It is an array of structs. d. It is a struct.
answer
It is an array of structs.
question
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[25] = 0; b. for (int j = 0; j < 25; j++) applianceList[j].cost = 0; c. for (int j = 1; j < 25; j++) applianceList.cost[j] = 0; d. applianceList.cost = 0;
answer
for (int j = 0; j < 25; j++) applianceList[j].cost = 0;
question
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. supplierType c. struct d. paintType
answer
supplierType
question
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;
question
Consider the following struct definition: struct rectangleData { double length; double width; double area; double perimeter; }; Which of the following variable declarations is correct? a. rectangleData myRectangle; b. struct rectangleData(); c. rectangle rectangleData; d. rectangleData rectangle = new rectangleData();
answer
rectangleData myRectangle;
question
T/F? Data in a struct variable must be read one member at a time.
answer
True
question
If a variable is passed by ____________________, then when the formal parameter changes, the actual parameter also changes.
answer
reference
question
In C++, the ____ symbol is an operator, called the member access operator.
answer
.(dot)
question
T/F? In structs, you access a component by using the struct name together with the relative position of the component.
answer
False
question
Memory is allocated for struct variables only when you ____________________ them.
answer
declare
question
T/F? Relational operations can be used on struct variables.
answer
False
question
The components of a struct are called the ____ of the struct.
answer
members
question
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
five
question
The syntax for accessing a struct member is structVariableName____.
answer
.memberName
question
To compare struct variables, you compare them ____.
answer
member-wise
question
Typically, in a program, a struct is defined ____ in the program.
answer
before the definitions of all the functions
question
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
Parameter passing by reference
question
Which of the following is an allowable aggregate operation on a struct? a. Arithmetic b. Assignment c. Input/output d. Comparison
answer
Assignment
question
Which of the following struct definitions is correct in C++? a. struct studentType { int ID = 1; }; b. struct studentType { int ID; }; c. int struct studentType { ID; } d. struct studentType { string name; int ID; double gpa; }
answer
struct studentType { int ID; };
question
You can assign the value of one struct variable to another struct variable of ____ type.
answer
the same
question
T/F? You can declare struct variables when you define a struct.
answer
True
question
T/F? You can use an assignment statement to copy the contents of one struct into another struct of the same type.
answer
True
question
T/F? 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).
answer
True