forked from phoenixx1/Robert-Lafore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.cpp
86 lines (67 loc) · 1.68 KB
/
7.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
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
/*
Start with the power() function of Exercise 2, which works only with type double .
Create a series of overloaded functions with the same name that, in addition to double ,
also work with types char , int , long , and float . Write a main() program that exercises
these overloaded functions with all argument types.
*/
//author @Nishant
#include <iostream>
using namespace std;
double power(double, int=2);
char power(char, int=2);
int power(int, int=2);
long power(long, int=2);
float power(float, int=2);
int main(){
double num1;
char num2;
int num3;
long num4;
float num5;
cout << "Enter a double value: ";
cin >>num1;
cout << "Power of " << num1 << " is: " <<power(num1) << endl;
cout << "\nEnter a char value: ";
cin >>num2;
cout << "Power of " << num2 << " is: " << power(num2) << endl;
cout << "\nEnter a int value: ";
cin >> num3;
cout << "Power of " << num3 << " is: " << power(num3) << endl;
cout << "\nEnter a long value: ";
cin >> num4;
cout << "Power of " << num4 << " is: " << power(num4) << endl;
cout << "\nEnter a float value: ";
cin >> num5;
cout << "Power of " << num5 << " is: " << power(num5) << endl;
return 0;
}
double power(double dd, int p) {
double power = 1;
for(int i=1; i<=p; i++)
power *= dd;
return power;
}
char power(char ch, int p) {
char power = 1;
for(int i=1; i<=p; i++)
power *= ch;
return power;
}
int power(int no1, int p) {
int power = 1;
for(int i=1; i<=p; i++)
power *= no1;
return power;
}
long power(long numb, int p) {
long power = 1;
for (int i=1; i<=p; i++)
power *= numb;
return power;
}
float power(float number, int p) {
float power = 1.0;
for (int i=1; i<=p; i++)
power *= number;
return power;
}