-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq3-extracredit.cpp
35 lines (27 loc) · 961 Bytes
/
q3-extracredit.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
#include <iostream>
using namespace std;
float sumOfSquares(float x, float y, float z) {
float sum1=0;
sum1= (x * x + y * y + z * z);
return sum1;
}
const float& sumOfSquaresRef(const float& x, const float& y, const float& z) {
static float sum2;
sum2 = x * x + y * y + z * z;
return sum2;
}
const float* sumOfSquaresP(const float* x, const float* y, const float* z) {
static float sum3;
sum3 = (*x) * (*x) + (*y) * (*y) + (*z) * (*z);
return &sum3;
}
int main() {
float x = 9.8, y = 1.2, z = 2.3, result;
result = sumOfSquares(x, y, z);
cout << " The value of sumOfSquares in the first case is: " << result << endl;
result = sumOfSquaresRef(x, y, z);
cout << " The value of sumOfSquaresRef by reference is: " << result << endl;
result = *sumOfSquaresP(&x, &y, &z);
cout << "The value of sumOfSquaresP by pointers is: " << result << endl;
return 0;
}