W 2018 A - (Truexams - Com) - 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

www.truexams.

com

22316
11819
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Use of Non-programmable Electronic Pocket
Calculator is permissible.
(7) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) State any four object oriented languages.
b) Describe use of protected access specifier used in the class.
c) Differentiate between OOP and POP.
d) Write any two characteristics of destructor.
e) Describe meaning of following:
(i) ios : : in
(ii) ios : : out

P.T.O.
www.truexams.com

22316 [2]
Marks
f) Give output for following code:
class student
{
int roll no;
char name [14];
} s[6];
void main( )
{
cout <<sizeof(s);
}
g) Write syntax to define a derived class.

2. Attempt any THREE of the following: 12


a) Write a C++ program to accept array of five elements, find
and display smallest number from an array.
b) Write a C++ program to declare a class ‘College’ with data
members as name and college code. Derive a new class
‘student’ from the class college with data members as sname
and roll no. Accept and display details of one student with
college data.
c) Write a C++ program to declare a class ‘circle’ with data
members as radius and area. Declare a function getdata to
accept radius and putdata to calculate and display area of circle.
d) With suitable example, describe effect of ++ and – – operators
used with pointer in pointer arithmetic.

3. Attempt any THREE of the following: 12


a) Write a C++ program to declare a class addition with data
members as x and y. Initialize value of x and y with
constructor. Calculate addition and display it using function
‘display.’
b) With suitable diagram describe structure of C++ program.
c) Describe the concept of virtual base class with suitable example.
d) Describe use of static data member in C++ with example.
www.truexams.com

22316 [3]
Marks
4. Attempt any THREE of the following: 12
a) Write a C++ program to implement inheritance shown in
following figure:
Class : Teacher Class : Student
datamember : Name datamember : sname
empid rollno.

Class : Info

Accept and display data of one teacher and one student using
object of class ‘Info’.
b) Write a C++ program to print multiplication table of 7.
(example: 7 × 1 = 7 ..... 7 × 10 = 70)
c) Write a C++ program to swap two integer numbers and swap
two float numbers using function overloading.
(Hint : overload swap function)
d) Write a C++ program to count number of spaces present in
contents of file.
e) Write a C++ program to find greatest number among two
numbers from two different classes using friend function.

5. Attempt any TWO of the following: 12


a) Write a C++ program to overload binary operator ‘+’ to
concatenate two strings.
b) Write a C++ program to write ‘Welcome to poly’ in a file.
Then read the data from file and display it on screen.
c) Write a C++ program to declare a class ‘Account’ with data
members as accno, name and bal. Accept data for eight
accounts and display details of accounts having balance
less than 10,000.

P.T.O.
www.truexams.com

22316 [4]
Marks
6. a) Attempt any TWO of the following: 12
(i) Write a C++ program to find whether the entered number
is even or odd.
(ii) Write a C++ program to declare a structure employee
with members as empid and empname. Accept and
display data for one employee using structure variable.
b) Write a C++ program to implement following inheritance.

Class : Employee
Data : empid
Member : empcode

Class : Programmer Class : Manager


Datamember : Skill Datamember : department

Accept and display data for one programmer and one manager.
Make display function virtual.
c) Write C++ program for following multilevel inheritance.
Class : Carmanufacturer
datamember : Name

Class : Carmodel
datamember : Model name,
Model no.

Class : Car
datamember : Car no., colour

Accept and display data for one car with all details.
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
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.
2) The model answer and the answer written by candidate may vary but the examiner may try to
assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance
(Not applicable for subject English and Communication Skills).
4) While assessing figures, examiner may give credit for principal components indicated in the
figure. The figures drawn by candidate and model answer may vary. The examiner may give
credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant
values may vary and there may be some difference in the candidate’s answers and model
answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant
answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
a) State any four object oriented languages. 2M
Ans. Object oriented programming language:
 C++
 Smalltalk Any 4
 Object pascal languag
 java es ½ M
 Simula each
 Ada
 Turbo pascal
 Eiffel
 C#
 Python
b) Describe use of protected access specifier used in the class. 2M
Ans. Protected access specifier is use to declare a class member that is Correct
accessible by the member functions within its class and any class use 2M
immediately derived from it.

