-
Notifications
You must be signed in to change notification settings - Fork 7
/
VectorDrills
68 lines (52 loc) · 1.36 KB
/
VectorDrills
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
// -----------------------------------------------------------------------------
// https://lptcp.blogspot.com/
// Chapter 18
/*
All Chapter 18 Vector drills
*/
// https://github.com/l-paz91/principles-practice/
// -----------------------------------------------------------------------------
//--INCLUDES--//
#include "std_lib_facilities.h"
// -----------------------------------------------------------------------------
// drill 1
vector<int> gv = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
//drill 2
void f(vector<int>& v)
{
// 3a
vector<int> lv(10);
// 3b
lv = v;
//3c
for (int i : lv)
cout << i << ", ";
cout << endl;
//3d
vector<int> lv2 = v;
// 3e
for(int i : lv2)
cout << i << ", ";
cout << endl;
}
// -----------------------------------------------------------------------------
int fac(int n)
{
return n > 1 ? n*(fac(n - 1)) : 1;
}
// -----------------------------------------------------------------------------
// drill4
int main()
{
// 4a
f(gv);
// 4b
vector<int> vv = { 1, fac(2), fac(3), fac(4), fac(5), fac(6), fac(7), fac(8), fac(9), fac(10) };
// 4c
f(vv);
keep_window_open();
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------