We are Permanently Move to www.VUpk.net Please Join us there.
Showing posts with label CS304. Show all posts
Showing posts with label CS304. Show all posts

CS304 Assignments of Spring 2012

Sunday, 12 August 2012

CS304 Final term Subjective 2012

Monday, 6 August 2012

CS304 - Object Oriented Programming Finalterm Subjective Paper July 2012

  • Can a constructor throw an exception? How to handle the errors, when the constructor fails?
  • How can you describe virtual destructor? Why virtual destructor is used?
  • What do you know about exception in initialization?
  • what is iterator? and what is output and input iterator?
  • Describe a way to declare a template function as a friend of any other class.
  • Give three advantages that Iterates provide over Cursors.
  • What do you know about function templates?
  • Give the difference between virtual inheritance and multiple inheritances.

CS304 Final term Subjective Solved by MOAAZ

CS304- Object Oriented Programming Finalterm Solved Subjective Papers
Solved and Shared by Moaaz Siddiq


Attachments:
Download this file (CS304-FINALTERM-SUBJECTIVE-BY-MOAAZ.pdf)CS304-FINALTERM-SUBJECTIVE-BY-MOAAZ[ ]239 Kb

CS304 Final term Solved MCQs by MOAAZ

CS304- Object Oriented Programming Finalterm Solved Objective Papers

Solved and Shared by Moaaz Siddiq

Attachments:
Download this file (CS304-FINALTERM-MCQS-BY-MOAAZ.pdf)CS304-FINALTERM-MCQS-BY-MOAAZ[ ]423 Kb

CS304 Final term Paper 2009

FINALTERM EXAMINATION 
Fall 2009 
                                    CS304- Object Oriented Programming (Session - 1)
Time: 120 min
Marks: 75


Question No: 1 ( Marks: 1 )
Which one of the following terms must relate to polymorphism?
Static allocation
Static typing
Dynamic binding
Dynamic allocation

Question No: 2 ( Marks: 1 )
Multiple inheritance can be of type
Public
Private
Protected
All of the given
Question No: 3 ( Marks: 1 ) When a subclass specifies an alternative definition for an attribute or method of its
superclass, it is ______the definition in the superclass.
overload
overriding
copy riding
none of given

Question No: 4 ( Marks: 1 ) Like template functions, a class template may not handle all the types successfully.
True
False

Question No: 5 ( Marks: 1 )It is sometimes useful to specify a class from which no objects will ever be created.
True
False

Question No: 6 ( Marks: 1 ) Assume a class Derv that is privately derived from class Base. An object of class Derv
located in main() can access
public members of Derv.
protected members of Derv.
private members of Derv.
protected members of Base.
Question No: 7 ( Marks: 1 )
A pointer to a base class can point to objects of a derived class.
True
False

Question No: 8 ( Marks: 1 ) A copy constructor is invoked when
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: 9 ( Marks: 1 ) A function call is resolved at run-time in___________
non-virtual member function.
virtual member function.
Both non-virtual member and virtual member function.
None of given

Question No: 10 ( Marks: 1 ) When the base class and the derived class have a member function with the same name, you must be more specific which function you want to call (using ___________).
scope resolution operator
dot operator
null operator
Operator overloading

Question No: 11 ( Marks: 1 )Each try block can have _____no. of catch blocks.
1
2
3
As many as necessary.

Question No: 12 ( Marks: 1 ) Two important STL associative containers are ______and _______.
set,map
sequence,mapping
setmet,multipule
sit,mat

Question No: 13 ( Marks: 1 ) The mechanism of selecting function at run time according to the nature of calling object
is called,
late binding
static binding
virtual binding
None of the given options

Question No: 14 ( Marks: 1 ) An abstract class is useful when,

We do not derive any class from it.
There are multiple paths from one derived class to another.
We do not want to instantiate its object.
You want to defer the declaration of the class.

Question No: 15 ( Marks: 1 ) Which of the following is incorrect line regarding function template?
template<class T>
template <typename U>
Class<template T>
template < class T, class U>