Page 1 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

c) Differentiate between OOP and POP 2M


Ans
Sr. PROCEDURE OBJECT ORIENTED
No. ORIENTED PROGRAMMING
PROGRAMMING (POP) (OOP)
1 Focus is on doing things Focus is on data rather than Any two
(procedure). procedure. relevant
2 Large programs are divided Programs are divided into differen
into multiple functions. multiple objects. ces
3 Data move openly around Data is hidden and cannot 1M each
the system from function to be accessed by external
function. functions.
4 Functions transform data Objects communicate with
from one form to another each other through function.
by calling each other.
5 Employs top-down Employs bottom-up
approach in program approach in
design. program design
6 Procedure oriented Object oriented approach is
approach is used in C used in
language. C++ language.
d) Write any two characteristics of destructor. 2M
Ans. Characteristics:
1. It is used to destroy objects created by a constructor.
2. Name of destructor and name of the class is same. Any two
3. Its name is preceded with tilde (~) symbol. characte
4. It never takes any argument. ristics-
5. It does not return any value. 1M each
6. It is invoked implicitly by the compiler upon exit from the
program (or block or function) i.e when scope of object is over.
e) Describe meaning of the following 2M
(i) ios : : in
(ii) ios : : out Meanin
Ans. (i) ios : : in : It is a file mode. It is used to open a file in read only g of ‘in’
mode. 1M
Meanin
(ii) ios : : out : It is a file mode. It is used to open a file in write only g of
mode. ‘out’
1M

Page 2 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

f) Give output for following code: 2M


class student
{
int roll no;
char name [14];
} s[6];
void main()
{
cout<<sizeof(s);
}
Ans Considering roll_no(Single variable) the output is: 96 Correct
OR output
Considering roll, no (Two variables) the output is: 108 2M
OR
Considering roll no the output is: error – space between roll and no
g) Write syntax to define a derived class 2M
Ans Syntax:
class derived_class_name : visibility_mode/access_specifier Correct
base_class_name syntax
{ 2M
class body
};

2 Attempt any THREE of the following 12


a) Write a C++ program to accept array of five elements, find and 4M
display smallest number from an array.
Ans #include<iostream.h> Correct
#include<conio.h> logic
void main() 2M
{
int a[5],smallest,i;
clrscr(); Correct
cout<<" Enter array elements:"; syntax
for(i=0;i<5;i++) 2M
cin>>a[i];
smallest=a[0];
for(i=1;i<5;i++)
{
if(a[i]<smallest)

Page 3 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
{
smallest=a[i];
}
}
cout<<endl<<"Smallest number="<<smallest;
getch();
}
b) Write a C++ program to declare a class ‘College’ with data 4M
members as name and college code. Derive a new class ‘student’
from the class college with data members as sname and roll no.
Accept and display details of one student with college data.
Ans #include<iostream.h> Declarat
#include<conio.h> ion and
class college Definitio
{ n of
char name[10]; Base
int collegecode; Class
public: 1M
void getcollege()
{ Declarat
cout<<"Enter college name:"; ion and
cin>>name; Definitio
cout<<"Enter college code:"; n of
cin>>collegecode; Derived
} Class
void putcollege() 2M
{
cout<<endl<<"College name="<<name; Main
cout<<endl<<"College code="<<collegecode; function
} 1M
};
class student:public college
{
char sname[10];
int rollno;
public:
void getstudent()
{
cout<<"Enter student name";

Page 4 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
cin>>sname;
cout<<"Enter roll no:";
cin>>rollno;
}
void putstudent()
{
cout<<endl<<"Student name:="<<sname;
cout<<endl<<"Roll no:="<<rollno;
}
};
void main()
{
student s;
clrscr();
s.getcollege();
s.getstudent();
s.putcollege();
s.putstudent();
getch();
}

c) Write a C++ program to declare a class ‘circle’ with data 4M


members as radius and area. Declare a function getdata to accept
radius and putdata to calculate and display area of circle.
Ans #include<iostream.h>
#include<conio.h> Decalar
class circle ation
{ and
float radius,area; Definitio
public: n of
void getdata() class
{ with
cout<<"Enter radius:"; function
cin>>radius; s
} 3M
void putdata()
{
area=3.14*radius*radius;
cout<<"Area of circle="<<area;

Page 5 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
}
};
void main()
{ Main
circle c; function
clrscr(); 1M
c.getdata();
c.putdata();
getch();
}

