Академический Документы
Профессиональный Документы
Культура Документы
programming
Test II Marks-25 Time
-30minutes
Instructions
Answer all questions
Each question has its time limit.
When the limit expires, the next
question comes up automatically.
Marks allotted and time given are
shown in the header section
Marks : 1
Time:30
secs
Marks : 1
Time:30
secs
Marks : 1
Time:30secs
3. For a member function of a class to
be an interface between the outside
world and a class, it has to be
declared
A. private
B. protected
C. public
D. external
Marks : 1
Time:1
4. Identify the operator that cannot be
overloaded in C++
A. ?:
B. +
C. new
D. none
Marks : 1
Time:1
5. Consider the following class definition
class sample {
static int a;
int b;
void c(void);
}
sample m1,m2,m3;
How many copies of variable a and b, and function c( ), exists
in the memory
A. 3,3,3
B. 1,1,1
C. 1,3,1
D. 1,2,1
Marks : 1
Time:1
6. What does the inline keyword do?
A. Indicates a function declaration.
B. Tells the compiler to use function in other
programs.
C. Causes all function calls to be replaced by
the code from the function.
D. None of the above.
Marks : 1
Time:1
7.Which of the following function template definitions
are valid?
i. template<class T1, T2>void f( T1 a, T2 b){.....}
ii. template<class T1, class T1>void f( T1 *a, T2 &b){......}
iii. template<class T1, typename T2> void f( T1 a, T2 b)
{.....}
iv. template<class T1, class T2>void f(T1 a, T2 b) {.}
Answer:
A.
B.
C.
D.
i and ii only
ii and iii only
iii and iv only
i and iv only
Marks : 1
Time:30secs
8. Which of the following class is the
base of all the input/output stream
class hierarchy?
A. ios
B. iostream
C. ostream
D. istream
Marks : 1
Time:1
9. Copy constructor of a class is not used when
i. An object of the class type is passed to a function by value.
ii. An existing object of the class type is assigned to another
object of the same type.
iii. Another object is created from an existing object.
iv. An object of the class type is returned from a function by
value.
Correct Answer is:
A.i only
B.iii and iv only
C.ii only
D.i, iii, and iv only
Marks : 1
Time:1
10.Which is not applicable to a friend of class?
i. Friendship is against the principle of
encapsulation and information hiding.
ii. A friend function is not inheritable.
iii. Friendship is not symmetric.
iv. Friend can access the restricted section of a
class without an object of the class.
Correct answer is
A. i only .
B. ii, and iii only
C. only iv.
D. all of these
Marks : 3
Time:4
11.Given the following class and constructor implementation, explain how the
memory allocated to object c1 is initialized by the constructor in full
detail.
class Rational{
private:
int numerator;
int denominator;
public:
Rational( int nu =0, int de=1){
numerator=nu;
denominator = de;
}
};
Rational c1(2,4);
Marks : 3+2
Time:6
12.Given the class Account, answer the following questions:
class Account{
private:
char * name;
unsigned int acno;
double balance;G
public :
Account(const char * custName, unsigned int acNo, double
oBalance=0.0);
};
i). Give the full implementation of the constructor.
ii). Does the class require a destructor? If not, explain why? If
yes, provide the full destructor.
Marks : 4
Time:4
13.
Given the following class ,explain how the operator + can be overloaded by
using a friend function to perform addition of any two rational numbers.
class Rational{
private:
int numerator;
int denominator;
public:
Rational( int nu =0, int de=1){
numerator=nu;
denominator = de;
}
};
Hint : Addition of two rationals nos: x/y + a/b = (x*b + a*y)/(y*b)
Marks : 3
Time:5
14. Given the class Account, answer the following question.
class Person{
private:
char * name;
char * address;
char * panNumber;
public:
Person( const Person & thisPerson); // copy constructor; assume
already implemented
};
class Account{
private:
Person AcHolder;
unsigned int acno;
double balance;
public :
Account(const Account & thisAccount); // Copy construcot
};
Give the full implementation of the copy constructor of the class Account. Remember,
AcHolder is an embedded object in the class Account.