0% found this document useful (0 votes)
63 views20 pages

Summer-: Maharashtra Board of

The document provides a model answer key for an exam on object oriented programming using C++. It includes answers to questions on static and dynamic initialization of variables, syntax for declaring a class, characteristics of static member functions, types of visibility modes in inheritance, syntax for constructors in derived classes, defining polymorphism and its types, and defining a file and its operations.

Uploaded by

Srushti Porwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views20 pages

Summer-: Maharashtra Board of

The document provides a model answer key for an exam on object oriented programming using C++. It includes answers to questions on static and dynamic initialization of variables, syntax for declaring a class, characteristics of static member functions, types of visibility modes in inheritance, syntax for constructors in derived classes, defining polymorphism and its types, and defining a file and its operations.

Uploaded by

Srushti Porwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C+t Subject Code:

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 anyequivalent figure drawn.
5) Credits may be given step wise for numerical problems. ln some cases, the assumed
constantvalues 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

relevantanswer based on candidate's understanding.


7) For programming language papers, credit may be given to any other program based on
equivalent concept.
8) As per the policy decision of MaharashtraState Government, teaching in English/Marathi
and Bilingual (English + Marathi) medium is introduced at first year of AlCTE diploma
Programme from academic year 2021-2022.Hence if the students in first year (first and
second semesters) write answers in Marathi or bilingual language (English +Marathi), the
Examiner shall consider the same and assess the answer based on matching of concepts
with model answer.

Q. Sub Answer Marking


No Q.N. Scheme
1. Attempt any EIVE of the following: 10M
a Demonstratethe static and dynamic initialization of variables 2M
Ans. Static initialization Static

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)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors

22316
Subject:Object Oriented Programming Using C++ Subject Code:

cout<<"Enter value of variable ";


cin>>variable name;

Example
inta;
cout<<"Enter value of variable a"';

cin>>a;

Note Syntx/Exanple shallbe consideed

b) Write the syntax for declaration of a class 2M


Ans. class class name Correct
syntax 2M
private:
variable declarations;
function declarations;

public:
variable declarations;
function declarations:

c) State the characteristics of static member function 2M


Ans. A static function can have access to only other static members Any tuo
characteristi
declared in the class.
cs 1M each
A static member function can be called using the class name
instead of objects as follows:class name::function name:;

d) State different types of visibility modes in inheritance 2M


Ans. private Any tuo
ypes 1M
public eadh
protected

e) Give the syntax for constructor in derived classes 2M


Ans. Derived constructor

basel(arglist2),
(arglist1, arglist2,

...„bascN(arglistN)
,arglistN,):
Correct
syntax 2M

Body of derived class constructor

f) Define polymorphism with its types 2M


Ans. Polymorphism is the ability to take more than one form. Definition
1M

Page 2/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only for theUse of RAC Assessors

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

2 Attempt any THREE of the following: 12M


a) State the featuresof object oriented programming. 4M
Ans. Featuresof Object Oriented Programming are:
Any four
Follows bottom-up approach in program design.
features 1M
Emphasis is on data rather than procedure. each
Programs are divided into what are known as objects.
Data structures are designed such that they characterize the
objects

Functions that operate on the data of an object are tied together


in the data structures.

Data is hidden and cannot be accessed by external functions.


Objects may communicate with each other through functions.

New data and functions can be casily added whenever necessary

b) Explain overloaded constructor with suitable example. 4M


Ans. Constructoroverloading is a process of defining more than one
constructor functionin a class.

A class can have more than one constructor function Explanaton


2M
Type of constructor: default constructor, parameterized
constructor, constructor with default value and copy constructor.

An appropriate constructor function executes when number of


parameters and its data type matches with constructor function
prototype.

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);

In the above code, example is the name of the class.

First constructor is a default constructor that receives no arguments.


When object Il is created without values, first constructor executes

and assigns 0 value to variables a and b.


Second constructor receives one argument. When object I2 is

created with one value, second constructor executes and assigns


value 10 to variable a.

Third constructor receives two arguments.When object 13 is created


with two values, third constructor executes and assigns value 10 to
variable a and value 20 to variable b.

Page 4/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

Write a program on single inheritance 4M


Ans. #include<iostream.h>
#include<conio.h> Correct

class employee logic 2M

protected:
Correct
int emp id;
Syntx 2M
char name[10];

class emp info:public employee

int basicsalary:
public:
void getdata()

cout<<"Enter emp id";

cin>>emp id;
cout<<"Enter name":
cin>>name:
cout<<"Enter basic salary";
cin>>basic salary;

void putdata()

cout<<"nEmp id="<<emp id;


cout<<"nName-"<name:
cout<<"nBasic Salary="<<basic salary;

void main()

emp info e;

clrscr();

e.getdata):
e.putdata();

getch);

Note Any othe relevant rogr amshallbe considered!


d) Illustrate this pointer with example. 4M
Ans. C++ uses a unique keyword called 'this' to represent an object
that invokes a member function.

Page 5/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

"this'unique pointer is automatically passed to a member


functionwhen it is invoked. Explanation
2M
'this' is a pointer that always point to the object for which the
member function is called.

