-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathB05-dynarray.html
138 lines (119 loc) · 6.86 KB
/
B05-dynarray.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Bonus 05: Dynamic Array</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
</style>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
</head>
<body>
<h1 id="bonus-05-dynamic-array">Bonus 05: Dynamic Array</h1>
<p>For this assignment you will be implementing a Dynamic Array capable of accepting any primitive type.</p>
<h2 id="the-header">The Header</h2>
<pre><code class="language-c++"><div><span class="hljs-meta">#<span class="hljs-meta-keyword">pragma</span> once</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><memory></span></span>
<span class="hljs-keyword">template</span> <<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">T</span>> <span class="hljs-title">class</span> <span class="hljs-title">Vec</span> {</span>
<span class="hljs-keyword">public</span>:
<span class="hljs-keyword">typedef</span> T* iterator;
<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">const</span> T* const_iterator;
<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">size_t</span> size_type;
<span class="hljs-keyword">typedef</span> T value_type;
Vec();
<span class="hljs-function"><span class="hljs-keyword">explicit</span> <span class="hljs-title">Vec</span><span class="hljs-params">(size_type n, <span class="hljs-keyword">const</span> T& t = T())</span></span>;
Vec(<span class="hljs-keyword">const</span> Vec& v);
Vec& <span class="hljs-keyword">operator</span>=(<span class="hljs-keyword">const</span> Vec&);
~Vec()
T& <span class="hljs-keyword">operator</span>[](size_type i)
<span class="hljs-keyword">const</span> T& <span class="hljs-keyword">operator</span>[](size_type i) <span class="hljs-keyword">const</span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">push_back</span><span class="hljs-params">(<span class="hljs-keyword">const</span> T& t)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">push_front</span><span class="hljs-params">(<span class="hljs-keyword">const</span> T& t)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">const</span> T <span class="hljs-title">pop_back</span><span class="hljs-params">()</span></span>;
<span class="hljs-function"><span class="hljs-keyword">const</span> T <span class="hljs-title">pop_front</span><span class="hljs-params">()</span></span>;
<span class="hljs-function">size_type <span class="hljs-title">size</span><span class="hljs-params">()</span> <span class="hljs-keyword">const</span></span>;
<span class="hljs-comment">// Iterators</span>
<span class="hljs-function">iterator <span class="hljs-title">begin</span><span class="hljs-params">()</span></span>;
<span class="hljs-function">const_iterator <span class="hljs-title">begin</span><span class="hljs-params">()</span></span>;
<span class="hljs-function">iterator <span class="hljs-title">end</span><span class="hljs-params">()</span></span>;
<span class="hljs-function">const_iterator <span class="hljs-title">end</span><span class="hljs-params">()</span> <span class="hljs-keyword">const</span></span>;
<span class="hljs-comment">// Clear the vector</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">clear</span><span class="hljs-params">()</span></span>;
<span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">empty</span><span class="hljs-params">()</span> <span class="hljs-keyword">const</span></span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">erase</span><span class="hljs-params">(iterator position)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">remove</span><span class="hljs-params">(<span class="hljs-keyword">const</span> T& t)</span></span>;
<span class="hljs-keyword">private</span>:
iterator data;
iterator size;
iterator capacity;
<span class="hljs-comment">// facilities for memory allocation</span>
<span class="hljs-built_in">std</span>::allocator<T> alloc;
};
</div></code></pre>
<h2 id="instructions">Instructions</h2>
<p>This assignment will be hosted on Github Classroom.</p>
<ol>
<li>Register for the assignment on our Github Classroom using <a href="https://classroom.github.com/a/veyFoobr">this link</a></li>
<li>Clone the repository to your machine
<ol>
<li>Open a terminal</li>
<li>Navigate to your algorithms folder</li>
<li>Go to the parent directory (<code>cd ..</code>)</li>
<li>Clone the repository to this location (<code>git clone <your repository link here></code>)</li>
</ol>
</li>
<li>Getting things in order
<ol>
<li>Open your new folder in VS Code</li>
</ol>
</li>
<li>Implement a Generic Dynamic Array <strong>Commit and Push your work after each task</strong>
<ol>
<li>Create the folder necessary to complete the class (<code>Array</code>)</li>
<li>Create and populate the header file <code>Array.hpp</code> (Copy and paste the header content from above)</li>
<li>Create the unit tests file <code>Array.test.cpp</code> (Refer to other test files for guidance)</li>
<li>Create the source file <code>Array.cpp</code></li>
<li>Populate the source file with all the requisite methods</li>
<li>Repeat the following steps, committing and pushing after each cycle
<ol>
<li>Select a method to implement</li>
<li>Write a unit test for that method</li>
<li>Implement the method such that it passes your unit tests, adding additional tests along the way as you think of new possible scenarios</li>
</ol>
</li>
</ol>
</li>
<li>Submit your work (<code>git add . && git commit -m "Done" && git push</code></li>
</ol>
<h2 id="grading">Grading</h2>
<table>
<thead>
<tr>
<th>Criteria</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<tr>
<td>Functional Correctness</td>
<td>90</td>
</tr>
<tr>
<td>Quality</td>
<td>10</td>
</tr>
</tbody>
</table>
<h2 id="submission">Submission</h2>
<p>Submissions are handled by Github Classroom.
Submissions after the deadline are not graded.</p>
</body>
</html>