You are on page 1of 10

SRM Institute of Science and Technology

Faculty of Engineering and Technology


School of Computing
SRM Nagar, Kattankulathur – 603203, Chengalpattu District, Tamilnadu
Academic Year:2022 -2023EVEN
Test: CLA T-2 Date: 18-04-2023
Course Code &Title:21CSC101T – Object Oriented Design and Programming Duration: 2 periods
Year &Semester:I / II Max. Marks: 50

SET A

Course Articulation Matrix:

Sl.No. Course
Outcomes PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 P10 P11 P12

1 CO1 - 2 2 - 2 - - - - - - 3
2 CO2 - 2 2 - 2 - - - - - - 3
3 CO3 - 2 2 - 2 - - - - - - 3
4 CO4 - 2 2 - 2 - - - - - - 3
5 CO5 - 2 2 - 2 - - - - - - 3

PART– A (20*1 =20 Marks)

Q. MCQ Marks BL CO PO PI
No Code
1 Find the type of inheritance in which more than one 1 2 3 1 1.3.1
class inherits the property of a single base class.
a. Multiple inheritance
b. Hierarchical inheritance
c. Multi-level inheritance
d. Hybrid inheritance

2 What will be the output of the following C++ code? 1 4 3 2 2.1.3


#include <iostream>
#include <string>
using namespace std;
class A {
float d;
public:
int a;
void change(int i){
a = i;
}
void value_of_a(){
cout<<a;
}
};
class B: public A {
int a = 15;
public: void print(){
cout<<a;
}
};
int main(int argc, char const *argv[]) {
B b;
b.change(10);
b.print();
b.value_of_a();
return 0;
}
a. 1010
b. 1510
c. 1515
d. 5110
3 Which rule will not affect the friend function? 1 1 3 1 1.3.1
a. Private and protected members of a class
cannot be accessed from outside
b. Private and protected can be accessed from
anywhere
c. Protected member can be accessed anywhere
d. Private member can be accessed anywhere
4 Pick out the correct statement. 1 2 3 2 1.3.1
a. A friend function may be a member of another
class
b. A friend function may not be a member of
another class
c. A friend function may or may not be a
member of another class
d. A friend function can be only accessed by
object of the class
5 Which among the following best defines the hybrid 1 1 3 1 1.4.1
inheritance?
a. Combination of two or more inheritance
types
b. Combination of same type of inheritance
c. Inheritance of more than 7 classes
d. Inheritance involving all the types of
inheritance
6 In C++, when the inheritance is private, the private 1 1 3 2 2.1.2
methods in base class are __________ inthe derived
class.
a. Inaccessible
b. Accessible
c. Protected
d. Public
7 A virtual function is a member function of which of 1 1 3 2 2.4.1
the following class?
a. Derived class
b. Parent class
c. base class
d. Both A and B
8 A virtual function is redefined in which of the 1 1 3 3 2.4.1
following class?
a. Derived class
b. Parent class
c. base class
d. Both A and B
9 UML activity diagrams are useful in representing 1 1 3 5 5.1.2
which analysis model elements?
a. behavioral elements
b. class-based elements
c. flow-based elements
d. scenario-based
10 In an Activity Diagram, organizing the activities into 1 1 3 5 5.1.1
groups is called ________
a. forking
b. joining
c. swimlane
d. synchronization
11 What is a function template? 1 1 4 5 5.2.1
a. creating a function without class
b. creating a function with having an exact type
c. creating a function without having blank spaces
d. creating a function without having to specify the
exact type
12 Which of the following is used for generic 1 1 4 4 5.1.2
programming?
A. Modules
B. Templates
C. Virtual functions
D. Abstract Classes
13 What is the syntax for defining a user-defined exception 1 1 4 2 2.4.1
class in C++?
a) DECLARE EXCEPTION;
b) DECLARE my-exception EXCEPTION;
c) DECLARE my-exception;
d) EXCEPTION;
14 If inner catch block is unable to handle the exception 1 1 4 3 2.4.1
thrown then__________
a). Program stops abnormally
b). The compiler looks for the outer try-catch block
c). The compiler will check for appropriate catch
handler of the outer try block
d) The compiler will not check for appropriate catch
handler of the outer try block ·
15 The C++ code which causes abnormal 1 1 4 1 2.4.1
termination/behaviour of a program should be written
under _________ block.
A) try
b) catch
c) throw
d)finally
16. Which of the following diagram displays the structural 1 1 4 2 2.4.1
relationship of components of a software?
A) Component Diagram
B) class diagram
C)use case diagram
D)deployment diagram
17 Select the correct example for default arguments with the 1 1 4 3 5.1.2
template class?
a. template<class K=int, typename>.
b. template<class K, typename V=string>
c. Template<class K=char, int>
d. template<typenmae K(double), class V>
18 Identify the proper syntax for the template class definition. 1 1 4 3 5.1.2
a. template <typename X, class Z> class named (Z n1, Z
n2);
b. Template <class X, typename Z>;
c. Template <class X, class Z> X named(X n1, Z n2){ }
d. template <typename Z> class named{Z n1, Z n2; };

