-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionOverloadingAreaPerimeterDEMO.m4.cpp
More file actions
99 lines (78 loc) · 2.67 KB
/
Copy pathFunctionOverloadingAreaPerimeterDEMO.m4.cpp
File metadata and controls
99 lines (78 loc) · 2.67 KB
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
//************************************************************************
// Author: Rolando Carreon
// Date: mar 18 2025
// Language: C++
// Assignment: FunctionOverloadingAreaPerimeterDEMO.m4
// Description: calculate the area and perimeter of a rectangle or circle
//************************************************************************
#include<iostream>
using namespace std;
//function prototypes
double area(int);
int area(int, int);
double area (double, double);
double perimeter(int);
int perimeter(int, int);
double perimeter(double, double);
// global varibles
const double PI = 3.1415926535;
int main()
{
// declare local variables
int base1 = 6, height1 = 8;
double base2 = 2.5, height2 = 1.8;
int radius1 = 3;
// get the area'perimter of a rectangle using integers
cout << "Passing base and height as integers\n";
cout << "Area: " << area(base1, height1) << endl;
cout << "Perimeter: " << perimeter(base1, height1) << endl;
cout << endl;
// get the area'perimter of a rectangle using doubles
cout << "Passing base and height as doubles\n";
cout << "Area: " << area(base2, height2) << endl;
cout << "Perimeter: " << perimeter(base2, height2) << endl;
cout << endl;
// get the area'perimter of a circle using integer
cout << "Passing radius as integer\n";
cout << "Area: " << area(radius1) << endl;
cout << "Perimeter: " << perimeter(radius1) << endl;
cout << endl;
return 0;
}
// function definitions
// calculates the area of a rectangle based on the base and height being
// passed in as integers, and returns the area as a integer
int area(int base, int height)
{
return base * height;
}
// calculate the perimeter of a rectangle based on the base and height being
// passed in as integers, and returns the perimeter as an integer
int perimeter(int base, int height)
{
return 2 * (base + height);
}
// calculates the area of a rectangle based on the base and height being
// passed in as doubles, and returns the area as a double
double area(double base, double height)
{
return base * height;
}
// calculate the perimeter of a rectangle based on the base and height being
// passed in as doubles, and returns the perimeter as an double
double perimeter(double base, double height)
{
return 2 * (base + height);
}
// calculates the area of a circle based on the radius being
// passed in as integers, and returns the area as a double
double area(int radius)
{
return PI * radius * radius;
}
// calculates the perimeter of a circle based on the radius being
// passed in as integers, and returns the perimeter as a double
double perimeter(int radius)
{
return 2 * PI * radius;
}