1. (TCO 2) Only those class members that are hidden from users of the class are
ID: 3637983 • Letter: 1
Question
1. (TCO 2) Only those class members that are hidden from users of the class are part of the _____ of the class. (Points : 2)interface
implementation
constructors
GUI (graphical user interface)
2. (TCO 2) A public accessor can be paired with a public _____ to allow an outside class to set and retrieve the value of an object’s attribute. (Points : 2)
constructor
mutator
getter
None of the above
3. (TCO 2) Which of the following statements is/are true? (Points : 2)
A change to the implementation should not require a change to the user’s code.
The code within public methods is actually part of the implementation because the user cannot see it.
The implementation is totally hidden from the user.
All of the above
None of the above
4. (TCO 2) A Waiter is responsible for taking the order from the Customer based on the menu, informing the Chef of the order and delivering the requested food back to the Customer. A Chef is responsible for preparing the food and notifying the Waiter when the food is ready. The Customer is responsible for placing an order from the menu. In identifying the interface of the Waiter object, which of the following would you consider as (an) appropriate message(s) the Waiter should respond to? (Points : 2)
“Please bring me chicken soup.”
“Can you tell me how to make macaroni and cheese?”
“How many hours do you work?”
All of the above
Only A and B
5. (TCO 5) One of the purposes of a(n) _____ is to release resources back to the system when the object is not used anymore. (Points : 2)
class
constructor
destructor
instance variable
6. (TCO 5) Which of the following method pairs depict method overloading?
(Points : 2)
public void Roll() ; public int Roll(int x)
public int Reverse(int x, int y) ; public int Reverse(int y, int x)
public int Subtract(int x, int y) ; public int Subtract(int x, int y, int z)
All of the above
Only A and C
7. (TCO 5) Consider the following class definition and the object instantiation.
class House
{
private:
int age;
double salesPrice;
public:
House()
{
age = 1;
salesPrice = 2.0;
}
House(int a, double sp)
{
age = a;
salesPrice = sp;
}
int getAge()
{
return age;
}
double getSalesPrice()
{
return salesPrice;
}
~House() { }
} ;
int main()
{
int tempAge=0;
int tempPrice=0;
House ranch();
return 0;
}
Using the main() method to access the members of the object, which of the following statement is correct?
(Points : 2)
tempPrice = House.SalesPrice();
ranch.salePrice = 250000.0;
ranch.age = 3;
cout<<”The house price is: “ << ranch.SalesPrice();
8. (TCO 2) Can two methods each define a local variable with the same name? (Points : 2)
Yes, as long as the variable is used in the same way.
No, this is not possible because the compiler would not know which variable to use.
Yes, but only if the methods have the same name.
None of the above
9. (TCO 5) Which error handling technique is the least appropriate when developing an application?
(Points : 2)
Check for potential problems and abort the application when a problem is encountered.
Check for potential problems and throw an exception.
Check for potential problems, catch the mistake, and try to fix it.
Ignore the problem; all applications crash at some point.
10. (TCO 2) Which is an appropriate choice for a static attribute in a Building class?
(Points : 2)
numberOfBuildings
numberOfApartments
numberOfFloors
None of the above
Explanation / Answer
1. (TCO 2) Only those class members that are hidden from users of the class are part of the implementation of the class.
2. (TCO 2) A public accessor can be paired with a public mutator to allow an outside class to set and retrieve the value of an object’s attribute.
3. (TCO 2) Which of the following statements is/are true?
TRUE => A change to the implementation should not require a change to the user’s code.
TRUE => The code within public methods is actually part of the implementation because the user cannot see it.
TRUE => The implementation is totally hidden from the user.
TRUE => All of the above
None of the above
4. (TCO 2) A Waiter is responsible for taking the order from the Customer based on the menu, informing the Chef of the order and delivering the requested food back to the Customer. A Chef is responsible for preparing the food and notifying the Waiter when the food is ready. The Customer is responsible for placing an order from the menu. In identifying the interface of the Waiter object, which of the following would you consider as (an) appropriate message(s) the Waiter should respond to? (Points : 2)
TRUE => “Please bring me chicken soup.”
FALSE => “Can you tell me how to make macaroni and cheese?”
FALSE => “How many hours do you work?”
FALSE => All of the above
FALSE => Only A and B
5. (TCO 5) One of the purposes of a(n) destructor is to release resources back to the system when the object is not used anymore.
6. (TCO 5) Which of the following method pairs depict method overloading?
TRUE => public void Roll() ; public int Roll(int x)
FALSE => public int Reverse(int x, int y) ; public int Reverse(int y, int x)
TRUE => public int Subtract(int x, int y) ; public int Subtract(int x, int y, int z)
FALSE => All of the above
TRUE => Only A and C
7. (TCO 5) Consider the following class definition and the object instantiation.
Using the main() method to access the members of the object, which of the following statement is correct?
(Points : 2)
FALSE (no such method) => tempPrice = House.SalesPrice();
FALSE (private!) => ranch.salePrice = 250000.0;
FALSE (private) => ranch.age = 3;
**FALSE (no such method) => cout<<”The house price is: “ << ranch.SalesPrice();
** They are all false, if you *have* to select, then perhaps "SalesPrice()" is a typo and it was meant to be "getSalesPrice()", if this is the case then the last one is correct
8. (TCO 2) Can two methods each define a local variable with the same name?
FALSE => Yes, as long as the variable is used in the same way.
FALSE =>No, this is not possible because the compiler would not know which variable to use.
FALSE =>Yes, but only if the methods have the same name.
TRUE => None of the above
The answer is Yes, they can and they don't have to be used in the same way whatsoever.
9. (TCO 5) Which error handling technique is the least appropriate when developing an application?
FALSE => Check for potential problems and abort the application when a problem is encountered.
FALSE => Check for potential problems and throw an exception.
FALSE => Check for potential problems, catch the mistake, and try to fix it.
TRUE (least appropriate) => Ignore the problem; all applications crash at some point.
10. (TCO 2) Which is an appropriate choice for a static attribute in a Building class?
TRUE => numberOfBuildings
FALSE => numberOfApartments
FALSE => numberOfFloors
FALSE => None of the above
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.