19 Which diagram helps in the various packages of a software 1 1 4 2 2.4.1


system and the dependencies between them.?
a. package diagram
b. Component Diagram
c. Class Diagram
d. Sequence Diagram

20 List the 3 essential elements of a deployment diagram. 1 1 4 3 2.4.1


a) artifacts, nodes and connections
b) stack, queue, deque
c) memory, database, connections
d) package, element, deployment
SET A

PART- B (2 * 10=20 Marks)


CONCEPT UNDERSTANDING
21 #include<iostream> 3+7 3 3 3 3.4.2
A using namespace std;
class Base
{
};
class Derived: public Base
{
};
int main()
{
Base *bp = new Derived;
Derived *dp = new Base;
}
(i) What is the output of the above program?
Justify your answer.

compiler error.
Explanation: A Base class pointer/reference
can point/refer to a derived class object, but
the other way is not possible.

(ii) Discuss the approaches to handling exceptions


in C++ with examples.

n exception is a problem that arises during the


execution of a program. A C++ exception is a
response to an exceptional circumstance that arises
while a program is running, such as an attempt to
divide by zero.

Exceptions provide a way to transfer control from one


part of a program to another. C++ exception handling
is built upon three keywords: try, catch, and throw.

 throw − A program throws an exception when


a problem shows up. This is done using a
throw keyword.
 catch − A program catches an exception with
an exception handler at the place in a program
where you want to handle the problem. The
catch keyword indicates the catching of an
exception.
 try − A try block identifies a block of code
for which particular exceptions will be
activated. It's followed by one or more catch
blocks.

#include<iostream>
usingnamespace std;
doubledivision(int a,int b){
if( b==0){
throw"Division by zero condition!";
}
return(a/b);
}

int main (){


int x =50;
int y =0;
double z =0;

try{
z =division(x, y);
cout<< z <<endl;
}catch(constchar*msg){
cerr<<msg<<endl;
}

return0;
}

OR
21 Write a C++ program using class templates. The 10 3 3 3 3.4.2
B template can contain multiple arguments, and it
should use the non-type arguments in addition to the
type T argument.
#include <iostream>
usingnamespacestd;

// Function to swap two numbers


template<classT>
voidswap_(T* x, T* y)
{
T temp = *x;
*x = *y;
*y = temp;
}

// Function to implement the Bubble Sort


template<classT, intsize>
voidbubble_sort(T arr[])
{
for(inti = 0; i< size - 1; i++) {

// Last i elements are already


// in place
for(intj = 0; j < size - i - 1; j+
+) {
if(arr[j] >arr[j + 1]) {

// Swap operation
swap_(&arr[j], &arr[j +
1]);
}
}
}
}

// Function to print an array


template<classT, intsize>
voidprintArray(T arr[])
{
inti;
for(i = 0; i< size - 1; i++) {
cout<<arr[i] << ", ";
}

cout<<arr[size - 1] <<endl;
}

