English 5555

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Sample Paper

FINAL TERM EXAMINATION

Fall 2022

CS304(P) - Object Oriented Programming(Practical)

Time: 90 min

Marks: 40

Question No: 1 (Marks: 01) - Please choose the correct option

What is the keyword used in templates in C++?

A. class
B. typename
C. both class & typename (Correct)
D. function

Question No: 2

What is the purpose of using the "::" template-template parameter in C++?

A. Binding
B. Rebinding
C. Both binding & rebinding (Correct)
D. Reusing

Question No: 3

What does not require instantiation in C++?

A. Functions
B. Non-virtual member function
C. Member class
D. All of the mentioned (Correct)

Question No: 4

What is the keyword used to define user-defined data types in C++?


A. def
B. union
C. typedef (Correct)
D. type

Question No: 5

What is the scope of data types defined with typedef in C++?

A. Inside that block only


B. Whole program (Correct)
C. Outside the program
D. Main function

Question No: 6

What is a template in C++?

A. A formula for creating a generic class (Correct)


B. A tool for manipulating a class
C. A way of creating attributes
D. None of the given

Question No: 7

What is used for generic programming in C++?

A. Modules
B. Templates (Correct)
C. Virtual functions
D. Abstract Classes

Question No: 8

What can be passed by non-type template parameters at compile time in C++?

A. int
B. float
C. Constant expression (Correct)
D. char

Question No: 9

Function template in C++ is a way of creating a function___________.


A. without a class
B. with an exact type
C. without blank spaces
D. without specifying the exact type (Correct)

Question No: 10

Which of the following is not an advantage of using Templates in C++?

A. High Reliability (Correct)


B. Reusability
C. Writability
D. Generic Programming

Question No: 11

Which one of the following is not a type of inheritance in C++?


A. public
B. virtual (Correct)
C. private
D. protected

Question No: 12

In C++ inheritance, is it possible for a child class to initialize its indirect base classes
through its constructor initialization list?
A. Yes, it is possible
B. No, it is not possible (Correct)
C. It depends on the implementation.
D. Only if the indirect base classes are direct base classes of the child class.

Question No: 13

How many classes are required to implement the multiple inheritance in a program?
A. Only two
B. At least two
C. At least three (Correct)
D. Only four

Question No: 14

_____________ is used to solve multiple inheritance issues.


A. Virtual inheritance (Correct)
B. Friend functions
C. Generic programming.
D. Templates
Question No: 15

What is multiple inheritance in Object-Oriented (OO) programming?

A. a derived class inherits from multiple base classes. (Correct)


B. a base class inherits from multiple derived classes.
C. a class inherits from a single base class.
D. a class cannot inherit from any base class.

Question No: 16

A/an __________ is a template definition of methods and variables of a class and its
object cannot be instantiated.
A. virtual class
B. static class
C. concrete class
D. abstract class(Correct)

Question No: 17

Specialization (Restriction) can be implemented using both ______ and ___________


inheritance.
A. Public, Protected
B. Private Protected (Correct)
C. Virtual, Protected
D. Public, Virtual

Question No: 18

Correct format to declare a template function is _______________.


A. template< class T >
void funName( T x ); (Correct)

B. template< classfunction T >


void funName( T x );

C. template< Function T >


void funName( T x );

D. template< class T function F>


void funName( T x );

Question No: 19

The target function for a call is selected at run-time is known as_____________.


A. Dynamic binding (Correct)
B. Static binding
C. Function binding
D. Object binding

Question No: 20

A mechanism that enables us to write a single function or class that works for all data
types is known as _________.

A. Generic programming (Correct)


B. Imperative programming
C. Functional programming
D. Logic programming

Question No: 21

What is the purpose of using a cursor pointer declared outside an aggregate object?

A. Traverse elements (Correct)


B. Store fixed value
C. Store multiple values
D. Store address

Question No: 22