Question No: 16 ( Marks: 1 ) Which of the following is/are advantage[s] of generic programming?
Reusability
Writability
Maintainability
All of given

Question No: 17 ( Marks: 1 ) By default the vector data items are initialized to ____
0
0.0
1
null
Question No: 18 ( Marks: 1 ) Which one of the following functions returns the total number of elements in a vector.
length();
size();
ele();
veclen();

Question No: 19 ( Marks: 1 ) Suppose you create an uninitialized vector as follows:

vector<int> evec;
After adding the statment,
evec.push_back(21);
what will happen?

The following statement will add an element to the start (the back) of evec and will initialize it with the value 21.
The following statement will add an element to the center of evec and will reinitialize it with the value 21.
The following statement will delete an element to the end (the back) of evec and will reinitialize it with the value 21.
The following statement will add an element to the end (the back) of evec and initialize it with the value 21.

Question No: 20 ( Marks: 1 ) An STL container can not be used to,

hold objects of class employee.
store elements in a way that makes them quickly accessible.
compile c++ programs.
organize the way objects are stored in memory

Question No: 21 ( Marks: 1 ) Algorithms can only be implemented using STL containers.
True
False

Question No: 22 ( Marks: 1 )The main function of scope resolution operator (::) is,

To define an object
To define a data member
To link the definition of an identifier to its declaration
To make a class private

Question No: 23 ( Marks: 1 ) When is a constructor called?
Each time the constructor identifier is used in a program statement
During the instantiation of a new object
During the construction of a new class
At the beginning of any program execution

Question No: 24 ( Marks: 1 ) Consider the code below,
class Fred {
public:
Fred();
...
};
int main()
{
Fred a[10];
Fred* p = new Fred[10];
...
}
Select the best option,
Fred a[10]; calls the default constructor 09 times Fred* p = new Fred[10]; calls the default constructor 10 times
Produce an error
Fred a[10]; calls the default constructor 11 times Fred* p = new Fred[10]; calls the default constructor 11 times
Fred a[10]; calls the default constructor 10 times Fred* p = new Fred[10]; calls the default constructor 10 times

Question No: 25 ( Marks: 1 ) Associativity can be changed in operator overloading.
True
False

Question No: 26 ( Marks: 1 ) A normal C++ operator that acts in special ways on newly defined data types is said to be
glorified.
encapsulated.
classified.
overloaded.

Question No: 27 ( Marks: 1 ) Which operator can not be overloaded?
The relation operator ( >= )
Assignment operator ( = )
Script operator ( [] )
Conditional operator (? : )

Question No: 28 ( Marks: 1 ) Suppose obj1 and obj2 are two objects of a user defined class A. An + operator is
overloaded to add obj1 and obj2 using the function call obj1+obj2.
Identify the correct function prototype against the given call?

A operator + ( A &obj);
int + operator();
int operator (plus) ();
A operator(A &obj3);

Question No: 29 ( Marks: 1 ) Default constructor is such constructor which either has no ---------or if it has some
parameters these have -------- values
Parameter, temporary
Null, Parameter
Parameter, default
non of the given

Question No: 30 ( Marks: 1 ) Public methods of base class can --------- be accessed in its derived class
directly
inderectly
simultaniously
non of the given

Question No: 31 ( Marks: 1 )
Is Deque a Birectional Container?
Yes, deque behaves like queue (line) such that we can add elements on both sides of it.

Question No: 32 ( Marks: 1 )
What is meant by Generic Programming?
Generic programming refers to programs containing generic abstractions general code
that is same in logic for all data types like printArray function), then we instantiate that
generic program abstraction (function, class) for a particular data type, such abstractions
can work with many different types of data.

Question No: 33 ( Marks: 2 )
Sort the following data in the order in which compiler searches a function?
Complete Specialization, Generic Template, Partial Specialization, Ordinary Function.
Specializations of this function template, instantiations with specific types, can be called
just like an ordinary function:
cout << max(3, 7); // outputs 7