For example, the function call A.max ()will set the pointer

this' to the address of the object A. Then suppose we call

B.max (), the pointer this'will store addressof object B.

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( ):

In the above example, this pointer is used to represent objects when


setdata() and putdata () functions are called.

Note Any other relevantexample shall beconsidred.

3. Attempt any THREE of the following: 12M


a) Write a program to print first n natural numbers and their sum 4M
using for loop.
Ans.
#include<iostream.h>
#include<conio.h>

Page 6/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

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;

cout<< "Sum of numbers is ="<< sum;


getch();

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

2. Static data member is 2. Non-static data member


automatically initialized with can be initialized with zero or
zero. non-zero value,
3.All objects of a class share 3.Each object of theclass gets
the same copy of static data its own copy of non-static
members. data members.

4.It can be accessed through 4.Itcan be accessed only


static member function as well through non-static member
as non-static member function function of the class
of the class
5. Declaration Syntax: 5.DeclarationSyntax:
static data type variable; data type variable;
e.g. static int count; e.g. int no;

Page 7 /20
MAHARASHTRA STATE BOARD OF 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++ Subject Code:

c) State any four rules for virtual functions 4M


Ans. Rules for virtual function are:
1. A virtual functionmust be a member of some class.

2. Virtual functionscannot be static members.


3. Virtual functionscan be a friend of another class. Anyfour
corect rules
4. Virtual functionsshould be accessed using pointers.
1M each
5. A virtual function in based class must be defined, even though
it may not be used.
6. The prototype of virtual functions should be samne in base as
well as in derived class.

7. If it is defined in base class, it need not be necessarily redefined


in derived class.

8. A class may have virtual destructor, but it cannot have a virtual


constructor.

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

decrementing it will not make it to point to the next object of


derived class.

d) Write a program for get and put functions 4M


Ans. Programn code:
#include<iostream.h> Correct
syntax f
int main(0
get): 2M,

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):

cout<< "\nNumber of characters "<<count <<"n":


return 0;

Note Anyother relevantprogram shall be considered

Page 8/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER– 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C+t Subject Code:

4. Attempt any THREE of the following: 12M


a Explain the structureof Ctt program 4M
Ans. General C++ program has following structure:

INCLUDE HEADER FILES Corect


dagram 2M
CLASS DECLARATION

MEMBER FUNCTIONS DEFINITIONS

MAIN FUNCTION PROGRAM

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.

3. Member Functions Definition


This section allows programmers to design member functions of a
class. The programmer can have an inside declaration of a function
or outside declaration of a function.

4. Main Function Program


In this section programmers create objects and call various
functions writer within various class.

Page 9/ 20
MAHARASHTRA STATE BOARD OF 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++ Subject Code:

b) List any four properties of constructor function 4M


Ans. Properties of constructor function are:
1. A constructor name must be same as that of itsclass name. Anyfour
popeties
2. Constructors are called automatically when the objects are IM each
created.

3. Constructors should be declared in the public section to be


available to all the functions.

4. Constructors do not have return type, not even void and


therefore they cannot return value.

5. Constructorscan have default arguments as otherC++ functions.


6. Constructorscannot be inherited.
7. Constructorscannot be static.

8. Constructorscannot be virtual.
9. The address of a constructor cannot be referred.
10.Constructorsare member functions so they can be overloaded.

c) Illustrate the concept of virtual base class with suitableexample. 4M


Ans. Virtual Base Class: An ancestor class is declared as virtual base
class to avoid duplication of inherited members inside child class

due to multiplepaths of inheritance.

Grandparent

Parent 1 Parent

Child

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


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

Page 10/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001- 2005 Certified)

SUMMER– 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors

22316
Subject:Object Oriented Programming Using C+t Subject Code:

class Grandparent

class Parent1 :virtual public Grandparent

class Parent2:virtual public Grandparent

class Child: public Parent1,public Parent2

Example:
#include<iostream.h>

#include<conio.h>
class student

intrno;

public:
void getnumber)

cout<<"Enter RollNo:":

cin>>no;

void putnumber()

cout<<"nnt Roll No:"<<rno<<"n";

class test: virtual public student

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)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

cin>>part2;

void putmarks()

cout<<Mt Marks Obtained n'":

cout<<"nlt Part 1:"<<partl:


cout<<"n\tPart2:"<<part2;

class sports: public virtual student

public:
int score;

void getscore)

cout<<"Enter Sports Score:";


cin>>score;

void putscore)

cout<<"nlt Sports Score is:"<<score;

class result: public test, public sports

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)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

clrscr);

obi.getnumber();
obj.getmarks():

obj.getscore();
obj.display0:

getch);
}

d) State the advantages of pointer 4M


Ans. 1. Pointers save memory space.
Anyfour
2. Pointers reduce the length and complexity of a program.
corect
3. Pointers allow the passing of arrays and strings to functionmore
advantages
efficiently. 1M each
4. Pointers make it possible to return more than one value from the
function.

5. Execution time with pointers is faster because data are


manipulated with the address, that is, direct access to memory
location.

6. Memory accessed efficiently with the pointers. The pointer


