forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaultargs.cpp
More file actions
40 lines (33 loc) · 906 Bytes
/
Copy pathdefaultargs.cpp
File metadata and controls
40 lines (33 loc) · 906 Bytes
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
// Default argument example
#include<iostream>
using namespace std;
// Print a list of numbers (start to end by step).
void iterate(int start, int end, int step=1, int columns=5)
{
int count = 1; // to keep track of # of columns
for (int ii=start; ii <= end; ii += step)
{
cout << ii << "\t";
if ( (count % columns) == 0) {
cout << endl;
}
count ++;
}
cout << endl;
}
int main ()
{
// Call iterate with 4 parameters (columns=8)
cout << endl;
cout << "iterate(1,40,1,8)" << endl;
iterate(1,40,1,8);
// Call iterate with 3 parameters (use default column value)
cout << endl;
cout << "iterate(1,200,10)" << endl;
iterate(1,200,10);
// Call iterate with 2 parameters (use the default step & column values)
cout << endl;
cout << "iterate(1,50)" << endl;
iterate(1,50);
return 0;
}