The compiler examines the arguments used to call max and determines that this is a call
to max(int, int). It then instantiates a version of the function where the parameterizing
type T is int, making the equivalent of the following function:
int max(int x, int y)
{
return x < y ? y : x;
}
the C++ Standard Template Library contains the function template max(x, y) which
creates functions that return either x or y, whichever is larger. max() could be defined like
this:
template <typename T>
T max(T x, T y)
{
return x < y ? y : x;
}
Question No: 34 ( Marks: 2 )
State any conflict that may rise due to multiple inheritance?
The conflict may arise is the diamond problem, which our author likes to call the
“diamond of doom”. This occurs when a class multiply inherits from two classes which
each inherit from a single base class. This leads to a diamond shaped inheritance pattern.
For example, consider the following set of classes:
classPoweredDevice
{
};
classScanner: publicPoweredDevice
{
};
classPrinter: publicPoweredDevice
{
};
classCopier: publicScanner, publicPrinter
{
};

Scanners and printers are both powered devices, so they derived from PoweredDevice.
However, a copy machine incorporates the functionality of both Scanners and Printers.
Ambiguity also cause problem.
Question No: 35 ( Marks: 3 )
Describe three properties necessary for a container to implement Generic Algorithms.
If you declare a container as holding pointers, you are responsible for managing the
memory for the objects pointed to. The container classes will not automatically free
memory for these objects when an item is erased from the container.
Container classes are expected to implement methods to do the following:
• create a new empty container (constructor),
• report the number of objects it stores (size),
• delete all the objects in the container (clear),
• insert new objects into the container,
• remove objects from it,
• provide access to the stored objects.
Question No: 36 ( Marks: 3 )
Write three important features of virtual functions.
With virtual functions, derived classes can provide new implementations of functions
from their base classes. When someone calls a virtual function of an object of the derived
class, this new implementation is called, even if the caller uses a pointer to the base class,
and doesn't even know about the particular derived class.
The virtual function is an option, and the language defaults to non virtual, which is the
fastest configuration.
The derived class can completely "override" the implementation or "augment" it (by
explicitly calling the base class implementation in addition to the new things it does).

Question No: 37 ( Marks: 3 )
Consider the code below,
#include <iostream>
#include <stdlib.h>
using namespace std;
class Shape{
public:
void Draw(){cout<<"shape"<<endl;}
};
class Line : public Shape{
public:
void Draw(){cout<<"Line"<<endl;}
};
class Circle : public Shape{
public:
void Draw(){cout<<"Circle"<<endl;}
};
int main(int argc, char *argv[])
{
Shape * ptr1 = new Shape();
Shape * ptr2 = new Line();
Shape * ptr3 = new Circle();
ptr1->Draw();
ptr2->Draw();
ptr3->Draw();
system("PAUSE");
return 0;
}
This code shows output,
Shape
Shape
Shape
Give the reason for this output
Suppose we want to show the output,
Shape
Line
Circle

How we can change the code to do that?
class shape { public:
void draw();
};
class circle : public shape { };
int main(int argc, char **argv){
circle my_circle;
my_circle.draw();
}
While this has all the usual advantages, e.g., code reuse, the real power of polymorphism
comes into play when draw is declared to be virtual or pure virtual, as follows:
class shape{ public:
virtual void draw()=0;
};
class circle : public shape { public:
void draw();
}
Here, circle has declared its own draw function, which can define behavior appropriate
for a circle. Similarly, we could define other classes derived from shape, which provide
their own versions of draw. Now, because all the classes implement the shape interface,
we can create collections of objects that can provide different behavior invoked in a consistent
manner (calling the draw member function). An example of this is shown here.
shape *shape_list[3]; // the array that will
// pointer to our shape objects
shape[0] = new shape; // three types of shapes
shape[1] = new line; // we have defined
shape[2] = new circle;
for(int i = 0; i < 3; i++){
shape_list[i].draw();
}
When we invoke the draw function for each object on the list, we do not need to know
anything about each object; C++ handles the details of invoking the correct version of
draw. This is a very powerful technique, allowing us to provide extensibility in our
designs. Now we can add new classes derived from shape to provide whatever behavior
we desire. The key here is that we have separated the interface (the prototype for shape)
from the implementation.
Question No: 38 ( Marks: 5 )
There are some errors in the code given below, you have to
1. Indicate the line no. with error/s
2. Give the reason for error/s
3. Correct the error/s.

