Area of Rectangle and Trapezoid using Polymorphism || Polymorphism || C++



In this program, we are going to Find Area of rectangle and Trapezoid using Polymorphism in C++ Programming Language. 
 


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

#include <iostream>
using namespace std;

class Calculator
{
    public:
    static int area(int x, int y)
    {
        return x * y;
    }

    static int area(int x, int y, int z)
    {
        int v = (x + y) / 2;
        int w = z * v;
        return w;
    }
};

int main()
{
    Calculator obj;
    cout << "Area of rectangle = " << obj.area(10, 20) << endl;
    cout << "Area of trapezoid = " << obj.area(12, 20, 23);
    return 0;
}

//.......Coded by RISHAB NAIR


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

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

class Calculator
{
    public:
    static int area(int x, int y)
    {
        return x * y;
    }

    static int area(int x, int y, int z)
    {
        int v = (x + y) / 2;
        int w = z * v;
        return w;
    }
};

void main()
{
    clrscr();
    Calculator obj;
    cout << "Area of rectangle = " << obj.area(10, 20) << endl;
    cout << "Area of trapezoid = " << obj.area(12, 20, 23);
    getch();
}

//.......Coded by RISHAB NAIR


#ENJOY CODING

Post a Comment

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

Previous Post Next Post