Paper F - City University of Hong Kong

advertisement
-1-
DIVISION OF COMPUTER STUDIES
CITY UNIVERSITY OF HONG KONG
Course Code & Title :
DCO10105 Object-Oriented Programming and Design
Session
:
Revision Quiz 4, Semester B, 2005/2006 (Paper F)
Time Allowed
:
10 minutes
Date
:
20-26 April 2006
This paper has TWO pages.
1.
The total points for this paper is 20.
2.
This paper consists of TWO questions.
3.
Answer ALL questions.
4.
Write answers following the question or on the areas specified in the question.
5.
You may use pencil to provide the answers.
6.
All coding should be in ANSI C++ language, or can be implemented under DevC++ v4.9.9.0.
7.
Provide any assumptions that you think would be useful, as long as they do not contradict the
question.
Lab Group: _________ Name: ________________________________ ID __________________
For use by the Tutor:
Points:
20
RQ4F
-2-
1) Given the following incomplete class diagram, assume that Product is already defined in Product.h.
Write the class definitions for ElectricalProduct but you are not required to write any members for
the class. Other than #include <string>, list one more #include statement.
[Total 10 points]
2) Use the class diagram in question 1 and consider the following C++ code segment:
[Total 10 points]
string inputValue;
try
{
cin >> inputValue;
if (inputValue == "P001")
throw Product();
else
if (inputValue == "E001")
throw ElectricalProduct();
cout << "Exiting the try block." << endl;
}
catch (Product p) {
cout << "Input is a book." << endl;
}
catch (ElectricalProduct ep) {
cout << "Input is a fan." << endl;
}
cout << "After the catch block." << endl;
A) What is the output if the value of inputValue is “E001”?
[5 points]
B) What is the output if the value of inputValue is “B001?
[5 points]
RQ4F
Download