FINALTERM EXAMINATION
Fall 2009
CS304- Object Oriented Programming (Session - 4)
Time: 120 min
Marks: 75
Question No: 1 ( Marks: 1 ) - Please choose one
► variables and data members
► functions and classes
► classes and exceptions
► programs and algorithms
Question No: 2 ( Marks: 1 ) - Please choose one
► Static allocation
► Static typing
► Dynamic binding
► Dynamic allocation
Question No: 3 ( Marks: 1 ) - Please choose one
► The compiler generates only one copy of the function template
► The compiler generates a copy of function respective to each type of data
► The compiler can only generate copy for the int type data
► None of the given.
Question No: 4 ( Marks: 1 ) - Please choose one
► Templates
► Overloading
► Data hiding
► Encapsulation
Question No: 5 ( Marks: 1 ) - Please choose one
class Vector<char*> { }
This is an example of partial specialization.
► True
► False
Question No: 6 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 7 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 8 ( Marks: 1 ) - Please choose one
► public members of Derv.
► protected members of Derv.
► private members of Derv.
► protected members of Base.
Question No: 9 ( Marks: 1 ) - Please choose one
► template <typename T>
► typename <template T>
► Template Class <ClassName>
► Class <Template T>
Question No: 10 ( Marks: 1 ) - Please choose one
► Base
► Derived
► Abstract
► virtual
Question No: 11 ( Marks: 1 ) - Please choose one
► scope resolution operator
► dot operator
► null operator
► Operator overloading
Question No: 12 ( Marks: 1 ) - Please choose one
► All
► One specific
► All instances of one date type
► None of the given options
Question No: 13 ( 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: 14 ( 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: 15 ( Marks: 1 ) - Please choose one
► State
► Behavior
► Protected data members
► All of given
Question No: 16 ( 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: 17 ( 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: 18 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 19 ( Marks: 1 ) - Please choose one
► Only the public member functions of its base classes
► Only the public data members of its base classes
► Both public data members and member functions of all its base classes
► Data members and member functions of any two base classes
Question No: 20 ( 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: 21 ( Marks: 1 ) - Please choose one
► template<class T>
► template <typename U>
► Class<template T>
► template < class T, class U>
Question No: 22 ( Marks: 1 ) - Please choose one
► 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: 23 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 24 ( Marks: 1 ) - Please choose one
1. Car
2. Computer
3. Desk
4. Ahmed
5. Bicycle
6. Truck
► 1, 4, 5
► 2, 5, 6
► 1, 2, 3, 6
► 1, 5, 6
Question No: 25 ( Marks: 1 ) - Please choose one
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: 26 ( Marks: 1 ) - Please choose one
► Have different copies of this variable
► Have same copy of this variable
► Can not access this variable
► None of given
Question No: 27 ( Marks: 1 ) - Please choose one
► Separation
► Composition
► Aggregation
► None of the given
Question No: 28 ( 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: 29 ( Marks: 1 ) - Please choose one
► /
► -
► +
► ++
Question No: 30 ( Marks: 1 ) - Please choose one
► specialization
► inheritance
► abstraction
► composition
Question No: 31 ( Marks: 1 )
Ans:
Pure Virtual Function is a Virtual function with no body. Declaration of Pure Virtual Function:
Since pure virtual function has no body, the programmer must add the notation =0 for declaration of the pure virtual function in the base class.class classname //This denotes the base class of C++ virtual function
{
public:
virtual void virtualfunctioname() = 0 //This denotes the pure virtual function in C++
};
{
public:
virtual void virtualfunctioname() = 0 //This denotes the pure virtual function in C++
};
Question No: 32 ( Marks: 1 )
Ans
When a class-type is included in the class-base, it specifies the direct base class of the class being declared. If a class declaration has no class-base, or if the class-base lists only interface types, the direct base class is assumed to be object. A class inherits members from its direct base class,
Deriving a class from more than one direct base class is called multiple inheritance.
Question No: 33 ( Marks: 2 )
Ans
The following example is use of a class template: template<class L> class Key
{
L k;
L* kptr;
int length;
public:
Key(L);
// ...
};
Suppose the following declarations appear later: Key<int> i;
Key<char*> c;
Key<mytype> m;
The compiler would create three objects. Question No: 34 ( Marks: 2 )
Ans:
There are three kinds of template parameters: - type
- non-type
- template
Question No: 35 ( Marks: 3 )
Ans”
The act of creating a new definition of a function, class, or member of a class from a template declaration and one or more template arguments is called template instantiation. The definition created from a template instantiation is called a specialization. A primary template is the template that is being specialized.
create function objects to do the case-insensitive compares, and
then reuse them when also wanting to do case-insensitive sorting
or searching.
then reuse them when also wanting to do case-insensitive sorting
or searching.
Question No: 36 ( Marks: 3 )
Ans:
the compiler does not make a separate copy of the object. Even if the types are not the same, the compiler is usually able to do a better job with initialization lists than with assignments.
Consider the following constructor that initializes member object x_ using an initialization list: square::square() : x_(whatever) { }. The most common benefit of doing this is improved performance. For example, if the expression whatever is the same type as member variable x_, the result of the whatever expression is constructed directly inside x_ — the compiler does not make a separate copy of the object. Even if the types are not the same, the compiler is usually able to do a better job with initialization lists than with assignments.
As if that wasn't bad enough, there's another source of inefficiency when using assignment in a constructor: the member object will get fully constructed by its default constructor, and this might, for example, allocate some default amount of memory or open some default file. All this work could be for naught if the whatever expression and/or assignment operator causes the object to close that file and/or release that memory (e.g., if the default constructor didn't allocate a large enough pool of memory or if it opened the wrong file).
Question No: 37 ( Marks: 3 )
Ans:
The function will throw DivideByZero as an exception that can then be caught by an exception-handling catch statement that catches exceptions of type int. The necessary construction for catching exceptions is a try catch system. If you wish to have your program check for exceptions, you must enclose the code that may have exceptions thrown in a try block.
The catch statement catches exceptions that are of the proper type. You can, for example, throw objects of a class to differentiate between several different exceptions. As well, once a catch statement is executed, the program continues to run from the end of the catch.
the errors can be handled outside of the regular code. This means that it is easier to structure the program code, and it makes dealing with errors more centralized. Finally, because the exception is passed back up the stack of calling functions, you can handle errors at any place you choose.
Question No: 38 ( Marks: 5 )
class Base{
private:
void base1();
protected:
void base2();
public:
void base3();
};
class Derived: public Base{
private:
void derived1();
protected:
void derived2();
public:
void derived3();
};
int main(){
Derived * derived = new Derived();
return 0;
}
Fill the table below to tell which member functions of Base and Derived classes we can access using the Derived pointer in the code indicated in www.allvupastpapers.blogspot.com
bold.
Ans:
Function Name | Availability (Yes / No)? |
base2() | no |
base3() | yes |
derived1() | No |
derived2() | No |
derived3() | Yes |
Question No: 39 ( 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;
}
Ans:
Starting sample_function
Trying
Trying after call
Catching
End program
Question No: 40 ( Marks: 10 )
In “main” Create an object of base class and call both functions with same object type.
Question No: 41 ( Marks: 10 )
1. Equation
2. Linear
3. Quadratic
Where Linear and Quadratic are inherited from Equation
Each class has the method Graph. Graph method should be pure virtual in Equation class.
This method should be overridden in both the inherited classes. It is meant to display the Graph shape of its respective class. Graph method of Linear will display the message;
Straight line
Similarly, the Graph method of Quadratic will display the message;
Parabola
In main, call the Graph method of both the Linear and Quadratic equations polymorphically through the parent class (Equation).
Ans:
#include "fraction.h"
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
class equation;
class equation {
int a, b;
public:
int c ()
{
return (c);}
void convert (Cequation);
};
class linear {
private:
int side;
public:
void set_side (
int a)
{side=a;}
friend
class equation;
};
void equation::convert (Cequation) {
a = 23;
b = 45;
}
int main () {
cequation sqr;
CRectangle rect;
sqr.set_side(4);
rect.convert(sqr);
cout << rect.area();
return 0;
}
No comments:
Post a Comment
PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE
Note: Only a member of this blog may post a comment.