CODE FOR Function overloading C++
- Get link
- X
- Other Apps
code:
#include<iostream>
using namespace std;
class shapes {
private:
int length, width, hieght;
public:
shapes()
{
length = 0;
width = 0;
hieght = 0;
cout << "ENTER LENGHT\nwidth\nhieght\n";
}
void choice()
{
cout << "ENTER YOUR CHOICE\n";
cout << "R-\tAREA OF RECTANGLE\nC-\tAREA OF CIRCLE\nT-\tAREA OF TRIANGLE\n";
}
void Area(int a)//area of circle
{
cout << "r=\t" << a << endl;
cout << "AREA OF CIRCLE\t" << 2 * 3.14 * a<<endl;
}
void Area(int a, int b)//AREA OF RECTANGLE
{
cout << "LENGTH\t" << a << "\nWIDTH\t" << b<<endl;
cout << "AREA OF RECTANGLE\t" << a * b;
}
void Area(int a, int b, int c)//triangLe
{
cout << "LENGTH\t" << a << "\nWIDTH\t" << b << "\nHIEGHT\t" << c << endl;
cout << "AREA OF TRIANGLE\t" << a + b + c << endl;
}
};
int main()
{
for (int i = 0; i < 2; i++)
{
shapes s1;
int x, y, z;
cin >> x >> y >> z;
s1.choice();
char c;
cin >> c;
switch (c)
{
case 'C':
{
s1.Area(x);
break;
}
case 'R':
{
s1.Area(x, y);
break;
}
case 'T':
{
s1.Area(x, y, z);
break;
}
default:
{
cout << "enter valid number\n";
exit(0);
}
}
}
}
- Get link
- X
- Other Apps
Comments
Post a Comment