FINALTERM EXAMINATION
Spring 2010
CS304- Object Oriented Programming (Session - 4)
Question No: 1 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 2 ( Marks: 1 ) - Please choose one
► create an array of type pointer-to-base class that can hold pointers to derived classes.
► create functions that can never be accessed.
► group objects of different classes so they can all be accessed by the same function code.
► use the same function call to execute member functions of objects from different classes
Question No: 3 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 4 ( Marks: 1 ) - Please choose one
► a function do not returns by value.
► an argument is passed by value.
► a function returns by reference.
► an argument is passed by reference.
Question No: 5 ( Marks: 1 ) - Please choose one
► 1
► 2
► 3
► As many as necessary.
Question No: 6 ( Marks: 1 ) - Please choose one
► All
► One specific
► All instances of one date type
► None of the given options
Question No: 7 ( Marks: 1 ) - Please choose one
► Greater Memory
► Lesser Memory
► Equal Memory
► None of the given options
Question No: 8 ( Marks: 1 ) - Please choose one
► finds matching sequences of elements in two containers.
► finds a container that matches a specified container.
► takes iterators as its first two arguments.
► takes container elements as its first two arguments.
Question No: 9 ( Marks: 1 ) - Please choose one
► the last element copied from.
► the last element copied to.
► the element one past the last element copied from.
► the element one past the last element copied to.
Question No: 10 ( Marks: 1 ) - Please choose one
► 11 for v and 3 for w.
► 0 for v and 0 for w.
► 0 for v and 3 for w.
► 3 for v and 11 for w.
Question No: 11 ( Marks: 1 ) - Please choose one
► providing class growth through natural selection.
► facilitating class libraries.
► avoiding the rewriting of code.
► providing a useful conceptual framework.
Question No: 12 ( Marks: 1 ) - Please choose one
{
public:
virtual void Print() { cout << "Generic element"; }
};
class Heading : public DocElement
{
public:
void Print() { cout << "Heading element"; }
};
class Paragraph : public DocElement
{
public:
void Print() { cout << "Paragraph element"; }
};
void main()
{
DocElement * p = new Paragraph();
p->Print();
}
When you run this program, it will print out a single line to the console output.
What will be in that line?
Select one correct answer from the following list:
► Generic element
► Heading element
► Paragraph element
► Nothing will be printed.
Question No: 13 ( Marks: 1 ) - Please choose one
class X : public A, public B { ... ... };
► Single inheritance
► Multiple inheritance
► Double inheritance
► None of the given options
Question No: 14 ( Marks: 1 ) - Please choose one
► template < class class_name>
► template < class data_type>
► template < class T >
Here T can be replaced with any name but it is preferable.
► class class-name()
class template<class_name>
Question No: 15 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 16 ( Marks: 1 ) - Please choose one
► Reusability
► Writability
► Maintainability
► All of given
Question No: 17 ( Marks: 1 ) - Please choose one
► data type
► meta type
► virtual type
► pointer type
Question No: 18 ( Marks: 1 ) - Please choose one
► italic
► iteration
► iterator
► None of given
Question No: 19 ( Marks: 1 ) - Please choose one
► State
► Behavior
► Unique identity
► All of the given
Question No: 20 ( Marks: 1 ) - Please choose one
Cupboard has books
What is the relationship between Cupboard and books?
► Composition
► Aggregation
► Inheritance
► None of the given options
Question No: 21 ( Marks: 1 ) - Please choose one
► one instance of a class.
► another word for a class.
► a class with static methods.
► a method that accesses class attributes.
Question No: 22 ( Marks: 1 ) - Please choose one
► Friendship is one way only
► Friendship is two way only
► NO Friendship between classes
► Any kind of friendship
Question No: 23 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 24 ( Marks: 1 ) - Please choose one
Rational_number_1 + Rational_number_2
Where Rational_number_1 and Rational_number_2 are the two objects of Rational_number class (a user defined class). Identify which of the above two objects will be passed as an argument to the overloaded operator function?
► Rational_number_1
► Rational_number_2
► Both Rational_number_1 & Rational_number_2
► any of the two objects, randomly
Question No: 25 ( Marks: 1 ) - Please choose one
► can be
► cannot be
► does restirct to be
► not given
Question No: 26 ( Marks: 1 ) - Please choose one
► specialization
► inheritance
► abstraction
► composition
Question No: 27 ( Marks: 2 )
Question No: 28 ( Marks: 2 )
Question No: 29 ( Marks: 2 )
Question No: 30 ( Marks: 2 )
Question No: 31 ( Marks: 3 )
class c1{
public:
virtual void function(){
cout<<”I am in c1”<<endl;
}
};
class c2: public c1{
public:
void function(){
cout<<”I am in c2”<<endl;
}
};
class c3: public c1 {
public:
void function(){
cout<<”I am in c3”<<endl;
}
};
int main(){
c1 * test1 = new c2();
c1 * test2 = new c3();
test1->function();
test2->function();
system(“PAUSE”);
return 0;
}
Question No: 32 ( Marks: 3 )
Question No: 33 ( Marks: 3 )
class Test{
public:
int function1(){
try{
FILE *fileptr = fopen(“filename.txt”,“w”);
throw exception();
fclose(fileptr);
return 0;
}
catch(Exception e){
...
}
}
};
Question No: 34 ( Marks: 5 )
#include<iostream.h>
void sample_function(double test) throw (int);
int main()
{
try
{
cout <<”Trying.\n”;
sample_function(98.6);
cout << “Trying after call.\n”;
}
catch(int)
{
cout << “Catching.\n”;
}
cout << “End program.\n”;
return 0;
}
void sample_function(double test) throw (int)
{
cout << “Starting sample_function.\n”;
if(test < 100)
throw 42;
}
Question No: 35 ( Marks: 5 )
1. You have to identify any error/s in this code and describe the reason for error/s.
2. Give the correct code after removing the error/s.
template<typename U>
void Test(U);
template< class T >
class B {
int data;
public:
friend void Test<>( T );
};
template<typename U>
void Test(U u){
B < int> b1;
b1.data = 7;
}
int main(int argc, char *argv[])
{
char i;
Test(i);
system("PAUSE");
return 0;
}
Question No: 36 ( Marks: 5 )
class Base
{
char * p;
public:
Base() { p = new char[10]; }
~Base() { delete [] p; }
};
class Derived : public Base
{
char * q;
public:
Derived() { q = new char[20]; }
~Derived() { delete [] q; }
};
void foo()
{
Base* p = new Derived();
delete p;
}
With this program, every time function foo is called, some memory will leak.
Explain why memory will leak. Also, explain how to fix this problem.
No comments:
Post a Comment
PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE
Note: Only a member of this blog may post a comment.