Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
370 views
in Object Oriented Programming with C++ by (49.1k points)
closed by

Write the coding for the following output using constructor overloading.

Output:

Constructor without parameters.

Parameterized constructor… 

Copy Constructor… 

Enter data… 20 30 

Object a: 

The numbers are..20 30 

The sum of the numbers are.. 50 

Object b : 

The numbers are..10 20 

The sum of the numbers are.. 30

Object c.. 

The numbers are..10 20 

The sum of the numbers are.. 30

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

#include

using namespace std;

class add

{

int num1, num2, sum; 

public:

add()

{

cout << “\n Constructor without parameters…”; 

num1 = 0;

num2 = 0;

sum = 0;

}

add (int s1, int s2 )

{

cout << “\n Parameterized constructor…”;

num1= s1;

num2=s2;

sum=0;

}

add (add &a)

{

cout << “\n Copy Constructor…”; ‘

num1 = a.num1;

num2 = a.num2;

sum = 0;

}

void getdata()

{

cout<<“\n Enter data …”; cin>>num 1 >> num2;

}

void addition()

{

sum=num 1 + num2;

}

void putdata()

{

cout << “\n The numbers are..”;

cout <cout << “\n The sum of the numbers are..” << sum; }

};

int main()

{

add a, b (10, 20), c(b);

a. getdata();

a. addition();

b. addition();

c. addition();

cout << “\n Object a : “;

a. putdata();

cout << “\n Object b : “;

b. putdata();

cout << “\n Object c..”;

c. putdata();

return 0; 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...