d) With suitable example, describe effect of ++ and - - operators 4M


used with pointer in pointer arithmetic.
Ans. ++ Operator: - It is referred as increment operator that increments the
value of variable. If ++ operator is used with pointer variable, then Descript
pointer variable points to next memory address that means pointer ion of
increment with respect to size of the data type used to declare pointer ++
variable. operator
1M
Example:-
int a[5]={10,20,30,40,50},*ptr;
ptr=a[0]; Any
for(i=0;i<5;i++) relevant
{ Example
cout<<*ptr; 1M
ptr++;
}
In the above example, ptr points to memory location of a[0].
Increment statement ptr++ increments ptr by memory size of int i.e 2
bytes and ptr points to a[1].

- - Operator: - It is referred as decrement operator that decrements Descript


the value of variable. If - - operator is used with pointer variable, then ion of - -
pointer variable points to previous memory address that means operator
pointer decrement with respect to size of the data type used to declare 1M
pointer variable.

Page 6 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

Example:- Example
int a[5]={10,20,30,40,50},*ptr; 1M
ptr=a[4];
for(i=0;i<5;i++)
{
cout<<*ptr;
ptr- -;
}

In the above example, ptr points to memory location of a[4].


Decrement statement ptr- - decrements ptr by memory size of int i.e 2
bytes and ptr points to a[3].

3 Attempt any THREE of the following 12


a) Write a C++ program to declare a class addition with data 4M
members as x and y. Initialize values of x and y with constructor.
Calculate addition and display it using function ‘display’.
Ans. #include<iostream.h>
#include<conio.h>
class addition
{ Declarat
int x,y; ion and
public: definitio
addition(int,int); n of
void display(); class
}; with
addition::addition (int x1,int y1) construc
{ tor and
x=x1; display
y=y1; function
} 3M
void addition::display()
{
cout<<"\nAddition of two numbers is:"<<(x+y);
} Main
void main() function
{ 1M
addition a(3,4);

Page 7 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
a.display();
getch();
}

b) With suitable diagram describe structure of C++ program. 4M


Ans General C++ program has following structure.

INCLUDE HEADER FILES Correct


diagram
CLASS DECLARATION 2M
MEMBER FUNCTIONS DEFINITIONS
MAIN FUNCTION PROGRAM

Description:-
1. Include header files
In this section a programmer include all header files which are
require to execute given program. The most important file is
iostream.h header file. This file defines most of the C++statements Descript
like cout and cin. Without this file one cannot load C++ program. ion 2M
2. Class Declaration
In this section a programmer declares all classes which are necessary
for given program. The programmer uses general syntax of creating
class.
3. Member Functions Definition
This section allows programmer to design member functions of a
class. The programmer can have inside declaration of a function or
outside declaration of a function.
4. Main Function Program
In this section programmer creates objects and calls various functions
writer within various class.

c) Describe the concept of virtual base class with suitable example. 4M


Note: Program/diagram with syntax shall be considered as an
example.
Ans. Virtual Base Class:
An ancestor class is declared as virtual base class which is used to Descript
avoid duplication of inherited members inside child class due to ion
multiple path of inheritance. 2M

Page 8 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

Consider a hybrid inheritance as shown in the above diagram. The


child class has two direct base classes, Parent1 and Parent2 which
themselves have a common base class as Grandparent. The child
inherits the members of Grandparent via two separate paths. All the
public and protected members of Grandparent are inherited into Child
twice, first via Parent1 and again via Parent2. This leads to duplicate
sets of the inherited members of Grandparent inside Child class. The
duplication of inherited members can be avoided by making the
common base class as virtual base class while declaring the direct or
intermediate base classes as shown below.
class Grandparent
{
};
class Parent1:virtual public Grandparent
{ Example
}; 2M
class Parent2:virtual public Grandparent
{
};
class Child: public Parent1,public Parent2
{
};

Example
#include<iostream.h>
#include<conio.h>
class student
{
int rno;

Page 9 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
public:
void getnumber()
{
cout<<"Enter Roll No:";
cin>>rno;
}
void putnumber()
{
cout<<"\n\n\t Roll No:"<<rno<<"\n";
}
};
class test: virtual public student
{
public:
int part1,part2;
void getmarks()
{
cout<<"Enter Marks\n";
cout<<"Part1:";
cin>>part1; cout<<"Part2:";
cin>>part2;
}
void putmarks()
{
cout<<"\t Marks Obtained\n";
cout<<"\n\t Part1:"<<part1;
cout<<"\n\tPart2:"<<part2;
}
};
class sports: public virtual student
{
public:
int score;
void getscore()
{
cout<<"Enter Sports Score:";
cin>>score;
}
void putscore()

Page 10 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
{
cout<<"\n\t Sports Score is:"<<score;
}
};
class result: public test, public sports
{
int total;
public:
void display()
{
total=part1+part2+score;
putnumber();
putmarks();
putscore();
cout<<"\n\t Total Score:"<<total;
}
};
void main()
{
result obj;
clrscr();
obj.getnumber();
obj.getmarks();
obj.getscore();
obj.display();
getch();
}
d) Describe use of static data member in C++ with example. 4M
Ans Use of static data member:
1. Static data member is used to maintain values common to the entire Use of
class. static
2. It is initialized to zero when the first object of its class is created. data
3. Only one copy of that member is created for the entire class and is member
shared by all the objects of that class. 2M

Example:
#include<iostream.h> Relevant
#include<conio.h> example
class test 2M
{

Page 11 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
static int count;
int obj_no;
public:
void getdata()
{
obj_no=++count;
cout<<"\n Object number="<<obj_no;
}
static void showcount()
{
cout<<"\n total number of objects="<<count;
}
};
int test::count;
void main()
{
test t1,t2;
clrscr();
t1.getdata();
t2.getdata();
test::showcount();
test t3;
t3.getdata();
test::showcount();
getch();
}

4 Attempt any THREE of the following 12


a) Write a C++ program to implement inheritance shown in 4M
following figure:

Accept and display data of one teacher and one student using
object of class ‘Info’
Note: Any other correct logic of multiple inheritance in program
shall be considered.

Page 12 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

#include<iostream.h>
Ans #include<conio.h> Correct
class Teacher definitio
{ n of
protected: class -
char Name[20]; Teacher
int empid; 1M
};
class Student Correct
{ definitio
protected: n of
char sname[20]; class-
int rollno; Student
}; 1M
class Info:public Teacher,public Student
{ Correct
public: definitio
void acceptT() n of
{ class-
cout<<"\nEnter data for teacher:"; Info
cout<<"\nName:"; 1M
cin>>Name;
cout<<"\nEmployee id:";
cin>>empid;
}

void displayT()
{
cout<<"\nTeacher's data is:";
cout<<"\nName:"<<Name;
cout<<"\nEmployee id:"<<empid;
}
void acceptS()
{
cout<<"\nEnter student's data:";
cout<<"\nName:";
cin>>sname;

Page 13 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
cout<<"\nRoll no:";
cin>>rollno;
}
void displayS()
{
cout<<"\nStudent's data is:";
cout<<"\nName:"<<sname;
cout<<"\nRoll no:"<<rollno;
}
}; Correct
void main() definitio
{ n of
Info I; main
clrscr(); function
I.acceptT(); 1M
I.displayT();
I.acceptS();
I.displayS();
getch();
}

b) Write a C++ program to print multiplication table of 7. 4M


(example: 7 x 1 ….7 x 10 = 70)
Ans #include<iostream.h> Correct
#include<conio.h> logic
void main() 2M
{
int num;
clrscr();
cout<<"Multiplication table for 7 is:"<<endl; Correct
for(num=1;num<=10;num++) syntax
{ 2M
cout<<"7 *"<<num<<"="<<7*num<<endl;
}
getch();
}

c) Write a C++ program to swap two integer numbers and swap two 4M
float numbers using function overloading.

Page 14 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316

(Hint: overload swap function)


Note: Any other relevant logic shall be considered.

Ans #include<iostream.h> Correct


#include<conio.h> logic
void swap(int a,int b) 2M
{
int temp; Correct
temp=a; syntax
a=b; 2M
b=temp;
cout<<"\nInteger values after swapping are:"<<a<<" "<<b;
}
void swap(float x,float y)
{
float temp1=x;
x=y;
y=temp1;
cout<<"\nFloat values after swapping are:"<<x<<" "<<y;
}
void main()
{
clrscr();
swap(10,20);
swap(10.15f,20.25f);
getch();
}

d) Write a C++ program to count number of spaces present in 4M


contents of file.
Note: Any other relevant logic shall be considered
Ans #include<iostream.h> Correct
#include<fstream.h> logic
#include<conio.h> 2M
void main()
{
ifstream file;
charch; Correct

Page 15 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
int s=0; syntax
clrscr(); 2M
file.open("abc.txt");
while(file)
{
file.get(ch);
if(ch==' ')
{
s++;
}
}
cout<<"\nNumber of spaces present in the content of the given file
are:"<<s;
getch();
}

e) Write a C++ program to find greatest number among two 4M


numbers from two different classes using friend function.
Ans. #include<iostream.h>
#include<conio.h>
class second;
class first
{
int x;
public: Correct
void getx() definitio
{ n of
cout<<"\nEnter the value of x:"; class
cin>>x; first
} 1M
friend void max(first,second);
};
class second
{
int y; Correct
public: definitio
void gety() n of
{ class
cout<<"\nEnter the value of y:"; second

Page 16 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
cin>>y; 1M
}
friend void max(first,second);
};
void max(first a,second b) Correct
{ definitio
if(a.x>b.y) n of
{ friend
cout<<"\Greater value is:"<<a.x; function
} 1M ,
else
{
cout<<"\nGreater value is:"<<b.y;
}
}
void main() Correct
{ definitio
first a; n of
second b; main
clrscr(); function
a.getx(); 1M
b.gety();
max(a,b);
getch();
}

5 Attempt any TWO of the following 12


a) Write a C++ program to overload binary operator ‘+’ to 6M
concatenate two strings.

Ans #include<iostream.h>
#include<conio.h> Creating
#include<string.h> Class
class opov 2M
{
char str1[10];
public: Operato
void getdata() r
{ Functio

Page 17 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
cout<<"\nEnter a strings"; n
cin>>str1; 2M
}
void operator +(opov o)
{
cout<<strcat(str1,o.str1);
}
};
void main() Main
{ Functio
opov o1,o2; n
clrscr(); 2M
o1.getdata();
o2.getdata();
o1+o2;
getch();
}

b) Write a C++ program to write ‘Welcome to poly’ in a file. Then 6M


read the data from file and display it on screen.
Note: Any other relevant logic shall be considered
Ans #include<iostream.h>
#include<conio.h> Writing
#include<fstream.h> data in
void main() file
{ 3M
char str[25] = "Welcome to poly",ch;
clrscr(); Reading
ofstream fout; data
fout.open("output.txt"); from file
fout<<str; and
fout.close(); display
ifstream fin; on
fin.open("output.txt"); screen
while (!fin.eof()) 3M
{
fin.getline(str, 25);
cout<<str<<endl;
}

Page 18 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
fin.close();
getch();
}
c) Write a C++ program to declare a class ‘Account’ with data 6M
members as accno, name and bal. Accept data for eight accounts
and display details of accounts having balance less than 10,000.
Ans #include<iostream.h>
#include<conio.h> Creating
class Account Class
{ 2M
long int accno, bal;
char name[10]; Logic to
public: Display
void getdata() object
{ with
cout<<"\nEnter account number, balance and name "; given
cin>>accno>>bal>>name; conditio
} n
void putdata() 1M
{
if(bal>10000) Creating
{ 8 objects
cout<<"\nThe Account Number is "<<accno; 1M
cout<<"\nThe Balance is "<<bal;
cout<<"\nThe Name is "<<name;
} Calling
} function
}; s
void main() 2M
{
Account a[8];
int i;
clrscr();
for(i=0;i<8;i++)
{
a[i].getdata();
}
for(i=0;i<8;i++)
{

Page 19 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
a[i].putdata();
}
getch();
}
6 Attempt any TWO of the following 12
a) (i) Write a C++ program to find whether the entered number is 6M
even or odd.
(ii) Write a C++ program to declare a structure employee with
members as empid and empname. Accept and display data for
one employee using structure variable.