Which of the following is not a method to traverse the element in a cursor?


A. T* first()
B. T* beyond()
C. T* next( T* )
D. T* prev(T*) (Correct)

Question No: 23

Cursor works fine when we have _______ memory.


A. Contagious (Correct)
B. Non-contagious
C. Static
D. Dynamic

Question No: 24

Which of the following is not a key component of STL (Standard Template Library)?
A. Containers
B. Iterators
C. Algorithms
D. Map (Correct)

Question No: 25 (Marks: 05)

Consider the following code named "Circle", you are required to write the following
methods for the Radius class.

a. One Parameter Constructor

b. Setter and Getter

class Circle{

private:

float radius;

public:

….

};

Answer

class Circle{

private:

float radius;

public:

Circle(float r){

Radius = r;

}
void setRadius(float r){

radius = r;

float getRadius(){

return radius;

};

Question No: 26 (Marks: 05)

What will be the output of the following C++ Code?

#include <cstring>

#include <cstdlib>

#include <iostream>

using namespace std;

template< typename T >

bool isEqual( T x, T y ) {

return ( x == y );

template< >

bool isEqual< const char* >(

const char* x, const char* y ) {

return ( strcmp( x, y ) == 0 );

int main (){


cout<<isEqual( 5, 6 )<<"\n";

cout<<isEqual( 7.5, 7.5 )<<"\n";

cout<<isEqual( "abc", "aba" )<<"\n";

system("PAUSE");

return EXIT_SUCCESS;

Answer

0
1
0

Question No: 27 (Marks: 05)

Considering the following code, make changes in such a way that the compiler will
initialize the data members in the following order: b, c, a,

class A{

private:

int a;

float b;

char c;

public:

A();

};
A::A(): b(2.5), c(‘a’), a(2) {

};

Answer

class A{

private:

float b;

char c;

int a;

public:

A();

};

A::A(): b(2.5), c(‘a’), a(2) {

};

Question No: 28 (Marks: 05)

Consider the class diagram given below. Write an overriding “print ()” function for
person class and student class?
Answer

#include<iostream>

using namespace std;

class person{

char* name;

public:

person()

{
name="";

void print()

cout<<"name of student"<<name;

};

class student: public person

char* name;

char* major;

public:

student(char* aname, char* amajor)

name=aname;

major=amajor;

void print()

cout<<"name of the student"<<name;

cout<<"major of the student"<<major;

}
};

int main()

student std("ali","CS");

std.print();

Question No: 29 (Marks: 05)

What will be the output of the following C++ Code?

#include <string.h>
#include <iostream>
using namespace std;

class CaseSenCmp {
public:
static int isEqual( char x, char y ) {
return x == y;
}
};
class NonCaseSenCmp {
public:
static int isEqual( char x, char y ) {
return toupper(x) == toupper(y);
}
};
template< typename C >
int compare( char* str1, char* str2 )
{
for (int i = 0; i < strlen( str1 ) && i < strlen( str2 ); i++)
if ( !C::isEqual (str1[i], str2[i]) )
return str1[i] - str2[i];
return strlen(str1) - strlen(str2);
};
int main() {
int i, j;
char *x = "hello", *y = "HELLO";
i = compare< CaseSenCmp >(x, y);
j = compare< NonCaseSenCmp >(x, y);
cout << "Case Sensitive: " << i;
cout << "\nNon-Case Sensitive: "<< j << endl;
return 0;
}

Answer

Case Sensitive: 32
Non-case Sensitive: 0

Question No: 30 (Marks: 05)

Write a C++ code of overloaded addition operator (+).

class Complex{

private:

double real, img;

public:

//write code here

};

int main()

Complex c1, c2, c3;

c3= c1+c2;
}

Answer

Complex Complex::operator +( const Complex & rhs){

Complex t;

t.real = real + rhs.real;

t.img = img + rhs.img;

return t;

You might also like