0% found this document useful (0 votes)
54 views12 pages

CT-2 QP - Set D - Answer

The document discusses a test for an object oriented design and programming course. It contains a course articulation matrix mapping course outcomes to program outcomes. It also contains 20 multiple choice questions covering topics like inheritance, polymorphism, templates and exceptions in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views12 pages

CT-2 QP - Set D - Answer

The document discusses a test for an object oriented design and programming course. It contains a course articulation matrix mapping course outcomes to program outcomes. It also contains 20 multiple choice questions covering topics like inheritance, polymorphism, templates and exceptions in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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 ProgrammingDuration: 2 periods
Year & Semester:I / II Max. Marks: 50
SET D
Course Articulation Matrix:(to be placed)

Sl.No Course
PO PO PO PO PO PO PO PO PO P1 P1 P1
. Outcome
1 2 3 4 5 6 7 8 9 0 1 2
s
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 Mark BL CO PO PI
No s Code
1 In hierarchical inheritance, do members of base class 1 4 3 2 2.4.3
get divided among all of its child classes?
a. Yes, equally
b. Yes, depending on type of inheritance
c. No, it’s doesn’t get divided
d. No, it may or may not get divided
2 In hierarchical inheritance, each class can inherit the 1 2 3 1 1.3.1
base class________________
a. Independently using any inheritance
b. Independently with private inheritance only
c. With same type of inheritance
d. With each class using different inheritance only
3 A friend function declaration appears_________ 1 1 3 1 1.3.1
a. Outside of the class
b. Inside the class declaration to which it is a
friend
c. As a separate declaration inside main()
d. Anywhere prior to the function invocation
4 What is the correct output of given code snippets in 1 3 3 2 2.4.1
C++?
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
class compare
{
int n=100;
char c='a';
friend int larger(compare,compare);
};
int larger(compare c1,compare c2)
{
if (c1.n>c2.c)
return c1.n;
else
return c2.c;
}
int main() {
// Write C++ code here
compare c1,c2;
cout<<larger(c1,c2);

return 0;
}

a. 100
b. 97
c. Run time error
d. ‘a’
5 Which amongst the following is true for hybrid 1 1 3 2 2.1.2
inheritance?
a. Constructor calls are in reverse
b. Constructor calls are priority based
c. Constructor of only derived class is called
d. Constructor calls are usual
6 If hierarchical inheritance requires to inherit more 1 1 3 2 2.1.2
than one class to single class, which syntax is correct?
(A, B, C are class names)
a. hierarchical class A: public B, public C
b. multiple class A: public B, public C
c. many class A: public B, public C
d. class A: public B, public C
7 Show the correct statement 1 3 3 5 3.3.2
a. Pure virtual functions and virtual functions are
the same
b. Both Pure virtual function and virtual function
have an implementation in the base class
c. Pure virtual function has no
implementation in the base class whereas
virtual function may have an
implementation in the base class
d. The base class has no pure virtual function
8 Which is the correct syntax of defining a pure virtual 1 1 3 5 5.2.1
function?
a. pure virtual return_typefunc();
b. virtual return_typefunc() pure;
c. virtual return_typefunc() = 0;
d. virtual return_typefunc();
9 1 2 3 2 2.1.3
What happens to a function defined inside a class
without any complex operations (like looping, a large
number of lines, etc)?
a. It becomes virtual function
b. It becomes friend function
c. It becomes inline function
d. It gives error while compiling
10 .A ________ is a behavior that specifies the sequence 1 1 3 5 5.1.1
of states an object goes through during its lifetime in
response to events.
a. class
b. state machine
c. use case
d. activity
11 How Exception handling is implemented in the C++ 1 2 4 2 1.3.1
program?
a. Using Exception keyword
b. Using try-catch block
c. Using Exception block
d. Using Error handling schedules
12 What id the syntax for catching any type of 1 2 4 2 1.3.1
exceptions?
a. catch(Exception e)
b. catch(…)
c. catch(Exception ALL)
d. catch(ALL)
13 Templates are initiated at_______________________ 1 1 4 2 2.1.2
a. Runtime
b. Compile time
c. At the time of Object creation
d. None of the above

14 Which type of exception caused by events or faults 1 1 4 1 1.4.1


unrelated (external) to the program and beyond the
control of the program?
a. Synchronous Exception
b. Asynchronous exception
c. Internal exception
d. Zero value exception
15 What is the difference between normal function and 1 1 4 3 2.4.1
template function?
a. Unlike a normal function, the template function
accepts a single parameter
b. Unlike the template function, the normal function
accepts more than one parameter
c. Template function works with any data types
whereas normal function works with specific types
only
d. The normal function works with any data types
whereas template function works with specific types
only
16 Which one is generally used in class templates? 1 2 4 2 3.3.1
a. Data storage
b. Debug
c. fixed data type
d. Storage
17 Identify the validity of template parameters. 1 2 4 5 5.1.1
a. inside that block only
b. inside the class
c. whole program
d. inside the main class
18 which diagrams are used to distribute files, libraries, 1 1 4 5 5.1.2
and tables across topology of the hardware
A) deployment
B) use case
C) sequence
D) collaboration
19 How good packages are coupled and highly cohesive 1 2 4 3 3.3.1
among the elements in package?
a. Tightlyb. Highly
c. loosely
d. None of the above
20 Which of these are types of nodes used in the 1 2 4 3 2.4.1
deployment diagram?
a) Device
b) Execution Environment
c) Artifact
d) Device & Execution Environment
SET D

PART- B (2 * 10=20 Marks)


