BTE 320 Ch. 9 (structs) Flashcards

(34 cards)

1
Q

A function can return a value of the type struct

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Aggregate input/output operations are allowed on a struct variable

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

You can decalre struct variables when you define a struct

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In structs, you access a component by using the struct name together with the relative position of the component

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You can use an assignment statement to copy the contents of one struct into another struct of the same type

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Relational operations can be used on struct variables

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Data in a struct variable must be read one member at a time

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A function can return a value of the type array

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
struct rectangleData
{
 double length;
 double width;
 double area;
 double perimeter;
};
rectangleData bigRect;

Which of the following statements is valid in C++?

a. cin&raquo_space; bigRect.length&raquo_space; width;
b. cout &laquo_space;bigRect.length;
c. cout &laquo_space;bigRect;
d. cout &laquo_space;length;

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. A struct is typically a ____ data structure.
    a. simple b. dynamic
    c. heterogeneous d. linked
A

c. heterogenenous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The components of a struct are called the ____ of the struct.

a. variables b. identifiers
c. elements d. members

A

b. identifiers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
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

a.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
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();

A

c. rectangleData myRectangle;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

b. before the definitions of all the functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

An array name and index are separated using ____.

a. curly brackets b. square brackets
c. a dot d. a comma

A

b. square brackets

17
Q

The syntax for accessing a struct member is structVariableName____.

a. .memberName b. *memberName
c. [memberName] d. $memberName

A

a. .memberName

18
Q
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

A

b. bigRect.length = 10;

19
Q

In C++, the ____ symbol is an operator, called the member access operator.

a. :(colon)
b. .(dot)
c. ,(comma)
d. $ (dollar sign)

20
Q
struct rectangleData
{
 double length;
 double width;
 double area;
 double perimeter;
};
rectangleData bigRect;
Which of the following statements is valid in C++?
A

b. cin&raquo_space; bigRect.length;

21
Q
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;

A

b. person2 = person1;

22
Q
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;

A

d. student.ID = student3.ID;

23
Q

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

24
Q

To compare struct variables, you compare them ____.

a. by reference
b. by value
c. index-wise
d. member-wise

25
``` 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)
d. if (bigRect.length == smallRect.width)
26
``` 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; ```
d. cin >> circle.radius;
27
``` 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;
b. cout << bigRect.length;
28
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
d. either by value or by reference
29
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
d. parameter passing by reference
30
Which of the following is an allowable aggregate operation on a struct? a. Arithmetic b. Assignment c. Input/output d. Comparison
b. assignment
31
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
d. the values and the length
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.
c. It is an array of structs.
33
``` 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
c. list
34
``` 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;
d. for (int j = 0; j < 25; j++) | applianceList.cost[j] = 0;