OOP Exam Model Answer Guide
OOP Exam Model Answer Guide
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
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 Marki
No Q.N. ng
. Schem
e
Page 1 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 2 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 3 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
WINTER – 2018 EXAMINATION
MODEL ANSWER
22316
Subject: Object Oriented Programming
with C++ Subject Code:
{
smallest=a[i];
}
}
cout<<endl<<"Smallest number="<<smallest;
getch();
}
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
Ans circle. #include<iostream.h>
#include<conio.h> Decalar
class circle ation
{ and
float radius,area; Defini
public: tio n
void getdata() of
{ class
cout<<"Enter radius:"; with
cin>>radius; functi
} on s
void putdata() 3M
{
area=3.14*radius*radius;
cout<<"Area of circle="<<area;
Page 5 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
} Main
}; functi
void main() on 1M
{
circle c;
clrscr();
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, Descr
then pointer variable points to next memory address that means ipt
pointer increment with respect to size of the data type used to ion of
declare pointer variable. ++
operat
Example:- or 1M
int a[5]={10,20,30,40,50},*ptr;
ptr=a[0];
for(i=0;i<5;i++) Any
{ relevan
cout<<*ptr; t
ptr++; Examp
} le 1M
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].
Page 6 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Main
functio
n 1M
Page 7 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
a.display();
getch();
}
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 Descr
like cout and cin. Without this file one cannot load C++ program. ipt
2. Class Declaration ion
In this section a programmer declares all classes which are 2M
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.
Page 8 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
Page 9 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
{
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 4M
Ans example. 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 memb
shared by all the objects of that class. er
2M
Example:
#include<iostream.h>
#include<conio.h> Releva
class test nt
{ exampl
e 2M
Page 11 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
WINTER – 2018 EXAMINATION
MODEL ANSWER
22316
Subject: Object Oriented Programming
with C++ Subject Code:
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 14 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
#include<iostream.h> Correct
#include<conio.h> syntax
void swap(int a,int b) 2M
{
int temp;
temp=a;
a=b;
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 16 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 17 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
WINTER – 2018 EXAMINATION
MODEL ANSWER
22316
Subject: Object Oriented Programming
with C++ Subject Code:
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();
}
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
Ans than 10,000. #include<iostream.h>
#include<conio.h> Creati
class Account ng
{ Class
long int accno, bal; 2M
char name[10];
public: Logic
void getdata() to
{ Displa
cout<<"\nEnter account number, balance and name "; y
cin>>accno>>bal>>name; object
} with
void putdata() given
{ conditio
if(bal>10000) n
{ 1M
cout<<"\nThe Account Number is "<<accno;
cout<<"\nThe Balance is "<<bal; Creati
cout<<"\nThe Name is "<<name; ng 8
} objects
} 1M
};
void main()
{ Calling
Account a[8]; functi
int i; on s
clrscr(); 2M
for(i=0;i<8;i++)
{
a[i].getdata();
}
for(i=0;i<8;i++)
{
Page 19 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
#include<iostream.h>
#include<conio.h>
Creati
ng
struct
ur
Page 20 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Accept and display data for one programmer and one manager.
Make display function virtual.
Ans.
#include<iostream.h>
#include<conio.h>
class Employee
{ Creati
int empid,empcode; ng all
public: classes
void emp() 3M
{
cout<<"\nEnter an employee id ";
cin>>empid;
cout<<"\nEnter an employee code ";
cin>>empcode;
Page 21 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 22 / 25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Manager m;
clrscr();
cout<<"\nFor Programmer Class ";
eptr = &e;
eptr->emp();
p.getskill();
eptr->display();
eptr= &p;
eptr->display();
getch();
}
inheritance.
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 25 / 25