CONCEPT UNDERSTANDING
21 (i) "Friends should be used only for limited 3+7 3 1 2 2.6.3
A purposes". Justify the statement.
Answer:
Friends should be used only for limited purposes.
Too many functions or external classes are
declared as friends of a class with protected or
private data access lessen the value of
encapsulation of separate classes in object-
oriented programming.

#include <iostream>
using namespace std;

// Forward declaration
class ABC;

class XYZ {
int x;

public:
void set_data(int a)
{
x = a;
}

friend void max(XYZ, ABC);


};

class ABC {
int y;

public:
void set_data(int a)
{
y = a;
}

friend void max(XYZ, ABC);


};

void max(XYZ t1, ABC t2)


{
if (t1.x > t2.y)
cout << t1.x;
else
cout << t2.y;
}

// Driver code
int main()
{
ABC _abc;
XYZ _xyz;
_xyz.set_data(20);
_abc.set_data(35);

// calling friend function


max(_xyz, _abc);
return 0;
}
Output
35

(ii) What are exceptions? List some of


common exceptions along with brief
descriptions.
OR
21 What is Multilevel inheritance? Give an example in 10 2 3 2 3.2.1
B C++ to demonstrate Multilevel inheritance.

Answer:
A derived class can be derived from another derived
class. A child class can be the parent of another class.

Syntax:
class A // base class
{
..........
};
class B
{
..........
}
class C : access_specifier B
// derived class
{
...........
};
// base class
class Vehicle
{
public:
Vehicle()
{
cout << "This is a Vehicle";
}
};
class fourWheeler: public Vehicle
{ public:
fourWheeler()
{
cout<<"Objects with 4 wheels are
vehicles"<<endl;
}
};
// sub class derived from two base classes
class Car: public fourWheeler{
public:
car()
{
cout<<"Car has 4 Wheels”;
}
};
// main function
int main()
{
//creating object of sub class will
//invoke the constructor of base classes
Car obj;
return 0;
}

22 Draw an activity diagram with swimlanes for an 10 2 4 5 5.1.2


A example for ATM for a cash withdrawal use case.
Show the three involved classes (people, etc.) of the
activity namely Customer, ATM, and Bank in the
diagram.

OR
22 Global group requires a system to be developed for 10 2 4 5 5.1.1
B maintenance of leaves in their organization. There are
different types of leaves: Casual leaves, Medical
leaves, Earned leaves and special leaves. These leaves
vary from employee to employee. If the employee is
regular he can avail all types of leaves. An adhoc
employee can only avail casual leaves. The medical
and earned leaves can be credited in the employees
account. The maximum limit of the credit is 240.
Further if an employee has availed all the leaves his
salary may be deducted. Draw an activity diagram for
the scenario.
PART – C (1*10=10 Marks)
SCENARIO BASED/HOTs
23 Design a simple Calculator performing the four basic 10 3 3 3 3.2.2
A arithmetic operations in C++ using a class template.
The template of the class will consist of two variables
whose values are passed at the time of object creation.
The constructor of this class takes two arguments of
generic datatypes. Further, this Calculator class
template consists of five main functions – show(),
addition(), subtraction(), multiplication(), and
division(). The show() function is responsible for
calling the rest of the four generic functions. Created
two instances from the template of Calculator class
and performed the basic calculations using its class
functions

template <class Temp>


class Calculator
{
private:
Temp n1, n2;

public:
Calculator(Temp num1, Temp num2)
{
n1 = num1;
n2 = num2;
}
void show()
{
cout<< "Addition is: " << n1 << "+" << n2 << "="
<<addition() <<endl;
cout<< "Subtraction is: " <<n1 << "-" << n2 << "="
<<subtraction() <<endl;
cout<< "Product is: " << n1 << "*" << n2 << "="
<<multiplication() <<endl;
cout<< "Division is: " << n1 << "/" << n2 << "="
<<division() <<endl;
}

Temp addition() { return (n1 + n2); }

Temp subtraction() { return n1 - n2; }

Temp multiplication() { return n1 * n2; }

Temp division() { return n1 / n2; }


};

int main()
{
Calculator<int> Calc1(25, 12);
Calculator<float> Calc2(13.6, 5.9);

cout<< "Integer results for 25 and 12:" <<endl;


Calc1.show();

cout<<endl<< "Float results for 13.6 and 5.9:"


<<endl;
Calc2.show();

return 0;
}
Output

OR
23 Construct a class named Fruit with a data member to 10 2 4 5 5.1.1
B calculate the number of fruits in a basket. Create two
other class named Apples and Mangoes to calculate
the number of apples and mangoes in the basket. Print
the number of fruits of each type and the total number
of fruits in the basket.

#include <iostream>
using namespace std;
class Fruit
{
public:
static int fruitCounter;
Fruit()
{
fruitCounter++;

}
~Fruit()
{
fruitCounter--;
}
};
class Apples: public Fruit
{
public:
static int applesCounter;
Apples():Fruit()
{
applesCounter++;

}
~Apples()
{
applesCounter--;
}
};
class Mangoes: public Fruit
{
public:
static int mangoesCounter;
Mangoes():Fruit()
{
mangoesCounter++;
}
~Mangoes()
{
mangoesCounter--;
}
};
int Fruit::fruitCounter = 0;
int Apples::applesCounter = 0;
int Mangoes::mangoesCounter = 0;
int main()
{
Apples firstApple,secondApple,thirdApple;
Mangoes
firstMango,secondMango,thirdMango,fourthMango;
cout<< "Total number of fruits: "
<<Fruit::fruitCounter<<endl;
cout<< "Number of apples: "
<<Apples::applesCounter<<endl;
cout<< "Number of mangoes: "
<<Mangoes::mangoesCounter<<endl;
return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy