-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespace.cpp
More file actions
67 lines (58 loc) · 1.37 KB
/
namespace.cpp
File metadata and controls
67 lines (58 loc) · 1.37 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
/*
*namespace.cpp
*/
#include<iostream>
using namespace std;
namespace calc{
void Min(int * a, int n, int & _min);
void Max(in t* a, int n, int & _max);
void Avg(int * a, inta n, );
namespace test{
void myfunc();
};
};
void calc::test:myfunction(){
//...
}
// these functions do not return any value because they act on a pointer
void calc::Min(int * a, int n, int & _min){// int & _min is a pointer to integers
_min = a[0];
for(int i = 1; i < n; i++){
if(a[i] < _min)
_min = a[i];
}
}
void calc::Max(int * a, int n, int & _max){ // int & _ max is a pointer to integers
_max = a[0];
for(int i=0; i < n; i++){
if(a[i] > _max)
_max = a[i];
}
}
void calc::Avg(int * a, int n, flaot & _avg){
float sum = 0;
for(int i=0; i < n; i++){
sum += a[i];
}
_avg = sum / n;
}
int main(int argc, char ** argv){
cout << "Insert array size: ";
int n;
cin >> n;
int * array = new int[n];
for(int i=0; i < n; i++){
cout << "Insert element " << i << ":";
cin >> array[i];
}
int MAX, MIN;
float AVG;
calc::Max(array, n, MAX);
calc::MiN(array, n, MIN);
calc::Avg(array, n, AVG);
cout << "Max is " << MAX << endl;
cout << "Min is " << MIN << endl;
cout << "Mean is " << AVG << endl;
delete [] array;
return 0;
}