1. #include <iostream> this will be #include <iostream.h>
2. #include <stdlib.h>
3. using namespace std;
4. template <typename T>
5. class MyClass{
6. public:
7. MyClass(){
8. cout<<"This is class1"<<endl;
9. }
10. };
11. template <typename T>
12. class MyClass<int*>{
13. public:
14. MyClass(){
15. cout<<"This is class2"<<endl;
16. }
17. };
18. int main(int argc, char *argv[])
19. {
20. MyClass<int> c1;
21. MyClass<int*> c2;
22. system("PAUSE");
23. return 0;
24. }
Question No: 39 ( Marks: 5 )
Given are two classes A and B. class B is inherited from class A. Write a code snippet(
for main function) that polymorphically call the method of class B. Also what
changes do you suggest in the given code segment that are required to call the class B
method polymorphically.
class A
{
public:
void method() { cout<<"A's method \n"; }
};
class B : public A
{
public:
void method() { cout<<"B's method\n"; }

};
Ans:
public class Test
{
public class A {}
public class B extends A {}
private void test(A a)
{
System.out.println("test(A)");
}
private void test(B b)
{
System.out.println("test(B)");
}
public static void main(String[] args)
{
Test t = new Test();
A a = t.new A();
A b = t.new B();
t.test(a);
t.test(b);
}
}
Question No: 40 ( Marks: 10 )
Create built-in STL (Standard Template Library) vector class object for strings
and add in it some words by taking input from user, then apply the sort()
algorithm to array of words stored in this vector class object.
Hint:Use push_back() to add the words in vector class object, and the [] operator
and size() to display these sorted words.
The STL is the containers, iterators and algorithms component of the proposed C++
Standard Library [ANSI95]. It represents a novel application of principles which have
their roots in styles of programming other than Object-orientation.
void listWords(istream& in, ostream& out)

