Deck 10: Defining Classes
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/61
Play
Full screen (f)
Deck 10: Defining Classes
1
When several items variables or variables and functions) are grouped together into a single package, that is known as ______________.
data) encapsulation
2
A member function that allows the user of the class to find out the value of a private data type is called a ___________________.
accessor function.
3
A structure can only be passed to a function as a call-by-value parameter
False
4
A structure definition ends with the closing brace and a _________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
5
A derived class is more specific than its parent, or base class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
6
All constructors for a class must be private.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
7
A function may return a structure.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
8
A member function that allows the user of the class to change the value of a private data type is called a ____________________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
9
Different class may not have member functions with the same name.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
10
The assignment operator may not be used with objects of a class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
11
A structure variable is a collection of smaller values called ____________ values
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
12
Who can access private members in a class?
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
13
Two different structure definitions may have the same member names.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
14
A struct variable is declared differently from a predefined type such as an int.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
15
The double colon ::) is known as the __________ operator.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
16
It is possible to have multiple private labels in a class definition.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
17
The keyword ________ defines a structure type definition.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
18
When a structure contains another structure variable as one of its members, it is known as a ___________________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
19
A class member function may be private.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
20
Class data members are almost always public.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
21
In the following class constructor definition, the part of the header starting with a single colon is called the ________________.
BankAccount::BankAccount): balance0), interest0.0)
BankAccount::BankAccount): balance0), interest0.0)
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
22
What is wrong with the following structure definition?
Struct MyStruct
{
Int size;
Float weight;
}
A) Nothing
B) Can not have mixed data types in a structure
C) missing semicolon
D) Braces are not needed.
Struct MyStruct
{
Int size;
Float weight;
}
A) Nothing
B) Can not have mixed data types in a structure
C) missing semicolon
D) Braces are not needed.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
23
If you have a class with a member function called displayostream& 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? ___________________________
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
24
A member function of a class should be made private
A) always
B) only if it will never be used
C) if it will only be used by other members of the class
D) never, it is illegal to make a member function private.
A) always
B) only if it will never be used
C) if it will only be used by other members of the class
D) never, it is illegal to make a member function private.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
25
A class in which modifications to the implementation appear to be invisible to the user of the class is known as _________________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
26
A member function that gets called automatically when an object of the class is declared is called a _______________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
27
In a structure definition, the identifiers declared in the braces are called
A) classes
B) structs
C) member names
D) variables
A) classes
B) structs
C) member names
D) variables
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
28
Given the following strucure 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;
B) cout << year;
C) cout << birthday.year;
D) cout << peson.year;
Struct DateType
{
Int day;
Int month;
Int year;
}
Struct PersonType
{
Int age;
Float weight;
DateType birthday;
}
PersonType person;
A) cout << person.birthday.year;
B) cout << year;
C) cout << birthday.year;
D) cout << peson.year;
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
29
C++11 allows you to have a constructor call another constructor. This feature is called _________________________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
30
When defining a class, the class should be composed of the kind of values a variable of the class can contain, and
A) member functions for that class
B) the keyword private
C) other class definitions
D) nothing else
A) member functions for that class
B) the keyword private
C) other class definitions
D) nothing else
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
31
Given the following strucure definition, what is the correct way to initialize a variable called today?
Struct DateType
{
Int day;
Int month;
Int year;
}
A) DateType today1,1,2000);
B) DateType today = 1,1,2000);
C) DateType today = {1,1,2000);
D) DateType today = {1,1,2000,0);
Struct DateType
{
Int day;
Int month;
Int year;
}
A) DateType today1,1,2000);
B) DateType today = 1,1,2000);
C) DateType today = {1,1,2000);
D) DateType today = {1,1,2000,0);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
32
The name of a constructor is _____________
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is the correct function definition header for the getAge function which is a member of the Person class?
A) int getAge);
B) int getAge)
C) int Person:getAge)
D) int Person::getAge)
A) int getAge);
B) int getAge)
C) int Person:getAge)
D) int Person::getAge)
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
34
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 outputPersonostream& out);
Private:
Int age;
Float weight;
Int id;
};
Void Person::outputPersonostream& out)
{
//what goes here?
}
A) out << person.age << person.weight << person.id;
B) out << person;
C) out << age << weight << id;
D) outputPersonperson);
Class Person
{
Public:
Void outputPersonostream& out);
Private:
Int age;
Float weight;
Int id;
};
Void Person::outputPersonostream& out)
{
//what goes here?
}
A) out << person.age << person.weight << person.id;
B) out << person;
C) out << age << weight << id;
D) outputPersonperson);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
35
You specify an individual member of a struct by using
A) the assignment operator
B) an ampersand
C) an underscore
D) The dot operator
A) the assignment operator
B) an ampersand
C) an underscore
D) The dot operator
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
36
If class A is derived from class B, then B is a _______ of A.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
37
C++11 allows you to directly set the member variables to initial values in the definition of the class. This feature is called __________________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
38
To assign values to a structure variable, you use the
A) equals operator
B) assignment operator
C) extraction operator
D) less than operator
A) equals operator
B) assignment operator
C) extraction operator
D) less than operator
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
39
The constructor of a class that does not have any parameters is called a __________ constructor.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
40
What can a constructor return? _______________
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
41
A Member function that allows the user of the class to see the value in a data member is known as
A) a mutator function
B) a mutation
C) a manipulator function
D) an accessor function
A) a mutator function
B) a mutation
C) a manipulator function
D) an accessor function
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
42
Data members or member functions of a class that are declared to be private may
A) only be accessed by the main program
B) only be accessed by members of the class
C) not be accessed by the class
D) are considered to be global variables
A) only be accessed by the main program
B) only be accessed by members of the class
C) not be accessed by the class
D) are considered to be global variables
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
43
Member functions of a class
A) may not be in the private section
B) must be in the private section
C) may be in either section
D) can not be called in the main program
A) may not be in the private section
B) must be in the private section
C) may be in either section
D) can not be called in the main program
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
44
In a class, all members are ____________ by default
A) public
B) private
C) global
D) all of the above
A) public
B) private
C) global
D) all of the above
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
45
In a struct, all members are ____________ by default
A) public
B) private
C) global
D) all of the above
A) public
B) private
C) global
D) all of the above
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
46
Which part of the ADT tells the programmer using it how to use it?
A) the implementation
B) the interface
C) the abstractness
D) the scope resolution
A) the implementation
B) the interface
C) the abstractness
D) the scope resolution
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
47
Given the following class definition, what is missing?
Class ItemClass
{
Public:
ItemClassint newSize, float newCost);
Int getSize);
Float getCost);
Void setSizeint newSize);
Void setCostfloat newCost);
Private:
Int size;
Float cost;
};
A) nothing
B) a default constructor
C) accessor functions
D) mutator functions
Class ItemClass
{
Public:
ItemClassint newSize, float newCost);
Int getSize);
Float getCost);
Void setSizeint newSize);
Void setCostfloat newCost);
Private:
Int size;
Float cost;
};
A) nothing
B) a default constructor
C) accessor functions
D) mutator functions
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
48
Given the following class, what would be the best declaration for a constructor that would allow the user to initialize the object with an initial age and cost?
Class Wine
{
Public:
Wine);
Int getAge);
Float getCost);
Private:
Int age;
Float cost;
}
A) int getAgeint newAge);
B) Wine);
C) Wineint age);
D) Wineint newAge, float newCost);
Class Wine
{
Public:
Wine);
Int getAge);
Float getCost);
Private:
Int age;
Float cost;
}
A) int getAgeint newAge);
B) Wine);
C) Wineint age);
D) Wineint newAge, float newCost);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
49
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;
B) cout << Wine.age, Wine.cost;
C) cout << bottle.getAge) << bottle.getCost);
D) cout << bottle.getAge << bottle.getCost;
E) cout << bottle.age << bottle.cost;
Class Wine
{
Public:
Wine);
Int getAge);
Float getCost);
Private:
Int age;
Float cost;
}
Wine bottle;
A) cout << bottle;
B) cout << Wine.age, Wine.cost;
C) cout << bottle.getAge) << bottle.getCost);
D) cout << bottle.getAge << bottle.getCost;
E) cout << bottle.age << bottle.cost;
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
50
A derived class has access to
A) the private functions and variables of its ancestor classes
B) the public functions and variables of its ancestor classes
C) only the functions and variables defined it its class
D) none of the above
A) the private functions and variables of its ancestor classes
B) the public functions and variables of its ancestor classes
C) only the functions and variables defined it its class
D) none of the above
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
51
If you design a class with private data members, and do not provide mutators and accessors, then
A) The private data members can still be accessed from outside the class by using the & operator
B) The data can not be changed or viewed by anyone.
C) None of the above
D) A and B
A) The private data members can still be accessed from outside the class by using the & operator
B) The data can not be changed or viewed by anyone.
C) None of the above
D) A and B
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
52
If you are designing a class for an ADT, you can tell if the class is an ADT if
A) when you change the implementation of the class, none of the rest of the program needs to change.
B) when you change the interface of the class, nothing else needs to change.
C) you change the privte part and the rest of the program using the ADT does not compile.
D) everything must be changed.
A) when you change the implementation of the class, none of the rest of the program needs to change.
B) when you change the interface of the class, nothing else needs to change.
C) you change the privte part and the rest of the program using the ADT does not compile.
D) everything must be changed.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
53
A class member function that automatically initializes the data members of a class is called
A) the init function
B) an operator
C) a constructor
D) a cast
A) the init function
B) an operator
C) a constructor
D) a cast
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
54
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) int getAgeint newAge);
B) Wine);
C) void setAge);
D) void setAgeint newAge);
Class Wine
{
Public:
Wine);
Int getAge);
Float getCost);
Private:
Int age;
Float cost;
}
A) int getAgeint newAge);
B) Wine);
C) void setAge);
D) void setAgeint newAge);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
55
If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?
A) myPersonClass::myPersonClass);
B) myPersonClass);
C) init);
D) cast);
A) myPersonClass::myPersonClass);
B) myPersonClass);
C) init);
D) cast);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
56
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);
ItemClassint newSize, float newCost);
Int getSize);
Float getCost);
Void setSizeint newSize);
Void setCostfloat newCost);
Private:
Int size;
Float cost;
};
A) ItemClass) myItem;
B) ItemClass myItem1, 0.0);
C) ItemClass myItem;
D) ItemClass myItem);
E) You can not do this
Class ItemClass
{
Public:
ItemClass);
ItemClassint newSize, float newCost);
Int getSize);
Float getCost);
Void setSizeint newSize);
Void setCostfloat newCost);
Private:
Int size;
Float cost;
};
A) ItemClass) myItem;
B) ItemClass myItem1, 0.0);
C) ItemClass myItem;
D) ItemClass myItem);
E) You can not do this
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
57
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 definition type
B) an available data type
C) an abstract data type
D) a primitive data type
A) an abstract definition type
B) an available data type
C) an abstract data type
D) a primitive data type
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
58
given the following class definition, how could you use the constructor to assign values to an object of this class?
Class CDAccount
{
Public:
CDAccount);
CDAccountfloat interest, float newBalance);
Float getBalance);
Float getRate);
Void setRatefloat interest);
Void setBalancefloat newBalance);
Private:
Float balance, rate;
};
And the following object declaration
CDAccount myAccount;
A) myAccount = CDAccountfloat myRate, float myBalance);
B) myAccount = CDAccount {myRate, myBalance};
C) myAccount = CDAccount[myRate, myBalance];
D) myAccount = CDAccountmyRate, myBalance);
Class CDAccount
{
Public:
CDAccount);
CDAccountfloat interest, float newBalance);
Float getBalance);
Float getRate);
Void setRatefloat interest);
Void setBalancefloat newBalance);
Private:
Float balance, rate;
};
And the following object declaration
CDAccount myAccount;
A) myAccount = CDAccountfloat myRate, float myBalance);
B) myAccount = CDAccount {myRate, myBalance};
C) myAccount = CDAccount[myRate, myBalance];
D) myAccount = CDAccountmyRate, myBalance);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
59
Developing an ADT means that the user of your class does not have to know the details about how the class is implemented. This is known as
A) interface
B) implementation
C) testing and debugging
D) information hiding
A) interface
B) implementation
C) testing and debugging
D) information hiding
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
60
A member function that allow the user of the class to change the value in a data member is known as
A) a mutator function
B) a mutation
C) a manipulator function
D) an accessor function
A) a mutator function
B) a mutation
C) a manipulator function
D) an accessor function
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
61
Which of the following function declarations will accept either cout or a file stream object as its argument?
A) void output fstream &outFile);
B) void output ofstream &outFile);
C) void output ostream &outFile);
D) void output iostream &outFile);
A) void output fstream &outFile);
B) void output ofstream &outFile);
C) void output ostream &outFile);
D) void output iostream &outFile);
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck