forked from ulysses4ever/cs211-arrays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.cpp
67 lines (54 loc) · 981 Bytes
/
arrays.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
#include <iostream>
#include <cassert>
#include "arrays.h"
// Task 1
void task_1()
{
int n = 10;
int * a = new int [n];
}
// Task 2
void task_2()
{
int a[5] = {0};
assert(!a[4]);
}
// returns zero
int task_3_zero()
{
int a[5] {0};
assert(!a[4]);
return a[4]; // don't touch this!
}
// Task 4
void task_4()
{
int a[5]{ 1, 2, 3, 4, 5 };
assert(a[0] == 1);
assert(a[1] == 2);
assert(a[2] == 3);
assert(a[3] == 4);
assert(a[4] == 5);
}
// Task 5
void task_5_copy(int * arr1, int * arr2, int size)
{
for (int i = 0; i < size; ++i)
arr2[i] = arr1[i];
}
// Task 6
void task_6_poor_copy(int * arr1, int * arr2, int size)
{
for(int i = 0; i < size; ++i)
{
arr2[i] = arr1[i];
}
}
// Task 7
void task_7_print(const int * arr, int size, char delim)
{
for(int i = 0; i < size; ++i)
{
std::cout << arr[i] << delim;
}
}