FY-3-b Easy program to calculate area and volume using method overloading

OOP program to calculate area and volume using method overloading

Design a class Geometry containing the methods area() and volume() and also
overload the area() function.

Click here to get other OOP Practical

FYIT practical 3-b OOP method overloading program

#include<iostream>
using namespace std;
class geometry
{
public:
int area(int x)
{
return(x*x);
}
int area(int x,int y)
{
return(x*y);
}
int volume(int x)
{
return(x*x*x);
}
int volume(int x, int y, int z)
{
return(x*y*z);
}
};
int main()
{
geometry g;
cout<<"Area of Square is "<<g.area(20)<<endl;
cout<<"Area of rectangle is "<<g.area(30,12)<<endl;
cout<<"Area of cube is "<<g.volume(5)<<endl;
cout<<"Area of cuboid is "<<g.volume(5,7,9);
return 0;
}

 

Output

oop-program-to-calculate-area-and-volume-using-method-overloading-itvoyagers

Check out more FYIT OOP Practical Program and other logic building programs in C++

We are aiming to explain all concepts of C++ and OOP in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment