CS304 (P) - Sample Paper
CS304 (P) - Sample Paper
Fall 2022
Time: 90 min
Marks: 40
A. class
B. typename
C. both class & typename (Correct)
D. function
Question No: 2
A. Binding
B. Rebinding
C. Both binding & rebinding (Correct)
D. Reusing
Question No: 3
A. Functions
B. Non-virtual member function
C. Member class
D. All of the mentioned (Correct)
Question No: 4
A. def
B. union
C. typedef (Correct)
D. type
Question No: 5
Question No: 6
Question No: 7
A. Modules
B. Templates (Correct)
C. Virtual functions
D. Abstract Classes
Question No: 8
A. int
B. float
C. Constant expression (Correct)
D. char
Question No: 9
A. without a class
B. with an exact type
C. without blank spaces
D. without specifying the exact type (Correct)
Question No: 10
Question No: 11
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
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
Question No: 18
Question No: 19
Question No: 20
A mechanism that enables us to write a single function or class that works for all data types is
known as _________.
Question No: 21
What is the purpose of using a cursor pointer declared outside an aggregate object?
Question No: 22
Question No: 23
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.
class Circle{
private:
float radius;
public:
….
};
Answer
class Circle{
private:
float radius;
public:
Circle(float r){
Radius = r;
radius = r;
}
float getRadius(){
return radius;
};
#include <cstring>
#include <cstdlib>
#include <iostream>
bool isEqual( T x, T y ) {
return ( x == y );
template< >
return ( strcmp( x, y ) == 0 );
cout<<isEqual( 5, 6 )<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
Answer
0
1
0
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();
};
};
Answer
class A{
private:
float b;
char c;
int a;
public:
A();
};
};
Consider the class diagram given below. Write an overriding “print ()” function for person class
and student class?
Answer
#include<iostream>
class person{
char* name;
public:
person()
name="";
void print()
{
cout<<"name of student"<<name;
};
char* name;
char* major;
public:
name=aname;
major=amajor;
void print()
};
int main()
student std("ali","CS");
std.print();
}
#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
class Complex{
private:
public:
};
int main()
c3= c1+c2;
Answer
Complex t;
return t;