Ans (i) Write a C++ program to find whether the entered number is
even or odd.
Acceptin
#include<iostream.h> g
#include<conio.h> Number
void main() 1M
{
int num; Conditio
clrscr(); n to
cout<<"\nEnter a Number "; check
cin>>num; number
if(num%2==0) 1M
{
cout<<"\nEntered number is even"; Display
} result
else 1M
{
cout<<"\nEntered number is odd";
}
getch();
}

(ii) Write a C++ program to declare a structure employee with


members as empid and empname. Accept and display data for
one employee using structure variable.

#include<iostream.h> Creating
#include<conio.h> structur

Page 20 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
struct employee e with
{ specified
int empid; member
char empname[10]; 1M
};
void main()
{ Acceptin
employee e; g and
clrscr(); displayi
cout<<"\nEnter employee id and Employee Name "; ng
cin>>e.empid>>e.empname; values
cout<<"\mThe Employee Id is "<<e.empid; 2M
cout<<"\nThe Employee Name is "<<e.empname;
getch();
}
b) Write a C++ program to implement following inheritance. 6M

Accept and display data for one programmer and one manager.
Make display function virtual.

Ans. #include<iostream.h>
#include<conio.h>
class Employee
{
int empid,empcode;
public: Creating
void emp() all
{ classes
cout<<"\nEnter an employee id "; 3M
cin>>empid;
cout<<"\nEnter an employee code ";
cin>>empcode;

Page 21 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
}
void virtual display()
{
cout<<"\nEmployee id "<<empid;
cout<<"\nEmployee code"<<empcode;
}
};
class Programmer : public Employee
{
char Skill[10];
public:
void getskill()
{
cout<<"\nEnter a Skill for Programmer ";
cin>>Skill;
}
void display()
{
cout<<"\nThe Programmer Skill is "<<Skill;
}
};
class Manager : public Employee
{
char department[10];
public:
void getdept()
{
cout<<"\nEnter a Department for Manager ";
cin>>department;
}
void display()
{
cout<<"\nThe Department of Manager is "<<department;
}
};
void main() Main
{ Functio
Employee e, *eptr; n
Programmer p; 3M

Page 22 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
Manager m;
clrscr();
cout<<"\nFor Programmer Class ";
eptr = &e;
eptr->emp();
p.getskill();
eptr->display();
eptr= &p;
eptr->display();

cout<<"\nFor Manager Class ";


eptr = &e;
eptr->emp();
m.getdept();
eptr->display();
eptr= &m;
eptr->display();

getch();
}

c) Write a C++ program for following multilevel inheritance. 6M

Accept and display data for one car with all details.

Ans #include<iostream.h>
#include<conio.h>
class Carmanufacturer
{ Declarat
char Name[10];

Page 23 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
public: ion &
void getcarm() Definitio
{ n of all
cout<<"\nEnter Car Name "; classes
cin>>Name; 3M
}

void putcarm()
{
cout<<"\nThe Car Name is "<<Name;
}
};
class Carmodel : public Carmanufacturer
{
char Modelname[10];
int Modelno;
public:
void getcarmodel()
{
cout<<"\nEnter Car Model Name and Model No. ";
cin>>Modelname>>Modelno;
}
void putcarmodel()
{
cout<<"\nEnter Car Model Name and Model No.
"<<Modelname<<" "<<Modelno;
}
};
class Car: public Carmodel
{
char colour[10], Carno[10];
public:
void getcar()
{
cout<<"\nEnter Car colour and car number";
cin>>colour>>Carno;
}
void putcar()
{

Page 24 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Object Oriented Programming with C++ Subject Code: 22316
cout<<"\nEnter Car colour and car number "<<colour<<"
"<<Carno;
}
};
void main()
{
Car c;
clrscr();
c.getcarm();
c.getcarmodel(); Main
c.getcar(); function
c.putcarm(); 3M
c.putcarmodel();
c.putcar();
getch();
}

Page 25 / 25

You might also like