Summer-: Maharashtra Board of
Summer-: Maharashtra Board of
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
initialization
Syntax
datatype variable name=value; -1M,
dynamic
Example -
initialization
int a-5; -1M
int a;
a-5;
Dynamic initialization
Syntax -
int a;
Page 1/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)
22316
Subject:Object Oriented Programming Using C++ Subject Code:
Example
inta;
cout<<"Enter value of variable a"';
cin>>a;
public:
variable declarations;
function declarations:
basel(arglist2),
(arglist1, arglist2,
...„bascN(arglistN)
,arglistN,):
Correct
syntax 2M
Page 2/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
22316
Subject: Object Oriented Programming Using C+t Subject Code:
Types:
Types 1M
1. Compile time polymorphism
2. Run time polymorphism
ag)
Ans.
Define
A
file with
file is a collection
the disk.
its operations
of related data stored in a particular area on
2M
Definition
1M
File Operations: Any two
Open file operations
Close file 1M
Read file
Write file
Update file
Page 3/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-2023 EXAMINATION
MODEL ANSWER-OnlyfortheUse of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:
Example: Example
2M
class example
int a,b;
public:
example)
a-0;
b-0;
example(int x)
aFx;
example(int x,int y)
a-x;
b=y;
void main()
example Il;
example 12(10);
example I3(10,20);
Page 4/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
protected:
Correct
int emp id;
Syntx 2M
char name[10];
int basicsalary:
public:
void getdata()
cin>>emp id;
cout<<"Enter name":
cin>>name:
cout<<"Enter basic salary";
cin>>basic salary;
void putdata()
void main()
emp info e;
clrscr();
e.getdata):
e.putdata();
getch);
Page 5/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
For example, the function call A.max ()will set the pointer
Example Example
#include<iostream.h> 2M
class sample
int a;
public:
void setdata(int x)
this ->a-x;
void putdata()
cout<<this->a:
}:
void main()
sample s;
S.setdata( 100);
s.putdata( ):
Page 6/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
void main()
Declaration
1M,Display
int n, sum =0; of natural
clrscr); numbers
cout<< "Enter a positive integer:"; 1M,
cin>> n;
Calaulate
cout<<"nNatural numbers till "<<n<<" numbers are:";
and display
for(inti =1; i<< n; it+)
sum2M
cout<<i<<"":
cout<<"\n":
for (i = 1; iK=n; it+)
sum=sum+i;
b) Compare static and non static data members (any four points) 4M
Ans.
Static data member Non static data member Anyfour
Correct
keyword| without using
points 1M
1.It is declared using 1.It is declared
'static'. keyword 'static'. each
Page 7 /20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC- 27001 - 2005 Certified)
22316
Subject: Object Oriented Programming Using C++ Subject Code:
9. While a base pointer can point to any type of derived object, the
reverseis not true.
10. When a base pointer points to a derived class, incrementing or
int count = 0:
char c;
Correct
cout<< "INPUT TEXTn";
syntax gf
cin.get(c); 2M
put):
while (c!=n')
cout.put(c);
count++t;
cin.get(c):
Page 8/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Description:-
1. Include header files
Correct
In this section programmer includes all header files which are
a explanation
required to execute a given program. The most important file is 2M
iostream.h header file. This file defines most of the C+statements
like cout and cin. Without this file one cannot load the C++
program.
2. Class Declaration
In this section a programmer declares all classes which are
necessary for the given program. The programmer uses general
syntax of creating class.
Page 9/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
22316
Subject: Object Oriented Programming Using C++ Subject Code:
8. Constructorscannot be virtual.
9. The address of a constructor cannot be referred.
10.Constructorsare member functions so they can be overloaded.
Grandparent
Parent 1 Parent
Child
Page 10/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001- 2005 Certified)
22316
Subject:Object Oriented Programming Using C+t Subject Code:
class Grandparent
Example:
#include<iostream.h>
#include<conio.h>
class student
intrno;
public:
void getnumber)
cout<<"Enter RollNo:":
cin>>no;
void putnumber()
public:
int part1,part2;
void getmarks()
cout<<"EnterMarks\n";
cout<<"Part1:":
cin>>partl; cout<<"Part2.":
Page 11/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC- 27001 - 2005 Certified)
cin>>part2;
void putmarks()
public:
int score;
void getscore)
void putscore)
int total;
public:
void display()
total-partl+part2+score;
putnumber);
putmarks();
putscore();
:
cout<<"nit Total
void main)
Score:"<<total:
result obj;
Page 12/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
clrscr);
obi.getnumber();
obj.getmarks():
obj.getscore();
obj.display0:
getch);
}
Page 13/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)
fstreamFile Name:
File object
FileName.open("FileName.txt",
ios:in);
creation 1M,
(!FileName) opening of
if
file 1M,.
cout<<"Filedoesn't exist"; closing of
file 2M
else
cout<<"Fileopened successfully";
FileName.close);
return 0;
Example:
#include <iostream> Example
3M
using namespace std;
char a ='m';
static intb= 50;
int main)
char a ='s':
Page 14 /20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001- 2005 Certified)
private:
int a: Correct
public: syntx 3M
void set(int x)
a =x:
a =obl.a + ob2.a:
void print)
int main()
Decimal dl;
Decimal d2;
Decimal d3:
dl.set(10);
d2.set(20):
d3.sum(d1, d2);
cout<<"First Decimal valuen";
dl.print();
cout<<"Second Decimal valuen";
d2.print():
cout<<"Sum of Decimal object1 and object2 -\n";
d3.print():
return 0;
Page 15/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)
public: Corect
int x: Syntx 3M
class B :public A
public:
X= 10;
:
}
class C
public:
int y;
C //constructor to initialize y
y=4;
public:
void sum)
cout<< "Sum="<<x+ y;
int main)
Page 16/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
points 1M
1. A constructor is a special|1. A destructor is a special each
member function whose task member function
Copy constructor
3. It is invoked automatically3. It is invoked implicitly
when the objects are created. by the compiler upon
exit of program / block
function.
4. Constructor accepts 4. Destructor never
parameters. Also it can have acceptsany parameter.
default value for its
parameter.
|5. A class can have more than|5. A class can have at the
one constructort. most one constructor.
It constructs the values of6. It does not construct the
).
data members of the class. values for the data
Page 17 / 20
MAHARASHTRA STATE BOARDOF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)
SUMMER-2023 EXAMINATION
MODEL ANSWER-Only for the Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C+t SubjectCode:
~classname()
....
8 Example 8. Example
ABC) ~ABC)
{
#include<iostream>
class Figure
public:
virtual int Area() =0;
void setBreadth(int br)
breadth =br;
void setHeight(int ht)
Page 18 / 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)
height = ht;
protected:
int breadth:
int height;
public:
int Area()
public:
int Area()
int main)
Rectangle R1;
Triangle T1;
R1.setBreadth(6);
RI.setHeight(1 2);
TI.setBreadth(40);
Tl.setHeight(4);
cout<< "The area of therectangle is:" <<RI.Area() <<endl;
cout<< "The area ofthe triangle is: "<< T1.Area() <<endl;
Page 19/20
MAHARASHTRA STATE BOARDOF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
public: Correct
char str[20]: syntax 3M
public:
void display_string)
cout<<str;
String s:
strcat(str,x.str);
strcpy(s.str,str);
return s;
int main)
strl.accept string0:
str2.accept string(0;
str3=strl+str2;
str3.display string):
return 0;
Page 20/ 20