Printing multiple data types using Constructor Overloading in C++ || Constructor Overloading || C++
In this, we are going to see how to Print integers and double numbers using Constructor Overloading, in C++.

 


The Code given below can be used in TURBO C++ Compilers: -

#include <stdio.h>
#include<conio.h>
class Point
{
    public:
    Point(int x, int y)
    {
        cout << "x=" << x << "    y=" << y << endl;
    }
    Point(double x, double y)
    {
        cout << "x=" << x << "  y=" << y;
    }

};

void main()
{
    clrscr();
    Point p1(5, 6), p2(4.5, 9.8);
    getch();
}

//...........Coded by Sahil Shaikh


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

class Point
{
    public:
    Point(int x, int y)
    {
        cout << "x=" << x << "    y=" << y << endl;
    }
    Point(double x, double y)
    {
        cout << "x=" << x << "  y=" << y;
    }

};

int main()
{
    Point p1(5, 6), p2(4.5, 9.8);
    return 0;
}

//...........Coded by Sahil Shaikh


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post