Chapter 9 Flashcards

1
Q

True or False:
You can declare struct variables when you define a struct

A

True

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

True or False:
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
3
Q

True or False:
To access a structure member (component), you use the struct variable name together with the member name; these names are separated by a period.

A

True

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

True or False:
You can use an assignment statement to copy the contents of one struct to another struct of the same type

A

True

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

True or False:
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
6
Q

True or False:
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
7
Q

True or False:
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
8
Q

True or False:
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
9
Q

True or False:
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
10
Q

A struct is typically a _______ data structure

A

heterogeneous

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

The components of a struct are called the ___________ of the struct

A

members

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

Which of the following struct definitions is correct in C++

A

struct studentType
{
int ID;
};

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

rectangleData myRectangle;

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

Typically, in a program, a struct is defined ________ in the program

A

before the definitions of all the functions

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

An array name and index are separated using

A

square brackets

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

The syntax for accessing a struct member is structVariableName_________

A

.memberName

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

Consider the following statements
struct rectangleData
{
double length;
double width;
double area;
double perimeter;
};

rectangleData bigRect;
Which fo the following statements correctly initializes the component length of bigRect

A

bigRect.length = 10;

18
Q

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

A

.(dot)

19
Q

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&raquo_space; bigRect.length;

20
Q

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

person2 = person1;

21
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

student1.ID = student3.ID;

22
Q

You can assign the value of one struct variable to another struct variable of ________ type.

A

the same

23
Q

To compare struct variables, you compare them _______

A

member-wise

24
Q

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.length == smallRect.width)

25
Q

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&raquo_space; circle.radius;

26
Q

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

cout &laquo_space;bigRect.length;

27
Q

A struct variable can be passed as a parameter _______

A

either by value or by reference

28
Q

Which of the following aggregate operations can be executed on array variables?

A

Parameter passing by reference

29
Q

Which of the following is an allowable aggregate operation on a struct?

A

Assignment

30
Q

A list has two items associated with it:

A

the values and the length

31
Q

Consider the following function prototype:
int seqSearch(const listType& list, int searchItem);

The actual parameter cannot be modified by ______

A

list

32
Q

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 an array of structs

33
Q

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

for (int j = 0; j < 25; j++)
applianceList.cost[j] = 0;

34
Q

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

supplierType

35
Q

A struct is a(n) ___________, not a declaration.

A

definition

36
Q

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;
};

A

5

37
Q

Memory is allocated for struct variables only when you _____ them.

A

declare

38
Q

Arrays are passed by __________ only.

A

reference

39
Q

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:

A

listType intList;

40
Q

If a variable is passed by __________, then when the formal parameter changes, the actual parameter also changes.

A

reference