-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example2.cpp
57 lines (48 loc) · 1.06 KB
/
Example2.cpp
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
/**
* @file Example2.cpp
*
* @brief C++ Program to return absolute value of variable types
* integer and float using function overloading.
*
* @author Saif Ullah Ijaz
*
*/
#include <iostream>
using namespace std;
// FUNCTION PROTOTYPE (DECLARATION)
/** function that returns absoulte of an integer.
*
* @param var The integer number to find absolute.
*
* @return absolute value of the integer input.
*/
int absolute(int);
/**
# @overload float absolute(float);
*/
float absolute(float);
// function main begins program execution
int main() {
int a = -5;
float b = 5.5;
cout << "Absolute value of " << a << " = " << absolute(a) << endl;
cout << "Absolute value of " << b << " = " << absolute(b) << endl;
system("pause");
return 0;
}
// end main
// FUNCTION DEFINITION
// takes integer as input
int absolute(int var) {
if (var < 0)
var = -var;
return var;
}
// end function absolute
// takes float as input
float absolute(float var) {
if (var < 0.0)
var = -var;
return var;
}
// end function absolute