2024 Summer Model Answer Paper
2024 Summer Model Answer Paper
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using 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.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual
(English + Marathi) medium is introduced at first year of AICTE diploma Programme from academic
year 2021-2022. Hence if the students 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.
Sub
Q. Marking
Q. Answer
No. Scheme
N.
1. Objects: Objects are the fundamental building blocks of OOP. They (Any two
represent real-world entities with attributes (data) and methods (functions) correct
that define their behavior. features)
2. Classes: A class that defines the properties and methods of an object. A
class that creates multiple objects of the same kind.
3. Encapsulation: Encapsulation is the process of bundling data and methods
together into a single unit, protecting the data from direct access outside
the object. This ensures data integrity and promotes modularity.
4. Inheritance: Inheritance allows new classes to inherit properties and
methods from existing classes. This promotes code reusability and
simplifies the creation of hierarchical relationships between objects.
5. Polymorphism: Polymorphism allows objects of different classes to
respond differently to the same message. This makes code more flexible
and adaptable.
6. Abstraction: Abstraction refers to the user’s interaction with a subset of
an object’s characteristics and operations.
Page 1 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
7. Dynamic Binding: In dynamic binding, the code to be executed in response
to the function call is decided at runtime. Because dynamic binding is
flexible, it avoids the drawbacks of static binding, which connected the
function call and definition at build time.
8. Message Passing: Objects communicate with one another by sending and
receiving information. A message for an object is a request for the execution
of a procedure and therefore will invoke a function in the receiving object
that generates the desired results. Message passing involves specifying the
name of the object, the name of the function, and the information to be sent.
Object:
Object is a basic run time entity that represents a person, place or any item that the
program has to handle.
c) What are the rules for virtual function (write any two) 2M
Ans. 1. Function Prototype Matching: The prototype (including return type, name, 1M each
and parameter list) of a virtual function must be identical in the base class and all (Any 2 correct
derived classes that override it. This ensures that the compiler can identify the Rules)
function correctly even when using a base class pointer or reference.
3. Declaration: Virtual functions are declared using the virtual keyword in the
base class.
Page 2 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
7. Base Class Definition: A virtual function must be defined (have a body) in the
base class, even if it's not overridden in any derived classes.
9. No Virtual Constructors: Class cannot have virtual constructors, but can have
virtual destructors.
Ans. Memory Management operators are new and delete. 1M for Any
one Use
Uses of Memory management operators: &
1M for
• Dynamic memory allocation in C++ refers to performing memory Example
allocation manually by a programmer.
• Use of dynamically allocated memory is to allocate memory of variable
size, which is not possible with compiler allocated memory except
for variable-length arrays.
• The most important use is the flexibility provided to programmers.
• We are free to allocate and deallocate memory whenever we need it and
whenever we don’t need it anymore.
delete operator: This operator is used to deallocate memory that was previously
allocated using new operator. It takes a pointer to the memory block you want to
free as an argument.
Example:
delete [ ] numbers;
Page 3 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
e) List different types of inheritance. 2M
f) List C++ stream classes along with their function (any two classes) 2M
2. ios class: The ios class is responsible for providing all input and output
facilities to all other stream classes.
4. iostream class: This class is responsible for handling both input and output
stream as both istream class and ostream class is inherited into it. It
provides function of both istream class and ostream class for handling
chars, strings and objects such as get, getline, read, put, write etc.
Page 4 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
int no, fact=1, i; 2M for correct
syntax
cout<<"Enter number:";
cin>>no;
for(i=1;i<=no;i++)
{
fact=fact*i;
}
cout<<"Factorial ="<<fact;
}
Note: Any other correct logic should be considered.
Characteristics:
• Friend function is not in the scope of the class to which it has been
declared as friend.
• It is called without any object of class like a normal function.
• It cannot access the member names directly and has to use an object name
and dot membership operator with each member name.
• It can be declared either in the public or the private part of a class without
affecting its meaning.
• It has the objects as arguments.
Example:
Program to interchange values of two integer numbers using friend
function.
#include<iostream>
using namespace std;
class B;
class A
{
Page 5 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
int x;
public: void accept()
{
cout<<"\n Enter the value for x:";
cin>>x;
}
friend void swap(A,B);
};
class B
{
int y;
public: void accept()
{
cout<<"\n Enter the value for y:";
cin>>y;
}
friend void swap(A,B);
};
void swap(A a, B b)
{
cout<<"\n Before swapping:";
cout<<"\n Value for x="<<a.x;
cout<<"\n Value for y="<<b.y;
int temp;
temp =a.x;
a.x=b.y;
b.y=temp;
cout<<"\n After swapping:";
Page 6 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
cout<<"\n Value for x="<<a.x;
cout<<"\n Value for y="<<b.y;
}
int main()
{
A a;
B b;
a.accept();
b.accept();
swap(a,b);
}
Note: Any other correct logic should be considered.
Page 7 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
#include<iostream>
using namespace std;
class electronicDevice
{
public:
electronicDevice()
{
cout << "I am an electronic device.\n\n";
}
};
class Computer: public electronicDevice
{
public:
Computer()
{
cout << "I am a computer.\n\n";
}
};
class Linux_based : public Computer
{
public:
Linux_based()
{
cout << "I run on Linux.\n\n";;
}
};
int main()
{
Linux_based obj;
Page 8 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
}
d) Explain virtual function with example. Give the rules for virtual functions. 4M
void show()
{
cout << "show base class\n";
}
};
Page 9 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
bptr = &d;
bptr->print();
bptr->show();
}
Rules for virtual functions:
1. The virtual functions must be members of some class.
2. They cannot be static members.
3. They are accessed by using object pointers.
4. A virtual function can be a friend of another class.
5. A virtual function in a base class must be defined, even though it may not be
used.
6. The prototypes of the base class version of a virtual function and all the
derived class versions must be identical.
7. We cannot have virtual constructors, but we can have virtual destructors.
8. While a base pointer can point to any type of the derived object, the reverse is
not true we cannot use a pointer to a derived class to access an object of the base
type.
9. When a base pointer points to a derived class, incrementing or decrementing it
will not make it to point to the next object of the derived class it is incremented
or decremented only relative to its base type.
10. If a virtual function is defined in the base class, it need not be necessarily
redefined in the derived class.
a) Develop a program to declare a class student the data members are rollno, 4M
name and marks accept and display data for one object of class student.
Page 10 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
cout<<"\nEnter data of student:";
cout<<"\nRoll number:";
cin>>rollno;
cout<<"\nName:";
cin>>name;
cout<<"\nMarks:";
cin>>marks;
}
void student::display()
{
cout<<"\nStudents data is:";
cout<<"\nRoll number:"<<rollno;
cout<<"\nName:"<<name;
cout<<"\nMarks:"<<marks;
}
int main()
{
student S;
S.accept();
S.display();
}
b) Describe the concept of virtual base class with suitable example. 4M
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
{
};
Page 11 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
class Parent1: virtual public Grandparent
{
};
class Parent2: public virtual Grandparent
{
};
class Child: public Parent1, public Parent2
{
};
Example:
#include<iostream>
using namespace std;
class student
{
int rno;
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:
Page 12 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
int score;
void getscore()
{
cout<<"Enter Sports Score:";
cin>>score;
}
void putscore()
{
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;
}
};
int main()
{
result obj;
obj.getnumber();
obj.getmarks();
obj.getscore();
obj.display();
}
Note: Any relevant example should be considered.
c) Write a C++ program to declare a class college with name and code. Derive 4M
new class as student with members as name. Accept and display details of
one students along with college data.
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
cin>>name; Main function
cout<<"Enter Code:"; with correct
cin>>code; syntax
}
void display_college()
{
cout<<endl<<"College Name:"<<name;
cout<<endl<<"College Code:"<<code;
}
};
class student:public college
{
char sname[10];
public:
void accept_student()
{
cout<<"Enter student Name:";
cin>>sname;
}
void display_student()
{
cout<<endl<<"Student Name:"<<sname;
}
};
int main()
{
student s;
s.accept_college();
s.accept_student();
s.display_college();
s.display_student();
Page 14 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
return 0; Printing
} number of lines
from a file
Note: Any other correct logic should be considered.
4. Attempt any THREE of the following: 12M
Ans. 3M for
Description of
visibility mode
and its effects
(1M for each
mode)
&
1M for
Fig.: Visibility of inherited members
Example with
Visibility modes, also known as access specifiers, are important concepts in object- all 3-visibility
oriented programming language. They control how other parts of the code can mode
access the properties (data members) and functionalities (member functions) of a
class. This is crucial for data hiding and creating well-organized code.
Public: When a base class is inherited with public visibility mode, the protected
members of the base class will be inherited as protected members of the derived
class and the public members of the base class will be inherited as public
members of the derived class.
Private: When a base class is inherited with private visibility mode the public
and protected members of the base class become ‘Private’ members of the
derived class.
Protected: When a base class is inherited with protected visibility mode the
protected and public members of the base class become ‘protected members’ of
the derived class.
Example:
class A
{
public: int x;
protected: int y;
private: int z;
};
class B: public A
{
// x is public
Page 15 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
// y is protected
// z is not accessible from B
};
class C: protected A
{
// x is protected
// y is protected
// z is not accessible from C
};
class D : private A
{
// x is private
// y is private
// z is not accessible from D
};
Note: Any relevant example should be considered.
b) Differentiate between constructor and destructor (any 4 points) 4M
7 The constructor’s name is same Here, its name is also same as the
as the class name. class name preceded by the tiled (~)
operator.
Page 16 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
8 In a class, there can be multiple While in a class, there is always a
constructors. single destructor.
11 Syntax: Syntax:
classname() destructor name is preceded
{… with tilde.
… ~classname()
} {….
….
}
12 Example: Example:
ABC() ~ABC()
{ {
… ….
} }
Example:
#include <iostream>
using namespace std;
// overloaded functions
void test(int);
void test(float);
void test(int, float);
Page 17 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
int main()
{
int a = 5;
float b = 5.5;
return 0;
}
// Method 1
void test(int var)
{
cout << "Integer number: " << var << endl;
}
// Method 2
void test(float var)
{
cout << "Float number: "<< var << endl;
}
// Method 3
void test(int var1, float var2)
{
cout << "Integer number: " << var1;
cout << " and float number:" << var2;
}
Function Overriding:
Example:
#include<iostream>
using namespace std;
class BaseClass
{
public:
virtual void Display()
Page 18 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
{
cout << "\nThis is Display() method of BaseClass";
}
void Show()
{
cout << "\nThis is Show() method of BaseClass";
}
};
// Driver code
int main()
{
DerivedClass dr;
BaseClass &bs = dr;
bs.Display();
dr.Show();
}
Note: Any relevant example should be considered.
d) Develop a C++ program to read content of file abc.txt 4M
inputFile.close();
} else {
Page 19 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
//cerr << "Error: Could not open file 'abc.txt'." << endl;
cout << "Error:'abc.txt' File not found." << endl;
}
return 0;
}
Description:
1. Include files
In this section a programmer includes 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 like cout and cin. Without this file one cannot load C++
program.
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.
In this section programmer creates objects and calls various functions writer within
various class.
Example:
#include<iostream>
using namespace std;
Page 20 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
class MyClass // The class
{
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};
int main()
{
MyClass myObj; // Create an object of MyClass
void setTeacherDetails()
{
cout<<"Enter Employee Name:";
cin>>Name;
void displayTeacherDetails()
Page 21 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
{
cout << "Employee Name: " << Name << endl;
cout << "Employee ID: " << emp_id << endl;
}
};
// Base class Student
class Student {
public:
string S_Name;
int Roll_No;
void setStudentDetails()
{
cout<<"Enter Student Name:";
cin>>S_Name;
int main() {
Info info;
info.setTeacherDetails();
info.setStudentDetails();
cout<<endl;
info.displayInfo();
}
OR
#include <iostream>
using namespace std;
// Base class Teacher
class Teacher {
public:
Page 22 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
string Name;
int emp_id;
void displayTeacherDetails() {
cout << "Teacher Name: " << Name << endl;
cout << "Employee ID: " << emp_id << endl;
}
};
void displayStudentDetails() {
cout << "Student Name: " << S_Name << endl;
cout << "Roll Number: " << Roll_No << endl;
}
};
info.setTeacherDetails("Alice", 123);
info.setStudentDetails("Bob", 456);
info.displayInfo();
Page 23 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
b) Develop a program to declare class book containing data members as title 6M
,authorname ,publication, price accept and display the information for one
object using pointer to that objects.
int main()
{
book b,*p;
p=&b;
p->accept();
p->display();
return 0;
}
c) Develop a C++ program to add two 3x3 matrices and display addition. 6M
int main()
Page 24 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
{ 2M for
int a[3][3],b[3][3],c[3][3]; Addition of
int i,j; Two Matrices
&
cout<<"\n Enter the matrix for A:"; 2M for
for(i=0;i<3;i++) Displaying
{ Addition of
for(j=0;j<3;j++) Matrix
{
cin>>a[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(j=0;j<3;j++)
{
cout<<"\t"<<c[i][j];
}
}
}
6. Attempt any TWO of following. 12M
a) Develop a C++ program to create structure book with data members name, 6M
cost and author. Accept and display data for 5 books using structure
Page 25 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
Ans. #include<iostream> 2M for correct
using namespace std; Code for
struct book Structure
{ Definition,
char name[30]; 2M for
int cost; Accepting data
char author[30]; &
}b[5]; 2M for
Displaying data
int main()
{
int i;
for(i=0;i<5;i++)
{
cout<<"\n Enter the Book "<<i+1<<" Name:";
cin>>b[i].name;
for(i=0;i<5;i++)
{
cout<<"\n The Book "<<i+1<<" Name:"<<b[i].name;
cout<<endl;
}
}
b) Develop a C++ program using parameterized constructor 6M
Ans. #include<iostream> 2M
using namespace std; for class
class number Definition,
{ 2M
int x; for constructor
public: Definition
Page 26 of 28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
number(int y) &
{ 2M
x=y; for Correct
} implementation
void display( )
{
cout<<"The sqaure of number is:"<<x*x;
}
};
int main( )
{
number n(50);
n.display( );
}
Note: Any other relevant program should be considered.
c) Write a C++ program to overload “+” operator so that it will perform 6M
concatenation of two strings. (Use class get data function to accept two
strings.)
SUMMER-2024 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Subject Name: Object Oriented Programming using C++ Subject Code: 22316
str2.input( );
str3=str1+str2;
str3.display( ); //displaying
OR
#include<iostream>
#include<string.h>
using namespace std;
class string_concat
{
char s1[30];
char s2[30];
public:
void getdata( )
{
cout<<"\n Enter the First String :";
cin>>s1;
}
void operator+( )
{
cout<<"\n The concatenation of two String
is:"<<strcat(s1,s2);
}
};
int main( )
{
string_concat s;
s.getdata( );
+s;
}
Page 28 of 28