Quantcast
Viewing all articles
Browse latest Browse all 10

Find the Area of shapes using function overloading

Here is a program which will find the Area of shapes using function overloading.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "iostream"
#include "conio.h"
using namespace std;
class measure
{
	public:
		void shape(int r);
		void shape(int l,int b);
		void shape(float t,int d,int e);
		void shape(long a);
		void shape(float c, long int g);
		void shape(double j);
		void shape(float h, double f);
};
void measure::shape(int r)
{
	cout<<"area of the circle is "<<3.14*r*r;
}
void measure::shape(int l,int b)
{
	cout<<"area of the rectangle is"<<l*b;
}
void measure::shape(float t,int d,int e)
{
	cout<<"area of the triangle is"<<t*d*e;
}
void measure::shape(long a)
{
	cout<<"area of the square is"<<a*a;
}
void measure::shape(float c, long int g)
{
	cout<<"Volume of the cone is "<<(1/3)*3.14*c*c*g;
}
void measure::shape(double j)
{
	cout<<"Volume of the sphere is "<<(4/3)*3.14*j*j*j;
}
void measure::shape(float h, double f)
{
	cout<<"\nVolume of the Cylinder is "<<3.14*f*f*h;
}
int main()
{
	int r,d,e,l,b;
	float t,c,h;
	long a;
	int ch;
	double j,f;
	long int g;
	measure obj;
	cout<<"\tCALCULATION OF AREA AND VOLUME";
	cout<<"\n\n1. area of circle";
	cout<<"\n2. area of rectangle";
	cout<<"\n3. area of triangle";
	cout<<"\n4. area of square";
	cout<<"\n5. Volume of the cone";
	cout<<"\n6. Volume of the sphere";
	cout<<"\n7. Volume of the cylinder";
	cout<<"\n\tEnter your choice ";
	cin>>ch;
	switch(ch)
	{
		case 1:
			cout<<"enter the value of radius of the circle \n";
			cin>>r;
			obj.shape(r);
			break;
		case 2:
			cout<<"enter the sides of rectangle \n";
			cin>>l>>b;
			obj.shape(l,b);
			break;
		case 3:
			cout<<"enter the sides of triangle \n";
			cin>>d>>e;
			obj.shape(0.5,d,e);
			break;
		case 4:
			cout<<"enter the sides of square";
			cin>>a;
			obj.shape(a);
			break;
		case 5:
			cout<<"\nEnter the radius of the cone";
			cin>>c;
			cout<<"\nEnter the height of the cone";
			cin>>g;
			obj.shape(c,g);
			break;
		case 6:
			cout<<"\nEnter the radius";
			cin>>b;
			obj.shape(b);
			break;
		case 7:
			cout<<"\nEnter the radius";
			cin>>f;
			cout<<"\nEnter the height";
			cin>>h;
			obj.shape(h,f);
			break;
		default:
			cout<<"\nThe choice entered is a wrong choice";
	}
	getch();
}

Viewing all articles
Browse latest Browse all 10

Trending Articles