is

assigns and releases the memory as well. Hence it can be said


the Memory of pointers is dynamically allocated.
7. Pointers are used with data structures. They are useful for

representing two-dimensionaland multi-dimensionalarrays.


8. An array, of any type, can be accessed with the help of pointers,
without considering its subscript range.
9. Pointers are used for file handling.

10. Pointers are used to allocate memory dynamically.


11. In C++, a pointer declared to a base class could access the object
of a derived class. However, a pointer to a derived class cannot
access the object of a base class.

e) Write a program for closing a file


4M
Ans. Program code:
#include<iostream>
#include <fstream>
int main)

Page 13/20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 -2005 Certified)

SUMMER– 2023 EXAMINATION


MODEL ANSWER-Onlyforthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

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;

5. Attempt any TWO of the following: 12M


a) State the use of scope resolution operator and explain it with 6M
example.
Ans. Scope ofa variable extends from the point of declaration to the Explnaton
3M
end of the block.

A variable declared inside a block is 'local' variable and a

variable declared outside block is called as global variable.


When we want to use a global variable but also has a local

variable with same name.


To access the global version of thevariable, C++providesscope
resolution operator.

Example:
#include <iostream> Example
3M
using namespace std;
char a ='m';
static intb= 50;
int main)
char a ='s':

cout<< "The value static variable b is : "<<::b;


cout<< "nThe value oflocal variable a is :" <<a;
cout<< "nThe value of global variable a is : <<:a; "
return 0;

Note Any other relevant example shall be cnsi der ed.

Page 14 /20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001- 2005 Certified)

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only fortheUse of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

b) Write a program to show object as functionargument. 6M


Ans. #include<iostream>
Correct
class Decimal
logic 3M

private:
int a: Correct

public: syntx 3M
void set(int x)

a =x:

void sum(Decimal obl, Decimal ob2)

a =obl.a + ob2.a:

void print)

cout<< "Value of A: "<<a<<endl;

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;

Note Any other relevant program shall be consi cered.

Page 15/20
MAHARASHTRA STATE BOARD OF 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++ Subject Code:

Write a program on hybrid inheritance 6M


Ans. #include <iostream>
class A Correct
logic 3M

public: Corect

int x: Syntx 3M

class B :public A

public:

B) llconstructor to initialize x in base class A

X= 10;

:
}
class C

public:

int y;
C //constructor to initialize y

y=4;

class D: public B, public C I/D is derived from class B and class


C

public:

void sum)

cout<< "Sum="<<x+ y;

int main)

Page 16/ 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C+t Subject Code:

D objl; llobject of derived class D


objl.sum(0:
return 0;

Note Any other rlevant program shallbe cnsi dered.


6. Attempt any TWO of the following 12M
a) State the difference between constructor and destructor(any six 6M
points)
Ans. Constructor Destructor Any six

points 1M
1. A constructor is a special|1. A destructor is a special each
member function whose task member function

is to initialize the objects of whose task is to destroy


its class. the objects that have
been created by
constructor.

2. Constructors are classified in2. Destructors are not


various types such as classified in any types.
Overloaded constructor
Default constructor
Parameterized constructor

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

members of the class.


7. Syntax 7. Syntax
classname) destructor name

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:

{.. preceded with tilde.

~classname()
....

8 Example 8. Example
ABC) ~ABC)
{

b) Explain abstract class with suitable example. 6M


Ans. By definition, a C++ abstract class must include at least one pure
Correct
virtual function.
explanation
Alternatively, put a function without a definition. 3M
Because the subclass would otherwise turn into an abstract class
Correct
in and of itself, the abstract class's descendants must specity the example 3M
pure virtual function.

Although the Abstract class type cannot be created from scratch,


it can have pointers and references made to
it.
A pure virtual function can exist in an abstract class in addition

to regular functions and variables.

The main objective of abstract base class is to provide some


traits to the derived classes and to create a base pointer required

for achieving run time polymorphism


Example:

#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)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C++ Subject Code:

height = ht;

protected:
int breadth:
int height;

class Rectangle: public Figure

public:
int Area()

return (breadth * height);

class Triangle: public Figure

public:
int Area()

return (breadth * height)2;

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;

Note Any other relevant eampleshall be consida ed.

Page 19/20
MAHARASHTRA STATE BOARDOF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER- 2023 EXAMINATION


MODEL ANSWER-Only forthe Use of RAC Assessors
22316
Subject:Object Oriented Programming Using C+t Subject Code:

c) Write C++ program to overload binary operator 4 to 6M


concatenate two strings.
Ans. #include<iostreanm> Correct
logic 3M
#include<string.h>
class String

public: Correct
char str[20]: syntax 3M
public:

void accept string()

cout<<"n Enter String


cin>>str:

void display_string)

cout<<str;

String operator+(String x) /Concatenating String

String s:

strcat(str,x.str);

strcpy(s.str,str);

return s;

int main)

String strl, str2, str3;

strl.accept string0:
str2.accept string(0;

str3=strl+str2;

cout<<"nn Concatenated String is

str3.display string):
return 0;

Page 20/ 20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy