Ch.10 Flashcards

1
Q

A member function that allows the user of the class to change the value in a data member is known as

A

a mutation

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

Why do you want to usually make data members private in a class?

A) so that no one can use the class
B) provide information hiding
C) ensure data integrity
D) provide data abstraction
E) B, C, and D

A

ensure data integrity
provide data abstraction.
provide information hiding.

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

You specify an individual member of a struct by using

A

the dot operator

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

Given the following class definition and the following member function header, which is the correct way to output the private data?

class Person
{
public:
 void outputPerson(ostream& out);
private:
 int age;
 float weight;
 int id;
};
void outputPerson(ostream& out)
{
 //what goes here?
}
A

out << age << weight << id;

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

What is wrong with the following structure definition?
struct MyStruct
{
int size;
float weight;
}

A

missing semicolon

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

Member functions of a class

A

may be in either section

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

To assign values to a structure variable, you use the

A

assignment operator

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

A class member function that automatically initializes the data members of a class is called

A

a constructor

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

Data members or member functions of a class that are declared to be private

A

may only be accessed by members of the class

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

Given the following class definition, how could you use the constructor to assign values to an object of this class?

class CDAccount
{
public:
 CDAccount( );
 CDAccount(float interest, float newBalance);
 float getBalance( );
 float getRate( );
 void setRate(float interest);
 void setBalance(float newBalance);
private:
 float balance, rate;
};

and the following object declaration
CDAccount myAccount;

A

myAccount = CDAccount(myRate, myBalance)

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

If you design a class with private data members, and do not provide mutators and accessors, then

A
A) the class cannot be used.
B) the data cannot be changed or viewed by anyone.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Given the following class definition, how would you declare an object of the class, so that the object automatically called the default constructor?
class ItemClass
{
public:
 ItemClass( );
 ItemClass(int newSize, float newCost);
 int getSize( );
 float getCost( );
 void setSize(int newSize);
 void setCost(float newCost);
private:
 int size;
 float cost;
};
A

ItemClass myItem;

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

A data type consisting of data members and operations on those members which can be used by a programmer without knowing the implementation details of the data type is called

A

an abstract data type

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

Given the following structure definition, what is the correct way to initialize a variable called today?
struct DateType
{
int day;
int month;
int year;
}

A

DateType today = {1,1,2000,0);

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

If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?

A

myPersonClass( );

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

Given the following structure definitions, what is the correct way to print the person’s birth year?
struct DateType
{
int day;
int month;
int year;
}

struct PersonType
{
int age;
float weight;
DateType birthday;
}

PersonType person;

A

cout << person.birthday.year;

17
Q

Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age?

class Wine
{
public:
Wine( );
int getAge( );
float getCost( );
private:
int age;
float cost;
}

A

void setAge(int newAge);

18
Q

Given the following class and object declaration, how would you print out the age and cost of a bottle of wine?

class Wine
{
public:
Wine( );
int getAge( );
float getCost( );
private:
int age;
float cost;
}

Wine bottle;

A

cout << bottle.getAge( ) << bottle.getCost( );

19
Q

Which part of the ADT tells the programmer using it how to use it?

A

the interface

20
Q

In a structure definition, the identifiers declared in the braces are called

A

member names

21
Q

If you have a class with a member function called display(ostream& out), that will send the values in the class to the parameter stream, and you need to call that function from within another member function, how would you call it to print the data to the screen?

A

display(cout);

22
Q

A member function that allows the user of the class to find out the value of a private data type is called a(n) ________.

A

accessor function

23
Q

A structure variable is a collection of smaller values called ________ values

A

member

24
Q

A member function that allows the user of the class to change the value of a private data type is called a ________.

A

mutator function

25
Q

The constructor of a class that does not have any parameters is called a ________ constructor

A

default

26
Q

The keyword ________ defines a structure type definition

A

struct

27
Q

When a structure contains another structure variable as one of its members, it is known as a

A

hierarchical structure

28
Q

What can a constructor return?

A

nothing

29
Q

In the following class constructor definition, the part of the header starting with a single colon is called the ________.

BankAccount::BankAccount( ): balance(0), interest(0.0)

A

initialization section

30
Q

The name of a constructor is

A

the name of the class

31
Q

The double colon (::) is known as the ________ operator

A

scope resolution operator

32
Q

A struct variable is declared differently from a predefined type such as an int

A

FALSE

33
Q

Two different structure definitions may have the same member names

A

TRUE

34
Q

The assignment operator may not be used with objects of a class

A

False

35
Q

All constructors for a class must be private

A

FALSE

36
Q

A structure can only be passed to a function as a call-by-value parameter

A

FALSE

37
Q

A function may return a structure

A

True

38
Q

A class member function may be private

A

TRUE