C. object programming < --- // “erase” deletes from x to y, inclusive
D. oriented programming
4. Define a class class Circle {
int x; int y; int r;
static double pi=3.14; public:
Circle(int=0, int=0, int=0); double area();
};
Which statement is correct?
A. Cannot assign value to pi in the class. < ---
B. Cannot assign zeros to the parameters in the constructor.
C. Should define a default constructor.
D. Return type of area() should be int.
5. Which statement is correct?
A. Use Cases describes structure of a system.
B. Use Cases describes interactions between a user and a system. < ---
C. Use Cases describes data flow of a system.
D. Use Cases describes views of code.
6. Which statement is correct?
A. In a class diagram, the {} indicates a “comment”.
B. In a class diagram, the {} indicates a “Role stereotype”.
C. In a class diagram, the {} indicates a “arguments’ list”.
D. In a class diagram, the {} indicates a “constraint”.
< ---
7. Which statement is correct?
A. A default copy constructor can make deep copy.
B. A default constructor can initialize data members. < ---
C. A default assignment operator can make a shallow copy.
D. A default destructor can delete dynamic memory allocated for data members.
8. Which statement is correct? A friend class of a class
A. is an instance object member of the class.
B. can access private data members in the class object. < ---
C. cannot access private data members, but can access protected data members in the class object.
D. cannot be defined.
9. Which statement is correct?
A. If no exceptions are thrown in the try block, all handlers are executed directly;
B. Exceptions can only be integer type or character type;
C. After the exception is thrown, it will be caught by the closest catch statement; < ---
D. A try block can be followed by zero or more catch blocks.
10. Which statement is correct?
A. A friend function of a class can be a member function of the class. < ---
B. A friend function of a class can access protected and public members, but not private members in the class.
C. A friend class of a class can be inherited; the derived class is also a friend of that class.
D. A friend function of a class must be declared inside the class.
11. Which operator cannot be overloaded?
A. Member parentheses operator ();
B. Exception member function what() ;
C. Dot operator .;
D. Logic bit AND operator &.
12. Define a class class Fraction {
private:
int numerator; int denominator;
public:
//member functions
};
Define overloading post fix increment operator (++) as a member function in the class Fraction. Which one of the following is correct?
A. In the class Fraction, define Fraction operator++(int);
Then implement the operator as Fraction Fraction::operator++(int) {
Fraction result = *this; numerator += denominator;
return result;
}
B. In the class Fraction, define Fraction operator++();
Then implement the operator as Fraction Fraction::operator++() {
numerator += denominator;
return *this;
} < ---
C. In the class Fraction, define Fraction operator++(int);
Then implement the operator as Fraction Fraction::operator++(int inc) {
numerator += inc * denominator;
return *this;
}
D. In the class Fraction, define Fraction operator++();
Then implement the operator as Fraction Fraction::operator+()
{ Fraction result = *this; numerator += denominator;
return result;
}
13. Which statement is true?
A. In C++ program, multiple inheritance is allowed. < ---
B. Multiple inheritance is supported by Object-Oriented Language.
C. Multiple inheritance is required to solve a programming problem.
D. None of above is true;
14. Define
int x; double y;
Which expression has truth value?
A. typeid(x) == typeid(y)
B. typeid(x) == typeid(int *)
C. typeid(y) == typeid(double *)
D. typeid(&y) == typeid(double *) < ---
15. Which statement is not correct?
A. Use namespace, programmers can avoid clashes between variables and function names.
B. Use namespace, programmers can choose different versions of functions or data types.
C. Use namespace, programmers can save time on coding.
D. Use namespace, programmers can hide information. < ---
16. Which statement is not correct?
A. A class cannot be defined in another class. < ---
B. To define private or protected constructor for a class, one can create a singleton class.
C. A monostate class contains only private static data members and public non-static member functions.
D. Function objects are really objects which have an overloaded () operator.
17. Which statement is not correct?
A. string s = "Hello world";
B. string s="Hello " + "world" < ---
C. string s(1, 'H');
D. string s("Hello world");
18. Define namespace date in date.h namespace date {
int day; int month; int year;
void setdate(int x, int y, int z) { day = x; month = y; year = z;
}
}
Which one of following has compilation errors?
A.
#include<iostream> #include "date.h" using namespace std; int main() {
4. All options are incorrect, or the statement "Cannot assign value to pi in the class." needs to be clarified.
7. C. Default constructors don't initialize members of basic types. A can aslo be true depending on how narrow your definition of "deep copy" is.
10. D. A member function being a friend of its own class would be redundant.
11. C.
12. I'll leave checking this one to someone else. I can never remember the syntax.
15. A. Namespaces don't hide anything. They merely avoid dumping names onto the global namespace.
16. C and D are both true, AFAICT.