You are on page 1of 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 Programming Duration: 2 periods
Year &Semester:I / II Max. Marks: 50

SET C
Course Articulation Matrix:(to be placed)

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 Consider the base class “Shape” . The classes 1 4 3 2 2.1.3
“Triangle”, “Circle”, and “Square” are derived from
the base class. Which of the following is incorrect
derivation?
a. class Triangle: public Shape
b. class Circle: public Shape
c. class Shape: public Triangle
d. class Square: public Shape

2 Consider that A is a parent class; B and C are the sub 1 4 3 2 2.4.3


classes. Which of the following is incorrect?
a. Object of B can access properties of A
b. Object of C can access properties of A
c. Object of C can access properties of B
d. Both options (a) and (b) are correct
3 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
4 How is a static member function similar to a friend 1 2 3 2 1.3.1
function?
a. A static member function is like a friend
function that doesn't need to be public
b. A friend function is similar to binary operator
overloading.
c. Friend function does not have access to class’s
private members
d. Friend function have implicit this operator
5 If single inheritance is used with class A and B. A is 1 1 3 2 2.1.2
base class. Then class C, D and E where C is base
class and D is derived from C, then E is derived from
D. Class C is made to inherit from class B. Which is
the resultant type?
a. Single level
b. Multilevel
c. Hybrid
d. Multiple
6 What will be the output of this program? 1 4 3 2 2.1.3

#include <iostream>

using namespace std;


class Base {};
class Derived: public Base {};

int main()
{
Base *p = new Derived;
Derived *q = new Base;
}
a. error: invalid conversion from
"Derived*" to "Base*"
b. No Compiler Error
c. error: invalid conversion from
"Base*" to "Derived*"
d. Runtime Error
7 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
8 In late binding, the function call is resolved during? 1 2 3 2 3.3.1
a. runtime
b. Compile time
c. Infinite time
d. Load time
9 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
10 ________ is used to represent concurrent flows in an 1 1 3 5 5.1.2
Activity Diagram
a. slide bar
b. synchronization bar
c. swim lane
d. branch
11 It is a specialised form of the Uml class diagram. 1 2 4 2 1.3.1
a. Package Diagram.
b. Component Diagram.
c. Activity Diagram.
d. Deployment Diagram
12 Identify the program output 1 2 4 2 1.3.1
#include <iostream>
using namespace std;
template <class T, class U>
class A { T x; U y; static int count; };
int main()
{ A<float, float> p;
A<int8_t, int8_t> q;
cout<<sizeof(p) <<endl; cout<<sizeof(q) <<endl;
return 0; } a. Syntax error
b. 8 8
c. 8 4
d. 8 2
13 What can non-type template arguments pass during 1 1 4 2 2.1.2
compilation?
a. Char.
b. int
c. float
d. constant expression
14 How is the C++ program's exception handling 1 1 4 1 1.4.1
implemented?
a. by try-catch block.
b. by Exception block
c. by Exception keyword
d. by Error Handling methods
15 An issue that occurs when a programme is being 1 1 4 3 2.4.1
executed is called as _____
a. Templates
b. Exception
c. Syntax Error
d. Semantical Error
16 Identify the program output 1 2 4 2 3.3.1
#include <iostream>
using namespace std;
template <typename T>
T max (T& p, T& q)
{ return (p<q?p:q); }
int main ()
{ int x = 55, y = 60, m;
long a = 105, b = 53, n;
m = max(x, y);
n = max(a, b);
cout<< m <<endl;
cout<< n <<endl; return 0; }
Which one will be correct?
a. 60,105
b. 55,53
c. 53,55
d. 105,55
17 In Component Diagram, Components 1 2 4 5 5.1.1
communicate with each other using which of
the following?
(A). Components
(B). interfaces
(C). Use cases
(D). attributes

18 Which among the following are not the valid 1 1 4 5 5.1.2


notations for packageand component diagram?

a) Notes

b) Box

c) Extension Mechanisms

d) Packages
19 To define a custom exception, which header file need 1 2 4 3 3.3.1
to be included
a. except
b. exception
c. userexcept
d. iostream
20 Which returns the cause of a user defined exception? 1 2 4 3 2.4.1
a. what()
b. try block
c. catch block
d. exception class
SET C

PART- B (2 * 10=20 Marks)


CONCEPT UNDERSTANDING
21 (i) "The class that contains the pure virtual 5+5 2 3 5 5.1.2
A function in c++ exists only to act as a
parent or base of the derived classes.".
Justy the statement with proper example.
Answer:

 Pure virtual Functions are virtual functions


with no definition. They start with virtual
keyword and ends with = 0. Here is the syntax
for a pure virtual function.

 Pure Virtual functions can be given a small


definition in the Abstract class, which you
want all the derived classes to have. Still you
cannot create object of Abstract class.
 Also, the Pure Virtual function must be
defined outside the class definition. If you will
define it inside the class definition, complier
will give an error. Inline pure virtual definition
is Illegal.
 Abstract Class is a class which contains atleast
one Pure Virtual function in it. Abstract
classes are used to provide an Interface for its
sub classes. Classes inheriting an Abstract
Class must provide definition to the pure
virtual function, otherwise they will also
become abstract class.

Example:

class pet
{
private:
char name[5];
public:
virtual void getdata()=0;
virtual void display()=0;
};
class fish : public pet
{
private:
char environment[10];
char food[10];
public:
void getdata();
void display();
};
class dog: public pet
{
private:

char environment[10];
char food[10];
public:
void getdata();
void display();
};
void fish::getdata()
{
cout<<"Enter the Fish Environment required"<<endl;
cin>>environment;
cout<<"Enter the Fish food require"<<endl;
cin>>food;
}
void fish::display()
{
cout<<"Fish Environment="<<environment<<endl;
cout<<"Fish Food="<<food<<endl;
cout<<"------------------"<<endl;
}
void dog::getdata()
{
cout<<"Enter the Dog Environment
required"<<endl;
cin>>environment;
cout<<"Enter the Dog Food require"<<endl;
cin>>food;
}
void dog::display()
{
cout<<"Dog
Environment="<<environment<<endl;
cout<<"Dog Food="<<food<<endl;

cout<<"---------------------------------------"<<endl;
}
void main()
{
pet *ptr;
fish f;
ptr=&f;
ptr->getdata();
ptr->display();
dog d;
ptr=&d;
ptr->getdata();
ptr->display();
getch();

(ii) Explain Synchronous and Asynchronous


exceptions with examples.

i) Synchronous Exception
"Occur during the program execution due to
some fault in the input data or technique that is not
suitable to handle the current class of data, within the
program .

For example:
errors such as out of range
Overflow
underflow and so on"

ii)Asynchronous Exceptions

Caused by events or faults unrelated (external)


to the program and beyond the control of the program.

For example
errors such as keyboard interrupts
hardware malfunctions
disk failure and so on

The exception handling mechanism of C++ is


designed to handle only synchronous exceptions
within a program.
OR
21 Illustrate a C++ program to demonstrate the Class 10 2 3 5 5.1.1
B template concepts using default and multiple
parameters concepts.

#include <iostream>
using namespace std;

// Class template with multiple and default


parameters
template <class T, class U, class V = char>
class ClassTemplate {
private:
T var1;
U var2;
V var3;

public:
ClassTemplate(T v1, U v2, V v3) : var1(v1),
var2(v2), var3(v3) {} // constructor
void printVar() {
cout<< "var1 = " << var1 <<endl;
cout<< "var2 = " << var2 <<endl;
cout<< "var3 = " << var3 <<endl;
}
};

int main() {
// create object with int, double and char types
ClassTemplate<int, double> obj1(7, 7.7, 'c');
cout<< "obj1 values: " <<endl;
obj1.printVar();

// create object with int, double and bool types


ClassTemplate<double, char, bool> obj2(8.8, 'a',
false);
cout<< "\nobj2 values: " <<endl;
obj2.printVar();

return 0;
}
22 The online shopping system offers a function that will 10 2 4 5 5.1.2
A significantly assist both buyers and sellers when
doing online shopping. Draw a Swimlane Activity
Diagram for Online Shopping System to see the
activities between the customer and the shopping
system.
OR
22 For an Online Bike Service Booking system draw the 10 2 4 5 5.1.2
B statechart and the component diagrams.
PART – C (1*10=10 Marks)
SCENARIO BASED/HOTs
23 Indian Electoral Office wants to update the details of 10 3 3 5.1.2 5.1.2
A voters in their portal. Write a C++ program that
prompts the user to enter their age and then checks if
the age is a valid number between 18 and 100. If the
age is not within this range, an exception is thrown,
which is caught by the catch block, which prints an
error message. Define the custom exception
'NotValidAge' to implement the same.

#include <iostream>
#include<exception>
#include<string>
using namespace std;
class NotValidAge: public exception{
public:
virtual const char* what() const throw(){
return "User age required to have 18 age to
become Indian Voter";
}
};

int main() {

NotValidAgeageex;
try
{
int age;
string name;
cout<<"Enter the name of the Person:";
cin>>name;
cout<<"Enter the age of the Person :";
cin>>age;
if(age<18)
throw ageex;
else
cout<<name<<" is an Indian Voter. Welcome!";
}
catch(exception& e)
{
cout<<e.what();
}

return 0;
}

OR
23 Create a class named Shape with a function that prints 10 2 4 5 5.1.1
B "This is a shape". Create another class named Polygon
inheriting the Shape class with the same function that
prints "Polygon is a shape". Create two other classes
named Rectangle and Triangle having the same
function which prints "Rectangle is a polygon" and
"Triangle is a polygon" respectively. Again, make
another class named Square having the same function
which prints "Square is a rectangle".
Now, try calling the function by the object of each of
these classes.

#include <iostream>
using namespace std;
class Shape{
public:
Shape(){}
virtual void print(){
cout<<"\nThis is a shape.";
}
};
class Polygon: public Shape{
public:
Polygon(){}
void print(){
cout<<"\nPolygon is a shape.";
}
};
class Rectangle: public Polygon{
public:
Rectangle(){}
void print(){
cout<<"\nRectangle is a Polygon.";
}
};
class Triangle: public Polygon{
public:
Triangle(){}
void print(){
cout<<"\nTriangle is a Polygon.";
}
};
class Square: public Rectangle{
public:
Square(){}
void print(){
cout<<"\nSquare is a Rectangle.";
}
};
int main(){
Shape S;
Polygon P;
Rectangle R;
Triangle T;
Square Sq;
S.print();
P.print();
R.print();
T.print();
Sq.print();
return 0;
}

You might also like