Chapter 10 Flashcards

1
Q

True or False:
A class is an example of a structured data type.

A

True

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

True or False:
In C++, class is a reserved word and it defines only a data type.

A

True

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

True or False:
If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables.

A

False

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

True or False:
In C++ terminology, a class object is the same as a class instance.

A

True

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

True or False:
Given this declaration:
class myClass
{
public:
void print(); //Output the value of x;
MyClass();
private:
int x;
};
MyClass myObject;
The following statement is legal:
myObject.x = 10;

A

False

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

True or False:
If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class.

A

True

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

True or False:
If an object is created in a user program, then the object can access both the public and private members of the class.

A

False

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

True or False:
You can use arithmetic operators to perform arithmetic operations on class objects.

A

False

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

True or False:
As parameters to a function, class objects can be passed by reference only.

A

False

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

True or False:
The public members of a class must be declared before the private members.

A

False

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

The components of a class are called the ________ of the class

A

members

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

Which of the following class definitions is correct in C++?

A

class studentType
{
public:
void setData(string, double, int);
private:
string name;
};

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

If a member of a class is ________, you cannot access it outside the class.

A

private

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

A class and its members can be described graphically using a notation known as the ____ notation.

A

UML

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

The word ______ at the end of several of the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object.

A

const

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

Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class?

A

clocktype

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

Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class?

A

three

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

A __ sign in front of a member name on a UML diagram indicates that this member is a public member.

A

+

19
Q

A __ sign in front of a member name on a UML diagram indicates that this member is a protected member.

A

#

20
Q

class rectangleType
{
public:
void setLengthWidth(double x, double y);
void print() const;
double area();
double perimeter();
rectangleType();
rectangleType(double x, double y);
private:
double length;
double width;
};
Consider the accompanying class definition. Which of the following variable declarations is correct?

A

rectangleType rectangle;

21
Q

class rectangleType
{
public:
void setLengthWidth(double x, double y);
void print() const;
double area();
double perimeter();
rectangleType();
rectangleType(double x, double y);
private:
double length;
double width;
};
Consider the accompanying class definition and the declaration: rectangleType bigRect;
Which of the following statements is correct?

A

bigRect.print();

22
Q

class rectangleType
{
public:
void setLengthWidth(double x, double y);
void print() const;
double area();
double perimeter();
rectangleType();
rectangleType(double x, double y);
private:
double length;
double width;
};
Consider the accompanying class definition and the object declaration: rectangleType bigRect(14, 10);
Which of the following statements is correct?

A

bigRect.setLengthWidth(3.0, 2.0);

23
Q

In C++, the _____ is called the member access operator.

A

.(dot)

24
Q

A class object can be __________. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block.

A

automatic

25
Q

A class object can be _____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates.

A

static

26
Q

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ______ in the formal parameter declaration.

A

const

27
Q

In C++, the scope resolution operator is ___.

A

::

28
Q

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) _______ function.

A

accessor

29
Q

To guarantee that the member variables of a class are initialized, you use ____________.

A

constructors

30
Q

class secretType
{
public:
static int count;
static int z;

secretType();
secretType(int a);
void print();
static void incrementY();
private:
int x;
static int y;
}
Consider the accompanying class definition. How many constructors are present in the class definition?

A

two

31
Q

How many destructors can a class have?

A

one

32
Q

A destructor has a character ___, followed by the name of the class.

A

~(tilde)

33
Q

What does ADT stand for?

A

abstract data type

34
Q

Which of the following is true about classes and structs?

A

By default, all members of a struct are public and all members of a class are private.

35
Q

If a function of a class is static, it is declared in the class definition using the keyword static in its _________.

A

heading

36
Q

With __________ functions, the definitions of the member functions are placed in the implementation file.

A

header

37
Q

If a class object is passed by _____, the contents of the member variables of the actual parameter are copied into the corresponding member variables of the formal parameter.

A

value

38
Q

Non-static member variables of a class are called the _________ variables of the class.

A

instance

39
Q

A program or software that uses and manipulates the objects of a class is called a(n) _________ of that class

A

client

40
Q

A(n) __________ function of a class changes the values of the member variable(s) of the class.

A

mutator

41
Q

A(n) ____________ contains the definitions of the functions to implement the operations of an object.

A

implementation file

42
Q

The header file is also known as the __________.

A

interface file

43
Q

A(n) ____________ is a statement specifying the condition(s) that must be true before the function is called.

A

precondition