Cube of Inputted number using Operator Overloading cpp
In this program, we are going see how to find and display Cube of Inputted number using Function Overloading  in C++ Programming Language.



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

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

class Mul
{
    int prod;

    public:
    Mul(int p = 0)
    {
        prod = p;
    }

    Mul operator*(Mul pd2)
    {
        Mul pd1;
        pd1.prod = prod * pd2.prod;
        return pd1;
    }
    void display()
    {
        cout << "Cube is: " << prod;
    }
};

void main()
{
    clrscr();
    int n;
    cout << "Enter a number: ";
    cin >> n;
    Mul m1(n);
    Mul m2(n);
    Mul m3(n);
    Mul m4;
    m4 = m1 * m2 * m3;
    m4.display();
    getch();
}

//.......Coded by SAHIL SHAIKH

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

#include <iostream>
using namespace std;

class Mul
{
    int prod;

    public:
    Mul(int p = 0)
    {
        prod = p;
    }

    Mul operator*(Mul pd2)
    {
        Mul pd1;
        pd1.prod = prod * pd2.prod;
        return pd1;
    }
    void display()
    {
        cout << "Cube is: " << prod;
    }
};

int main()
{
    int n;
    cout << "Enter a number: ";
    cin >> n;
    Mul m1(n);
    Mul m2(n);
    Mul m3(n);
    Mul m4;
    m4 = m1 * m2 * m3;
    m4.display();
    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