Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: object oriented Program
Description: answer set of object oriented Program
Description: answer set of object oriented Program
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
17432
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in the model
answer scheme
...
3) The language errors such as grammatical, spelling errors should not be given more Importance
(Not applicable for subject English and Communication Skills)
...
The figures drawn by candidate and model answer may vary
...
5) Credits may be given step wise for numerical problems
...
6) In case of some questions credit may be given by judgement on part of examiner of relevant
answer based on candidate‟s understanding
...
Q
...
1
...
N
...
Attempt any SIX of the following:
Which are the input-output operator in C++? Give suitable
example
...
Input operator: >> extraction or get from operator
Example: cin>> number;
2
...
List of
two
operator
s-1M
Example
of each
½M
2M
Give significance of ‘&’ and ‘*’ operators
...
With address operator address Signific
of a variable can be stored in pointer variable
...
Also used as „value at‟ operator
to read value stored inside the address pointed by pointer
...
(d)
Ans
...
(f)
Ans
...
Calculate the size of object B1 defined in following class:
Class Book
{
char B_name [15];
int B_id;
int price;
};
Book B1;
19 bytes
List any four types of constructor
...
Polymorphism- It is the ability to take more than one form
...
Any
four
types
½M
each
2M
Definitio
n 1M
Two
Types –
types
1) Compile time polymorphism
½M
2) Run time polymorphism
each
Define derived class
...
2M
Derived class:- a new class derived from an old class is called as Definitio
derived class
...
Write syntax to create a pointer for object
...
1
...
17432
Write syntax for overloaded constructor
...
syntax:class class_name
{
public:
class_name() //constructor name is same as class name
{
}
class_name(argument)//constructor name is same as class name
{
}
};
Attempt any TWO of the following:
What do you mean by default argument? Illustrate concept of
constructor with default argument using suitable example
...
When a constructor with default value is declared in a class, it does not
require object to pass value for default argument
...
If
object contains value for default argument, then passed value overwrites
the default value
...
In above example, obj1 passes one argument to constructor function so
x will have value as 5 and y will have value as default value 10
...
In obj2, default value is overwritten with
passed value
...
Multiple Inheritance: When a single class is derived from more than
one base classes, it is referred as multiple inheritance
...
class Test
{
};
class Sports
{
};
class Result:publicTest,public Sports
{
Page 4 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(c)
Ans
...
(a)
Ans
...
Destructor name is same as class name but is preceded by a tilde
...
Destructor is declared in public area of a class
...
Destructor never takes any argument
...
Destructor never returns any value
...
Access specifiers :
1
...
protected
3
...
Outside class access is not allowed
for private members of class
...
4M
Any
four
rules
1M each
16
4M
Three
access
specifier
s 1M
each
Protected access specifier: Class members declared as protected can be
accessed by the member functions within its class and any class
immediately derived from it
...
Public access specifier: Class members declared as public can be
accessed from outside the class also
...
display();
d
...
In the above example, variable „a‟ can be access by its member function
„display ()‟ as it is a private variable
...
Member function „display ()‟
and „show ()‟ can be accessed from main () as they are public members
of class
...
n 1M
When base class and its derived class both contain same name and
prototype member function then derived class function overrides base Explana
class function
...
When base pointer is used to refer
to functions, it ignores the contents of the pointer and selects the
member function that matches the function call
...
To execute derived class version of the overridden function
virtual keyword is used with base class function
...
If
the pointer points to base class then function from base class gets
Page 6 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
17432
executed
...
Run time polymorphism requires virtual function to execute same name
function from base class and derived class depending on address stored
inside the pointer
...
Program/Example:
#include
(Note: Any program showing multilevel inheritance shall be
considered)
...
h>
4M
Page 7 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
#include
(e)
Ans
...
getstudent();
r
...
display();
getch();
}
Differentiate between POP and OOP
...
PROCEDURE
OBJECT ORIENTED
No
...
procedure
...
multiple objects
...
functions
...
by calling each other
...
program design
6
Procedure oriented
Object oriented approach is
approach is used in C
used in
language
...
What is static member function? How is it declare?
4M
A member function that can access to only other static members
declared in the same class is known as static member function
...
Page 9 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
17432
class_name::function_name;
Syntax for declaration:
static return_typefunction_name()
{
functiona body
}
(f)
Ans
...
Accept and display data for five object using
pointer to array of object
...
h>
#include
(a)
Ans
...
General C++ program has following structure
...
Include header files
In this section a programmer include all header files which are require
to execute given program
...
h header
file
...
Without this file one cannot load C++ program
...
Declare Class
In this section a programmer declares all classes which are necessary for
given program
...
3
...
The programmer can have inside declaration of a function or outside
declaration of a function
...
Define Main Functions
This section the programmer creates object and call various functions
writer within various class
...
h
...
h>
Descript
ion 2M
Page 11 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(b)
Ans
...
accept( );
d
...
Give suitable example
...
This is known as constructor overloading
...
All the
constructors contain different number of arguments
...
2M
Multiple constructor can be declared in different ways:
integer();
// No arguments
integer(int, int);
// Two arguments
When the object is created the first constructor invoked
...
In the second case, the function call passes the appropriate values from
main ( )
...
For example, we could define a class as follows:
Program:
#include
h>
class integer
{
int m, n;
public:
integer()
{
m = 0;
n = 0;
}
// constructor 1
integer(int a, int b)
{
m = a;
n = b;
cout<<"value of m="<cout<<"value of n="<}
// constructor 2
};
void main()
{
clrscr();
integer i1;
integer i2(20,40);
getch();
}
Example
2M
This declared three constructors for an integer object
...
For
example, the declaration
...
The statement
integer i2 (20, 40);
Page 13 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(c)
Ans
...
So the process of sharing the same
name by two or more functions is referred to as function overloading
...
An abstract class is designed to act as base class
...
An abstract class is used to define an implementation and is intended to
be inherited from by concrete classes
...
#include
";
cin>>emp_no;
}
void display()
{
cout<<"\n Employee no
...
getdata();
f
...
In the above example, class employee is an abstract class since its object
is not created in main()
...
Write a program using function overloading to swap two integer
number and swap two float number
...
h>
#include
}
What is ‘this’ pointer? Give suitable example
...
C++ uses a unique keyword called „this‟ to represent an object that
invokes a member function
...
This unique pointer is automatically passed to a member function
when it is invoked
...
„this‟ is a pointer that always point to the object for which the
member function was called
...
For example, the function call
A
...
Next time suppose we call B
...
Consider the following example:
#include
setdata(100);
s
...
}
In the above example, this pointer is used to represent object s when
setdata() and putdata() functions are called
...
The memory space for object is allocated when they are declared & not
when the class is specified
...
Since all the objects belonging to that class use the
same member functions, no separate space is allocated for member
functions
...
Separate memory locations for
the objects are essential because the member variables will hold
different data values for different objects this is shown in fig:
4M
Explana
tion 2M
Example
2M
Page 17 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
4
...
17432
Attempt any FOUR of the flowing:
Write a program to implement single inheritance
...
Declare derived
class ‘Fitness’ with height and weight
...
#include
h>
class employee
{
protected:
int emp_no;
char emp_name[25];
void getdata()
{
cout<<"\n Enter employee no
...
is :"<
};
class fitness:public employee
{
protected:
float height,weight;
public:
void getdata()
{
employee::getdata();
cout<<"\n Enter height:";
cin>>height;
cout<<"\n Enter weight:";
cin>>weight;
}
void display()
16
4M
Correct
logic
2M
Correct
syntax
2M
Page 18 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
17432
{
employee::display();
cout<<"\n height is :"<
(b)
Ans
...
getdata();
f
...
The copy constructor is a constructor which creates an object by
initializing it with an object of the same class, which has been created
previously
...
Copy an object to pass it as an argument to a function
...
If a copy constructor is not defined in a class, the compiler itself defines
one
...
Syntax:
constructor_name(class_name(data type) &object_name)
{
body of copy construtor
}
Example:
#include
1M
y = y1;
}
// copy constructor
point(point &p2)
{
x = p2
...
y;
}
intgetX()
{
return x;
}
intgetY()
{
return y;
}
};
int main()
{
point p1(10, 15); // Normal constructor is called here
point p2 = p1; // Copy constructor is called here
// Let us access values assigned by constructors
cout<< "p1
...
getX() << ", p1
...
getY();
cout<< "\np2
...
getX() << ", p2
...
getY();
return 0;
}
Explain scope resolution operator and memory management
operator in C++
...
C++ resolves this problem by introducing a new operator::
called scope resolution operator
...
It takes the following form:
:: variable;
This operator allows access to the global version of a variable
...
New operator:
The new operator in C++ is used for dynamic storage allocation
...
(d)
Ans
...
Once a new operator is used, it is
efficient to use the corresponding delete operator for release of memory
...
Friend functions Private and protected members of a class cannot be
accessed from outside the same class in which they are declared
...
A function that is not a
member of a class but has access to the class‟s private and protected
members
...
Friend function is declared by the class that is
granting access
...
It is not affected by the access control keywords
(public, private and protected)
...
h>
#include
};
class xyz
{
int a;
public:
void get1()
{
cin>>a;
}
friend void add(abc,xyz);
};
void add(abc a1,xyz x1)
{
cout<
a;
}
void main()
{
abc a1;
xyz x1;
a1
...
get1();
add(a1,x1);
}
Write a program to implement inheritance as shown in fig 1
...
#include
h>
class staff
{
int code;
public:
17432
4M
Correct
Page 22 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
void accept()
{
cout<<"enter code of staff:"<
}
void dis()
{
cout<<"code="<
}17432
logic
2M
Correct
syntax
2M
};
class teacher : public staff
{
protected:
char subject[10];
public:
void acc1()
{
cout<<"enter subject:"<
}
void dis1()
{
cout<<"subject="<
};
class officer :public staff
{
protected:
char grade[5];
public:
void acc2()
{
cout<<"Enter Grade:"<
}
void dis2()
{
cout<<"grade="<
Page 23 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(f)
Ans
...
accept();
t
...
acc1();
t
...
accept();
o
...
acc2();
o
...
#include
h>
void main()
{
int a[5],a2[6],i,*a1,no,loc;
clrscr();
a1=&a[0];
cout<<"\n\t Enter array elements:\n";
for(i=0;i<5;i++)
{
cout<<"\n\t Enter "<cin>>*a1;
a1++;
}
cout<<"\n\t\t Enter element to be inserted at what location::";
cin>>no>>loc;
a1=&a[0];
for(i=0;i
a2[i]=*a1;
cout<<" a2["<a1++;
17432
4M
Correct
logic
2M
Correct
syntax
2M
Page 24 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
17432
}
a2[loc]=no;
a1=&a[loc];
for(i=loc+1;i<=5;i++)
{
a2[i]=*a1;
a1++;
}
a1=&a2[0];
cout<<"\n\t\t New Array is:\n";
for(i=0;i<6;i++)
{
cout<<"\n\t\t Element "<a1++;
}
getch();
}
5
...
Attempt any FOUR of the following:
State any four rules for operator overloading
...
Only existing operators can be overloaded
...
2
...
3
...
That is to say, we
can’t redefine the plus(+) operator to subtract one value from other
...
Overloaded operators follow the syntax rules of the original
operators
...
5
...
6
...
However,
member function scan be used to overload them
...
Unary operators overloaded by means of member function take no
explicit arguments and return no explicit values, but, those
overloaded by means of the friend function, take one reference
argument (the object of the relevant class)
...
Binary operators overloaded through a member function, take one
explicit argument and those which are overloaded through a friend
function take two explicit arguments
...
17432
9
...
10
...
They must not attempt to change their own arguments
...
Definition:Structure is a collection of different data types written under a common
name
...
Syntax:
struct structure_name
{
data_type variable 1;
data_typevariable 2;
...
...
...
17432
}
Create class shape
...
Accept dimensions of Triangle and Rectangle with appropriate
functions
...
With area function calculate area of triangle and rectangle
...
#include
h>
class shape
{
public:
int l, b, h;
virtual void area()=0;
};
class triangle:public shape
{
public:
void getdata()
{
cout<<”\n enter dimensions of triangle:\n length:”;
cin>>l;
cout<<”\n height:”;
cin>>h;
}
void area()
{
int a=0
...
(e)
Ans
...
getdata();
p->area();
p=&r;
r
...
More emphasis is given in doing things
...
Large program are divided into small modules class functions
...
Most of functions show global data
...
Does not support Abstraction, Inheritance, Encapsulation and
polymorphism
...
Employs top –down approach
6
...
7
...
#include
h>
#include
(4 points)
Correct
logic 2M
Correct
syntax
2M
4M
Ans
...
No
...
Functions to be called are
known well before
...
Any
four
relevant
points
1M each
Function to be called is
unknown until appropriate
selection is made
...
Page 29 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
6
...
17432
Attempt any TWO of the following:
Write a program declare a class student consisting of data member
stud_name and Roll_no
...
#include
h>
class student
{
private:
char stud_name[10];
int roll_no;
public:
void accept()
{
cout<<”enter student Details”:
cout<
cin>>roll_no;
}
void display()
{
cout<<”student name::”<
};
void main()
{
student s[4];
int i;
for(i=0;i<=3;i++)
{
s[i]
...
display();
}
getch();
16
8M
Class
declarati
on and
definitio
n 4M
Main
function
with
loop 4M
Page 30 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(b)
Ans
...
2
Assume suitable member function
...
h>
#include
get_stud();
r
...
get_marks();
r, disp_marks();
r
...
disp_score();
Page 32 / 33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER - 2017 EXAMINATION
Subject: Object Oriented Programming
Subject Code:
(c)
Ans
...
display();
getch();
}
Write a program to display string in reverse order by using pointer
...
h>
#include
h>
void main()
{
char str1[10],*ptr;
int l=0;
cout<<"enter string:";
cin>>str1;
ptr=&str1[0];
while(*ptr!='\0')
{
l++;
ptr++;
}
while(l>0)
{
ptr--;
cout<<*ptr;
l--;
}
getch();
}
4M
Correct
logic 4M
Correct
syntax
4M
Page 33 / 33
Title: object oriented Program
Description: answer set of object oriented Program
Description: answer set of object oriented Program