// Driver Code
intmain()
{
// Given array arr[]
floatarr[] = { 1.1, 1.2, 0.3, 4.55,
1.56, 0.6 };
constintsize_arr = sizeof(arr) /
sizeof(arr[0]);

// Size of the array passed as


// an argument to the function
bubble_sort<float, size_arr>(arr);

cout<< "Sorted Array is: ";


printArray<float, size_arr>(arr);

return0;
}

22 You are working as a Project Delivery owner in a 10 3 4 4 3.4.2


A DreamCorpPvt. Limited. You are required to send a
proposal to the new clients of your company. Draw the
business process for planning a meet, gathering the client
requirements and sending the proposal to the new client
using an activity Diagram with Swimlane.

OR
22 Draw a UML component diagram for an online shopping 10 3 4 4 3.4.2
B system with three related subsystems - WebStore,
Warehouses, and Accounting. The necesssary features of
Search Engine, Shopping Cart, and Authentication,
Manage Orders and Manage Customers are provided.
Draw the state chart for the order processing use case.

PART – C (1*10=10 Marks)


SCENARIO BASED/HOTs
23 Create two classes named Mammals and MarineAnimals. 10 3 3 3 3.4.3
A Create another class named BlueWhale which inherits both
the above classes. Now, create a function in each of these
classes which prints "I am mammal", "I am a marine
animal" and "I belong to both the categories: Mammals as
well as Marine Animals" respectively. Now, create an
object for each of the above class and try calling
1 - function of Mammals by the object of Mammal
2 - function of MarineAnimal by the object of
MarineAnimal
3 - function of BlueWhale by the object of BlueWhale
4 - function of each of its parent by the object of
BlueWhale

Declaration of class – 2 Marks


Usage of inheritance– 4 Marks
Main Function – 2 Mark
Sample Input and Output –2Mark

#include <iostream>
using namespace std;
class Mammals{
public:
void displayMammal() {
cout<< "I am mammal" <<endl;
}
};
class MarineAnimals {
public:
void displayMarine() {
cout<< "I am a marine animal" <<endl;
}
};
class BlueWhale : public Mammals, public MarineAnimals {
public:
void displayBW() {
cout<< "I belong to both the categories: Mammals as
well as Marine Animals" <<endl;
}
};
int main()
{
Mammals m;
MarineAnimals ma;
BlueWhalebw;
m.displayMammal();
ma.displayMarine();
bw.displayBW();
bw.displayMammal();
bw.displayMarine();
return 0;
}

[OR]
23 Write a C++ program for implementing the concept of 10 3 4 3 3.4.3
B class template. Create the template class myFirstclass.
Inside this, create a constructor that will initialize the two
members num1 and num2 of the class. Find minimum and
maximum of that two numbers using different data
arguments such as int, float , double and string concepts
using Function template concepts.

#include <iostream>
using namespace std;
template <class T>
class myFirstclass {
private:
T num1, num2;
public:
myFirstclass (T n1, T n2) {
num1 = n1;
num2 = n2; }
void displayResult() {
cout<< "Numbers: " << num1 << " and " << num2 << "."
<<endl;
cout<< “Minimum” << minimum(num1,num2) << endl;
cout<< “Maximum” <<maximum(num1,num2) <<endl; }
T minimum() { if(num1<num2) return num1; }
T maximum() { if(num1>num2) return num1; }
};
int main() {
myFirstclass <int>intCalc(2, 1);
myFirstclass <float>floatCalc(2.4, 1.2);
myFirstclass <double>doubCalc(22.445, 11.56);
myFirstclass <string>stringCalc(“Hello”,”Hi”);
cout<< "Int results:" <<endl;
intCalc.displayResult();
cout<<endl
<< "Float results:" <<endl;
floatCalc.displayResult();
cout<<endl
<< "Double results:" <<endl;
doubCalc.displayResult();
cout<<endl
<< "String results:" <<endl;
stringCalc.displayResult();
return 0;
}

You might also like