{
string s;
while (!in.eof() && in >> s) {
add s to some container
}
sort the strings in the container
remove the duplicates
for (each string t in container) {
out << t;
}
}
For now, assume that a word is defined as a whitespace-separated string as delivered by
the stream extraction operator. Later on we will consider ways of refining this definition.
Given the way this problem is expressed, we can implement this program directly, if
naïvely. The STL container class vector will suffice to hold the words: applying the
algorithms sort and unique provides the required result.
void listWords(istream& in, ostream& out)
{
string s;
vector<string> v;
while (!in.eof() && in >> s)
v.push_back(s); // (1)
sort(v.begin(), v.end());
vector<string>::iterator e
= unique(v.begin(), v.end()); // (2)
for (vector<string>::iterator b = v.begin();
b != e;
b++) {
out << *b << endl;
}
}
At (1) the vector member function push_back() is used to add to the end of the vector.
This can also be done using the insert member, which takes as a parameter an iterator
identifying the position in the vector at which to place the added element:
v.insert(v.end(), s);
This allows us to add at any position in the vector. Be aware, though, that adding
anywhere other than the end implies the overhead of physically shifting all elements from
the insertion point to the end to make room for the new value. For this reason, and given
the choices made in this example, attempts to optimise this code by maintaining the
vector in sorted order are unwise. Replace vector with list and this becomes possible -
although in both cases a search over the container will be necessary to determine the
correct position of insertion.
The unique algorithm has the surprising property of not changing the length of the
container to which it is applied (it can hardly do this, as it has access not to the
underlying container, but only to the pair of iterators it is passed). Instead, it guarantees
that duplicates are removed by moving unique entries towards the beginning of the
container, returning an iterator indicating the new end of the container. This can be used
directly (as here, at (2)), conversely it can be passed to the erase member with the old end
iterator, to truncate the container.
Question No: 41 ( Marks: 10 )
Q. Write a detailed note on Exceptions in Destructors with the help of a coding
example.
Exceptions in Destructors:
An object is presumably created to do something. Some of the changes made by an object
should persist after an object dies (is destructed) and some changes should not. Take an
object implementing a SQL query. If a database field is updated via the SQL object then
that change should persist after the SQL objects dies. To do its work the SQL object
probably created a database connection and allocated a bunch of memory. When the SQL
object dies we want to close the database connection and deallocate the memory,
otherwise if a lot of SQL objects are created we will run out of database connections
and/or memory.
The logic might look like:
Sql::~Sql()
{
delete connection;
delete buffer;
}
Let's say an exception is thrown while deleting the database connection. Will the buffer
be deleted? No. Exceptions are basically non-local gotos with stack cleanup. The code for
deleting the buffer will never be executed creating a gaping resource leak.
Special care must be taken to catch exceptions which may occur during object
destruction. Special care must also be taken to fully destruct an object when it throws an
exception.
Example code for exception ……
#include<iostream.h>
#include<conio.c>
class Exception {
private:

char message[30] ;
public:
Exception() {strcpy(message,"There is not enough stock");}
char * get_message() { return message; }
};
class Item {
private:
int stock ;
int required_quantity;
public:
Item(int stk, int qty)
{
stock = stk;
required_quantity = qty;
}
int get_stock()
{
return stock;
}
int get_required_quantity()
{
return required_quantity;
}
void order()
{
if (get_stock()< get_required_quantity())
throw Exception();
else
cout<<"The required quantity of item is available in the stock";
}
~Item(){}
};
void main()
{
Item obj(10, 20);
try

{
obj.order();
}
catch(Exception & exp2)
{
getch();
cout << "Exception: " << exp2.get_message() << endl;
}
getch();

CS304 Final term Subjective 2011

1- define composition and give its example with coding
2- what r container classes?how many types of container classes are there?
3- what is virtual inheritance?
4- can a constructor throw exception? If it fails, how should this error be handled?
5- define inheritance and give its example.
6- Three questions were about identification and correction of given coding and reason of error.
7- what is virtual constructor?
8- define static and dynamic binding.

CS304 Final term Paper 2010 - 2

FINALTERM  EXAMINATION
Spring 2010
CS304- Object Oriented Programming (Session - 3)

Time: 90 min
M a r k s: 58
CS304 Question No: 1        
Which one of the following terms must relate to polymorphism?
       ► Static allocation
       ► Static typing
       ► Dynamic binding
       ► Dynamic allocation
   
CS304 Question No: 2        
 Which of the following causes run time binding?
       ► Declaring object of abstract class
       ► Declaring pointer of abstract class
       ► Declaring overridden methods as non-virtual
       ► None of the given
   
CS304 Question No: 3        
 Which of the following is the best approach if it is required to have more than one functions having exactly same functionality and implemented on different data types?
       ► Templates
       ► Overloading
       ► Data hiding
       ► Encapsulation

CS304 Question No: 4        
 Which of the following is the best approach to implement generic algorithms with minimum number of coding lines?
       ► Templates
       ► Overloading
       ► Overriding
       ► Friend function/class
   
CS304 Question No: 5        
 Like template functions, a class template may not handle all the types successfully.
       ► True
       ► False
   
CS304 Question No: 6        
 A class template may inherit from another class template.
       ► True
       ► False
   
CS304 Question No: 7        
 Assume a class Derv that is privately derived from class Base. An object of class Derv located in main() can access
       ► public members of Derv.
       ► protected members of Derv.
       ► private members of Derv.
       ► protected members of Base.

CS304 Question No: 8        
 A copy constructor is invoked when
       ► a function do not returns by value.
       ► an argument is passed by value.
       ► a function returns by reference.
       ► an argument is passed by reference.
   
CS304 Question No: 9        
 Each try block can have ______ no. of catch blocks.
 
       ► 1
       ► 2
       ► 3
       ► As many as necessary.
 
   
CS304 Question No: 10        
 class DocElement
{
public:
      virtual void Print() { cout <
<
};
class Heading : public DocElement
{
public:
      void Print() { cout <
<
};
class Paragraph : public DocElement
{
public:
      void Print() { cout <
<
};
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.

CS304 Question No: 11        
 Suppose we have two derived classes from a single class, can we write a method with same name in both these derived classes ? Choose the best option.
       ► No
       ► Only if the two classes have the same name
       ► Only if the main program does not declare both kinds
       ► Yes
   
CS304 Question No: 12        
 When a virtual function is called by referencing a specific object by name and using the dot member selection operator (e.g., squareObject.draw()), the reference is resolved at compile time.
 
       ► True                
       ► False
   
CS304 Question No: 13        
 Considering the resolution order in which compiler search for functions in a program; the first priority is given to,
       ► general template
       ► partial specialization
       ► complete specialization
       ► ordinary function
   
CS304 Question No: 14        
 Vectors contain contiguous elements stored as a[an] ___.
 
       ► variable
       ► array
       ► function
       ► datatype
   
CS304 Question No: 15        
 By default the vector data items are initialized to ____
       ► 0
       ► 0.0
       ► 1
       ► null
   
CS304 Question No: 16        
 One purpose of an iterator in the STL is to connect algorithms and containers.
 
       ► True
       ► False
   
CS304 Question No: 17        
 Algorithms can only be implemented using STL containers.
 
       ► True
       ► False
   
CS304 Question No: 18        
 In ________, a base class can be replaced by its derived class,
       ► Sub-typing
       ► Super-typing
       ► Multiple-typing
       ► Restricted-typing
   
CS304 Question No: 19        
 this pointer does not point to current object of any class,
       ► True
       ► False
   
CS304 Question No: 20        
 Which of the following operator(s) take(s) one or no argument if overloaded?
       ► ++
       ► -
       ► +
       ► All of the given
 
CS304 Question No: 21        
 Which of the following operators can not be overloaded?
       ► Scope resolution  operator ( :: )
       ► Insertion operator ( <
<
       ► Extraction operator ( >> )
       ► The relation operator ( > )
   
CS304 Question No: 22        
 The type that is used to declare a reference or pointer is called its ---------
       ► default type
       ► static type
       ► abstract type
       ► reference type
   
CS304 Question No: 23        
 ------------- members are somewhere between public and private members. They are used in inheritance
       ► protected
       ► public
       ► private
       ► global
   
CS304 Question No: 24        
 Which of these are examples of error handling techniques ?
       noitanimreTlamronbA►
       ► Graceful Termination
       ► Return the illegal
       ► all of the given
   
CS304 Question No: 25        
 _______ is a relationship
 
       ► Inheritance
       ► Polymarphism
       ► abstraction
       ► encapsulation
   
CS304 Question No: 26        
 Graphical representation of the classes and objects is called object model it shows -------
 
       ► Class Name only
       ► Class Name and attributes
       ► Relationships of the objects and classes
       ► all of the given
   
CS304 Question No: 27    ( M a r k s: 2 )
 Describe the way to declare a template function as a friend of any class.
 
   
CS304 Question No: 28    ( M a r k s: 2 )
 Give the names of any two types of template.
 
CS304 Question No: 29    ( M a r k s: 2 )
 Explain the statement below,
vector ivec(4, 3);

CS304 Question No: 30    ( M a r k s: 2 )
 Q. Enlist the kinds of association w.r.t Cardinality (3)
CS304 Question No: 31    ( M a r k s: 3 )
 Give three advantages that Iterators provide over Cursors.   
CS304 Question No: 32    ( M a r k s: 3 )
 Give the differences between virtual inheritance and multiple inheritance.   
CS304 Question No: 33    ( M a r k s: 3 )
 If we declare a function as friend of a template class will it be a friend for a particular data type or for all data types of that class.   
CS304 Question No: 34    ( M a r k s: 5 )
 See the 5 code snippets below and tell whether these are correct or incorrect also justify your answers in the table given at the end.
 
Snippet No.1
 
template
class A {
} ;
template
class B : public A
{ … }
 
Snippet No.2
 
template
            class B : public A
            { … }   
 
   
 
Snippet No.3
class B : public A
            { … }   
Snippet No.4
          template
            class B : public A
            { … };
 
Snippet No.5
template
class B : public A
{ … }
 
Table:
 
Snippet No.
Is it correct or not (Correct/ Incorrect)
Justification of your answer
1
 
 
2
 
 
3
 
 
4
 
 
5
 
 

CS304 Question No: 35    ( M a r k s: 5 )
 What is the output produced by the following program?
 
#include
 
void sample_function(double test) throw (int);
 
int main()
{
            try
            {
                        cout <<”trying.\n”;
<<”trying.\n”;
                        sample_function(98.6);
                        cout <
<
            }
            catch(int)
            {
                        cout <
<
            }
           
            cout <
<
            return 0;
}
void sample_function(double test) throw (int)
{
            cout <
<
            if(test < 100)
               throw 42;
}

   
CS304 Question No: 36    ( M a r k s: 5 )
 Suppose the base class and the derived class each have a member function with the same signature. When you have a pointer to a base class object and call a function member through the pointer, discuss what determines which function is actually called, the base class member function or the derived-class function.

CS304 Final term papers 2010

FINALTERM EXAMINATION
Spring 2010
CS304- Object Oriented Programming


CS304 - Object Oriented Programming - Q. No: 1

Classes like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete, while classes like Sphere and Cube would normally be abstract.
True
False
CS304 - Object Oriented Programming - Q. No: 2
Virtual functions allow you to
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
CS304 - Object Oriented Programming - Q. No: 3
A pointer to a base class can point to objects of a derived class.
True
False
CS304 - Object Oriented Programming - Q. No: 4
A copy constructor is invoked when
a function do not returns by value.
an argument is passed by value.
a function returns by reference.
an argument is passed by reference.
CS304 - Object Oriented Programming - Q. No: 5
Each try block can have ______ no. of catch blocks.
1
2
3
As many as necessary.
CS304 - Object Oriented Programming - Q. No: 6
Non Template Friend functions of a class are friends of ________instance/s of that class.
All
One specific
All instances of one date type
None of the given options
CS304 - Object Oriented Programming - Q. No: 7
Template functions use _________ than ordinary functions.
Greater Memory
Lesser Memory
Equal Memory
None of the given options

CS304 - Object Oriented Programming - Q. No: 8

The find() algorithm
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.
CS304 - Object Oriented Programming - Q. No: 9 
The copy() algorithm returns an iterator to
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.
CS304 - Object Oriented Programming - Q. No: 10
If you define a vector v with the default constructor, and define another vector w with a one-argument constructor to a size of 11, and insert 3 elements into each of these vectors with push_back(), then the size() member function will return ______ for v and _____ for w.
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.
CS304 - Object Oriented Programming - Q. No: 11
Which is not the Advantage of inheritance?
providing class growth through natural selection.
facilitating class libraries.
avoiding the rewriting of code.
providing a useful conceptual framework.
CS304 - Object Oriented Programming - Q. No: 12
class DocElement
{
public:
virtual void Print() { cout <
<
};
class Heading : public DocElement
{
public:
void Print() { cout <
<
};
class Paragraph : public DocElement
{
public:
void Print() { cout <
<
};
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.
CS304 - Object Oriented Programming - Q. No: 13
Which type of inheritance is being represented by the following statement,
class X : public A, public B { ... ... };
Single inheritance
Multiple inheritance
Double inheritance
None of the given options
CS304 - Object Oriented Programming - Q. No: 14
When we write a class template the first line must be:
template
template
template
Here T can be replaced with any name but it is preferable.
class class-name()
class template
<

CS304 - Object Oriented Programming - Q. No: 15
Function templates should be used where code and behavior must be identical.
True
False
Rational
This will help us to standardized the codes.
They are meant for the situations where same functionality can be adapted to more than one type or class. It will reduce the need of repeating the entire code for each type.

CS304 - Object Oriented Programming - Q. No: 16
Which of the following is/are advantage[s] of generic programming?
Reusability
Writability
Maintainability
All of given
CS304 - Object Oriented Programming - Q. No: 17
The specialization pattern after the name says that this specialization is to be used for every,
data type
meta type
virtual type
pointer type
CS304 - Object Oriented Programming - Q. No: 18
A range is often supplied to an algorithm by two _______ values.
italic
iteration
iterator
None of given
CS304 - Object Oriented Programming - Q. No: 19
Which of the following is an integral part of an object?
State
Behavior
Unique identity
All of the given
CS304 - Object Oriented Programming - Q. No: 20
Consider the following statement
Cupboard has books
What is the relationship between Cupboard and books?
Composition
Aggregation
Inheritance
None of the given options
CS304 - Object Oriented Programming - Q. No: 21
Which sentence clearly defines an object?
one instance of a class.
another word for a class.
a class with static methods.
a method that accesses class attributes.
CS304 - Object Oriented Programming - Q. No: 22
___________, which means if A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.
Friendship is one way only
Friendship is two way only
NO Friendship between classes
Any kind of friendship
CS304 - Object Oriented Programming - Q. No: 23
The statement objA=objB; will cause a compiler error if the objects are of different classes.
True
False
CS304 - Object Oriented Programming - Q. No: 24
Consider the call given below of an overloaded operator "+",
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
CS304 - Object Oriented Programming - Q. No: 25
If a class D has been derived using protected inheritance from class B (If B is a protected base and D is derived class) then public and protected members of B -------- accessed by member functions and friends of class D and classes derived from D
can be
cannot be
does restirct to be
not given
CS304 - Object Oriented Programming - Q. No: 26
In Private -------------- only member functions and friend classes or functions of a derived class can convert pointer or reference of derived object to that of parent object
specialization
inheritance
abstraction
composition
CS304 - Object Oriented Programming - Q. No: 27 ( m a r k s: 2 )
Give two uses of a destructor.
CS304 - Object Oriented Programming - Q. No: 28 ( m a r k s: 2 )
Descibe the way to declare a template class as a friend class of any other class.
CS304 - Object Oriented Programming - Q. No: 29 ( m a r k s: 2 )
Give the name of two basic types of containers collectively called First class containers?
CS304 - Object Oriented Programming - Q. No: 30 ( m a r k s: 2 )
State any conflict that may rise due to multiple inheritance?
CS304 - Object Oriented Programming - Q. No: 31 ( m a r k s: 3 )
What will be the output after executing the following code?
class c1{
public:
virtual void function(){
cout<
<
}
};
class c2: public c1{
public:
void function(){
cout<
<
}
};
class c3: public c1 {
public:
void function(){
cout<
<
}
};
int main(){
c1 * test1 = new c2();
c1 * test2 = new c3();
test1->function();
test2->function();
system(“PAUSE”);
return 0;
}
CS304 - Object Oriented Programming - Q. No: 32 ( m a r k s: 3 )
If we declare a function as friend of a template class will it be a friend for a particular data type or for all data types of that class.
CS304 - Object Oriented Programming - Q. No: 33 ( m a r k s: 3 )
Tell the logical error/s in the code given below with reference to resource management; also describe how we can correct that error/s.
class Test{
public:
int function1(){
try{
FILE *fileptr = fopen(“filename.txt”,“w”);
throw exception();
fclose(fileptr);
return 0;
}
catch(Exception e){
...
}
}
};
CS304 - Object Oriented Programming - Q. No: 34 ( m a r k s: 5 )
What is the output produced by the following program?
#include
void sample_function(double test) throw (int);
int main()
{
try
{
cout <
<
sample_function(98.6);
cout <
<
}
catch(int)
{
cout <
<
}
cout <
<
return 0;
}
void sample_function(double test) throw (int)
{
cout <
<
if(test < 100)
throw 42;
}
CS304 - Object Oriented Programming - Q. No: 35 ( m a r k s: 5 )
The code given below has one template function as a friend of a template class,
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
void Test(U);
template
class B {
int data;
public:
friend void Test( T );
};
template
void Test(U u){
B b1;
b1.data = 7;
}
int main(int argc, char *argv[])
{
char i;
Test(i);
system("PAUSE");
return 0;
}
CS304 - Object Oriented Programming - Q. No: 36 ( m a r k s: 5 )
Consider the following class,
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.
Related Posts Plugin for WordPress, Blogger...