Skip to content

Commit 02e86b7

Browse files
authored
Add files via upload
Create a class called Shape with the attributes area(double) and member function calculateArea() for calculating the area of different shapes(square,circle,rectangle,triangle).Write a program to create an object and call the findArea() function with one integer argument to calculate the area of Square, two integer arguments to calculate the area of Rectangle,one double argument to calculate area of Circle,three integer arguments to calculate area of Triangle using function overloading.
1 parent e9e7c96 commit 02e86b7

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

fourteen.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*14.Create a class called Addition with the member function findAddition() for
2+
calculating the addition between the given numbers during the function
3+
call. Write a program to create an object and call the findAddition()
4+
function with two integer arguments,three integer arguments and two
5+
double arguments to implement function overloading*/
6+
7+
#include <iostream>
8+
using namespace std;
9+
10+
class Addition {
11+
public:
12+
// Function to calculate addition of two integers
13+
int findAddition(int a, int b) {
14+
return a + b;
15+
}
16+
17+
// Function to calculate addition of three integers
18+
int findAddition(int a, int b, int c) {
19+
return a + b + c;
20+
}
21+
22+
// Function to calculate addition of two doubles
23+
double findAddition(double a, double b) {
24+
return a + b;
25+
}
26+
};
27+
28+
int main() {
29+
Addition add_obj;
30+
31+
// Call findAddition with two integer arguments
32+
int result1 = add_obj.findAddition(10, 20);
33+
34+
// Call findAddition with three integer arguments
35+
int result2 = add_obj.findAddition(10, 20, 30);
36+
37+
// Call findAddition with two double arguments
38+
double result3 = add_obj.findAddition(10.5, 20.5);
39+
40+
// Print the results
41+
cout << "Addition of two integers: " << result1 << endl;
42+
cout << "Addition of three integers: " << result2 << endl;
43+
cout << "Addition of two doubles: " << result3 << endl;
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)