2018 Winter Model Answer Paper
2018 Winter Model Answer Paper
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 1 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 2 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 3 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 4 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Any
four
types of
inherita
nce with
suitable
2) Multiple inheritance: A derived class is derived from more than one diagram
base classes. 1M each
Diagram:
Page 5 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
It constructs the values of data It does not construct the values Any
members of the class. for the data members of the class. four
relevant
It is invoked automatically when It is invoked implicitly by the points
the objects are created. compiler upon exit of a 1M each
program/block/function.
Constructors are classified in Destructors are not classified in
various types such as : any types.
Default constructor
Parameterized constructor
Copy constructor
Overloaded constructor
A class can have more than one A class can have at the most one
constructor. constructor.
Page 6 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Correct
Diagram
2M
Page 7 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
#include<iostream.h>
class Base
{
public:
virtual void show( ) Correct
{ Example
cout<<”\n show base”; 2M
}
};
class Derived : public Base
{
public:
void show( )
{
Page 8 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
In above example, both base and derived class contains same name
function as show. By creating a pointer of base class one can invoke
desired show function by storing address of respective object in pointer.
Effect in inheritance:
Relevant
explanat
Private members of base class are not inherited directly in any visibility ion of
mode. three
1) Private visibility mode modes
In this mode, protected and public members of base class become 1M each
private members of derived class.
Page 9 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
d) List any six characteristics of OOP. Also list any two OOP 4M
languages.
Ans. Characteristics of OOP:
1) Emphasis is on data rather than procedure. Any six
2) Programs are divided into objects. characte
3) Data structures are designed such that they characterize the objects. ristics
1/2
4) Functions that operate on the data of an object are tied together in M
the data structure. each
5) Data is hidden and cannot be accessed by external functions.
6) Objects may communicate with each other through functions.
7) New data and functions can be easily added whenever necessary.
8) It follows bottom-up approach in program design.
OOP Languages:
1) Simula
2) Smalltalk Any two
3) Objective C OOP
4) C++ languag
5) Ada es ½ M
6) Object Pascal each
7) Turbo Pascal
8) Eiffel
9) Java
e) Demonstrate the concept of friend function with example. 4M
Ans. Friend function:
The private members of a class cannot be accessed from outside the
class but in some situations two classes may need access of each other’s Explana
private data. So a common function can be declared which can be made tion 2M
friend of more than one class to access the private data of more than one
class. The common function is made friendly with all those classes
whose private data need to be shared in that function. This common
function is called as friend function. Friend function is not in the scope
Page 10 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 11 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 12 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
1. int *a = new int;
2. *a = 10;
or
3. int *a = new int(10);
Syntax:
delete pointer_variable;
Example:
Delete p;
b) Explain the concept of constructor with default arguments with 4M
example.
Ans. C++ allows defining a constructor with default arguments. Programmer
can declare a parameterized constructor in which a parameter Explana
(argument) can have default value. tion 2M
When a constructor with default argument is invoked it initializes data
members either with default value or with value passed with function
Page 13 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
class ABC Example
{ 2M
int a,b;
public:
ABC(int x,int y=2)
{
a=x;
b=y;
cout<<a<<b;
}
};
void main()
{
ABC p(10);// first call to constructor
}
In the above example, constructor ABC has two arguments. One of the
arguments has default value.
In first call, constructor executes and it initializes variable with value 10
and b with default value 2.
In second call, constructor executes and it initializes variable with value
10 and b with default value 20.
c) Explain constructor in derived class using one example. 4M
Ans. When a class is declared, a constructor can be declared inside
the class to initialize data members. When a base class contains a
constructor with one or more arguments then it is mandatory for the Explana
derived class to have a constructor and pass arguments to the base class tion 2M
constructor. When both the derived and base classes contain
constructors, the base constructor is executed first and then the
constructor in the derived class is executed.
Page 14 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
#include<iostream.h> Example
#include<conio.h> 2M
class base
{
int x;
public:
base(int a)
{
x=a;
cout<<"Constructor in base. x="<<x;
}
};
class derived: public base
{
int y;
public:
derived(int a,int b):base(a)
{
y=b;
cout<<"Constructor in derived.y="<<y;
}
};
int main()
{
clrscr();
Page 15 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 16 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
It's not possible to access the public members of the derived class D by
using cptr.Using base class pointer to object cptr, only those members
inherited from B can be accessed and not the members that originally
belong to D. For a member of D has the same name as any of the
member of B, then reference to that member by cptr will always access
the base class member. While C++ allows a base pointer to point to any
object derived from that base, the pointer cannot be directly used to
access all the members of the derived class.
Example:
#include<iostream.h>
#include<conio.h>
class base
{
int a;
Page 17 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 18 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 19 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans. #include<iostream.h>
class furniture
{ Class
protected: furnitur
char material[20]; e 1M
int price;
}; Class
class table :public furniture table 1M
{
int height ; accept
float sur_area; and
public: display
void getdata() data 2M
{
cout<<"enter material";
Page 20 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
void putdata()
{
cout<<" material is"<<material<<endl;
cout<<"price is"<<price<<endl;
cout<<" height is "<<height<<endl;
cout<<"surface area is "<<sur_area<<endl;
}
};
void main()
{
table t1;
t1.getdata();
t1.putdata();
}
b) Describe constructor with syntax and example. 4M
Note: Any constructor type shall be considered
Ans. A constructor is a special member function whose task is to initialize the
objects of its class. It is special because its name is same as the class Explana
name. The constructor is invoked whenever an object of its associated tion 2M
class is created. It is called constructor because it constructs the value
data members of the class.
Syntax:
class_name( ) Correct
{ syntax
Constructor body 1M
}
Example:
class ABC
{
Page 21 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
void main()
{
ABC x;
}
c) Explain insertion and extraction operators in C++ with example. 4M
Ans. Insertion operator:
The operator << is called as insertion operator works with cout to Explana
inserts the contents of the variable on screen (for output). tion with
Example: example
cout<<”Welcome to C++”; //Message is displayed on screen as it is. for
OR insertion
cout<<x;// Value of x will be printed on console / screen. 2M
Extraction operator:
The operator >>is called as extraction operator or get from extracts the
value from keyboard and assigns it to the variable on its right.
Extraction operator is used with cin statement to accept input from user For
(keyboard). Extracti
Example: on
cin>>number1; operator
2M
d) List characteristics of static data member and static member 4M
function.
Ans. Characteristics of static member variable are:
i) It is initialized to zero when the first object of its class is created. No
other initialization is permitted. Charact
ii) Only one copy of that member is created for the entire class and is eristics
shared by all the objects of that class, no matter how many objects are of static
created. data
iii) It is visible only within the class, but its lifetime is the entire member
program. 2M
Page 22 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
#include<iostream.h>
class A
{
protected:
int a; Example
}; 2M
class B:public virtual A
{
protected:
int b;
};
class C:public virtual A
{
protected:
int c;
};
class D:public B,public C
Page 23 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 24 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 25 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
Example
#include<iostream.h> 2M
#include<conio.h>
struct demo
{
int a;
};
void main()
{
demo d;
clrscr();
cout<<"\nEnter a value for demo's a";
cin>>d.a;
cout<<"\nThe Value is "<<d.a;
getch();
}
Page 26 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
2. Classes
A class is the collection of related data and function under a single
name. A class is collection of object of similar type. The entire set of
data and code of an object can be made a user-defined data type with
the help of class. Once a class has been defined, we can create any
number of objects belonging to that class. Classes are user-defined that
types and behave like the built-in types of a programming language.
Page 27 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
4. Inheritance
Inheritance is the process by which objects of one class acquired the
properties of objects of another classes. In OOP, the concept of
inheritance provides the idea of reusability. This means that we can add
additional features to an existing class without modifying it. This is
possible by deriving a new class from the existing one. The new class
will have the combined feature of both the classes.
5. Polymorphism
Polymorphism means the ability to take more than on form. An
operation may exhibit different behavior is different instances. For
example, consider the operation of addition. For two numbers, the
operation will generate a sum. If the operands are strings, then the
operation would produce a third string by concatenation.
6. Dynamic Binding
Binding refers to the linking of a procedure call to the code to be
executed in response to the call.
7. Message Passing
An object-oriented program consists of a set of objects that
communicate with each other. Objects communicate with one another
by sending and receiving information.
Page 28 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
#include<iostream.h>
#include<conio.h>
void main()
{ Example
int value; 2M
int*ptr;
ptr= &value;
cout<<”memory address before increment=”;
cout<<ptr<<endl; ptr++;
cout<<” memory address after increment=”;
cout<<ptr<<endl;
}
memory address before increment=0X24c8ff4
memory address after increment=0X24c8ff5
Page 29 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 30 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans. #include<iostream.h>
#include<conio.h>
class Master
{
char name[10],code[3];
public:
void acceptM() Each
{ Class 1
cout<<"\nEnter name and code "; ½M
cin>>name>>code;
}
void displayM()
{
cout<<"\nThe name and code is"<<name<<code;
} Main
}; function
class Account : public virtual Master 2M
Page 31 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 32 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans. #include<iostream.h>
#include<conio.h> Pointer
void main() creation
{ and
char str1[10],*ptr; acceptin
int len=0; g string
cout<<"enter string:"; 2M
cin>>str1;
ptr=&str1[0]; Pointer
while(*ptr!='\0') to initial
{ position
len++; 1M
ptr++;
} Calculat
cout<<"\nThe Length of a string is"<<len; ion of
getch(); Length
} 4M
Display
length
1M
Page 33 / 33