Write a C++ program using constructor overloading.


Algorithm to solve the above problem:
STEP 1: Start the program
STEP 2: Create three member functions using the class name as constructors for read,write and display the values
STEP 3: Create three objects, call functions by passing the values
STEP 4: Call the function, by using dot operator to process the respective Execution
STEP 5: Return the values to the called function to the cailing function
STEP 6: Write the value in the main program
STEP 7: Terminate the program.

Implementation of above problem using C++:
#include<iostream>
using namespace std;
class integer
{
int m, n;
public:
integer(int x, int y)
{
m=x;
n=y;
}
void display(void)
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
}
};

int main()
{
integer obj1(0,10);
integer obj2 = integer(5,7);
cout<<"OBJECT 1"<<"\n";
obj1.display();
cout<<"OBJECT 2"<<"\n";
obj2.display();
return 0;
}

The program output is tested on www.jdoodle.com
Output:
OBJECT 1
m=0
n=10
OBJECT 2
m=5
n=7


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: