forked from Jkatzeff/Mackey-word-dump-comparer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.txt
316 lines (220 loc) · 12.8 KB
/
output.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Matching questions with at least 0.6 in common.
Question 2 on Free Response on cse111-2020q1-final.tt with accuracy 0.6888888888888889:
Write a main function that reads in strings using cin>>word for
each word, and at end of file, prints out all of the words in
lexicographic order followed by a count of the number of times
they occur. Use an appropriate data structure from the library.
[2pt]
Question 3 on Free Response on cse111-2020q1-final.tt with accuracy 0.66:
Define the template function minmax, whose arguments are a pair of
forward iterators pointing at numbers of type double. Its result
is a pair<double,double>, such that the first field is the minimum
element and the second field is the maximum. Return pair(NAN,NAN)
if the range is empty. (NAN is a macro in <cmath>). [3pt]
Question 5 on Free Response on cse111-2020q1-final.tt with accuracy 0.625:
Define the template operator<< whose second argument is a pair
representing a range. It prints out the elements of the range
with an open brace ({) at the beginning and a close brace at the
end (}) and with a comma and space between each element. The
iterators may point at anything for which operator<< is defined.
[3pt] For example:
vector<int> v {1,2,3,4,5};
cout << pair (v.begin(), v.end()) << endl;
will print:
{1, 2, 3, 4, 5}
Question 8 on Free Response on cse111-2020q1-final.tt with accuracy 0.7205882352941176:
Write a complete function readpipe. It opens a pipe to read from
the command given as its argument, and throws a runtime_error if
the pipe can not be opened. If the popen is successful, it uses a
buffer to read from the pipe, and each buffer read is appended to
a string, which is then returned as the value of the function.
[4pt]
string readpipe (const string& command) {
string result;
char buffer[1000];
Question 9 on Free Response on cse111-2020q1-final.tt with accuracy 0.7323943661971831:
Define the template function merge, with a return type of void.
It has three template arguments: InputItor1, InputItor2,
OutputItor. It has five functional arguments: begin and end
input itor1 arguments for the first input type, begin and end
input itor2 arguments for the second input type, and a begin
output itor. Merge the two input ranges into the output range.
Use operator< to compare elements, and assume the input ranges are
already sorted into ascending order. [4pt]
Question 10 on Free Response on cse111-2020q1-final.tt with accuracy 0.6379310344827587:
Define equal, which takes two pairs of iterators and returns true
if and only if the elements of the ranges given are equal, and the
lengths of the ranges are equal. Assume only input iterators:
You may not use size() or subtract iterators. Assume operator==
is defined on the elements of the ranges. [2pt]
template <typename itor>
bool equal (itor begin1, itor end1, itor begin2, itor end2) {
Question 1 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6818181818181818:
Write the prototypes (but not the function bodies) as they would
appear in the header file for the definition of class foo for all
of the class members which would otherwise be implicitly
generated. [2pt]
+----------------+
|Scoring: | class foo {
|6 correct: 2 * | public:
|5 correct: 1½ * |
|4 correct: 1 * |
|3 correct: ½ * |
|else: 0 * |
+----------------+
Question 2 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.75:
Write a function distance which counts the number of elements in a
range. Do not assume the iterator supports operator-. It is at
most a forward iterator. The function will use a loop and run in
$ O ( n ) $ time. [2pt]
template <typename iterator>
size_t distance (iterator begin, iterator end) {
Question 3 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6190476190476191:
Write a function average which returns the average of a sequence
of numbers. Assume the iterators point at things which are
doubles or which can be implicitly converted to doubles. Assume
only a forward iterator. [2pt]
template <typename iterator>
double average (iterator begin, iterator end) {
Question 4 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.7419354838709677:
Write a function has. Its first argument is a vector<int> and its
second argument is an int. It returns true only if the int occurs
somewhere in the vector, and false otherwise. [2pt]
Question 5 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6060606060606061:
The function find returns the position of the first occurrence of
n in vec. Make the standard assumption for what to do in the case
of not found. [2pt]
vector<int>::const_iterator find (const vector<int>& vec, int n) {
Question 7 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.72:
Define the unary member function bigint::operator- as it would
appear in bigint.cpp. Reminder: some declarations are listed
here: [1pt]
private:
ubigint uvalue;
bool is_negative {false};
public:
bigint (const ubigint&,
bool is_negative = false);
Question 8 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6153846153846154:
Assume that foo& foo::operator+= (const foo&) has been defined as
a class member. Write the body of the non-member operator+ that
adds two values of class foo and returns a foo. [2pt]
Question 10 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6835443037974683:
Write a function is_sorted which returns true if the range is
sorted into ascending order according to the comparison function.
The expression decltype(*iterator()) is the type of what the
iterator points at. A call to less(a,b) will return true if a
should be considered less than b. The sequences {3,9,11,21}, {4},
and {} would all be considered sorted for less<int>, but the
sequences {5,1,2,8} and {5,9,9,11,11} would not. But
{5,9,9,11,11} is sorted if less_equal<int> is used. Use less for
comparison, not operator<. [3pt]
template <typename iterator,
typename less_t = less_equal<decltype(*iterator())>>
bool is_sorted (iterator begin, iterator end, less_t less = less_t()) {
Question 12 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.7586206896551724:
Define the necessaary functions for class container and class
container::iterator so that the following for-loop can be
compiled. Show prototypes only, not complete bodies.
container cont; for (const auto& i: cont) f(i);
+-------------------------------+-------------------------------+
|template <typename T> |template <typename T> |
|class container { // [1pt] |class container::iterator { |
| |// [1pt] |
| | |
| | |
| | |
| | |
| | |
| | |
+-------------------------------+-------------------------------+
Question 13 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.7671232876712328:
Write the complete template function copy. It has two template
parameters: (1) an input iterator, (2) an output iterator. It
has three function parameters: (1) a begin input iterator, (2) an
end input iterator, and (3) a begin output iterator. All elements
from the input range are copied into the output range. It is
assumed that the output iterator is large enough to hold the input
range, and may be a back inserter. [2pt]
Question 14 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.7346938775510204:
Define the function copy_if which copies an input range to an
output range, but only copies those elements for which the
predicate is true. Again, assume the output range is large
enough. An example call might be: [2pt] copy_if (vi.begin(), vi.
end(), back_inserter(out), [](int i){ return i > 0; });
template <typename in_itor, typename out_itor, typename predicate>
void copy_if (in_itor begin, in_itor end, out_itor out, predicate ok) {
Question 15 on Free Response on cse111-2020q1-midterm.tt with accuracy 0.6346153846153846:
Define the template class queue. It has the public functions
push_back, pop_front, front (in both the constant and non-constant
versions), size, and empty. It has a private field of the
template class std::deque. Code each function inline with a
direct call to the corresponding std::deque function. Note:
deque has all of these functions with the same names. [3pt]
Question 4 on Multiple Choice part 1 on cse111-2020q1-midterm.tt with accuracy 0.7142857142857143:
Given an iterator i, What is the preferred (probably most
efficient) way of incrementing it in the third part of a for-loop,
and which will work for all iterators, as in
for (i = v.begin(); i != v.end; ___)
(A) i=i+1
(B) i+=1
(C) i++
(D) ++i
Question 7 on Multiple Choice part 1 on cse111-2020q1-midterm.tt with accuracy 0.6923076923076923:
Inside a virtual member function of class foo, what is the type of
this?
(A) foo
(B) foo&
(C) foo&&
(D) foo*
Question 2 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.7272727272727273:
Write a function called sum. It has a single template argument of
iterator type. It has two function arguments of that iterator
type indicating the begin and the end of a range. Sum returns a
double which is the sum of all elements in the range. Assume the
iterators point at elements of type double, or whatever can be
implicitly converted too type double. Code your solution as a
loop using the two-semicolon version of the for loop. [4pt]
Question 3 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.7012987012987013:
Write a template function is_monotonic. The template type
argument is an iterator type. It has two function arguments,
begin and end, of that iterator type. It returns a bool value
which is true if and only if the sequence is sorted in
monotonically increasing order. Assume the elements pointed at by
the iterators have operator< defined for them as the comparison
operator. E.g., {1,2,6,99} and {3,6,8,42} are monotonic, but
neither {3,5,5,7} nor {5,2,8,7} are. Monotonic means every number
is larger than the preceding one. [4pt]
Question 4 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.65625:
Write a function reverse whose argument is a vector<int>. E.g.,
the reverse of {1,3,5,7,9} is {9,7,5,3,1}. It must work for an
empty vector, and also for an even or odd number of elements in
the vector. [4pt]
Question 7 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.6333333333333333:
Indicate, using big-O notation, the amount of time it takes to
find an arbitrary element in each of: vector, unordered_map, map,
list. For each of map and unordered_map, what is the underlying
data structure? [4pt]
Question 8 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.7058823529411765:
Code a template operator<< which takes any kind of a vector and
prints out the contents of the vector in the order v[0], v[1],
v[2], ..., to the end. Assume operator<< is defined for the
elements of the vector. Print exactly one space between vector
elements, but no space before the first or after the last element.
[4pt]
Question 9 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.7857142857142857:
Given that ubigint has a field called vector<unsigned char>
ubigvalue, code the non-const function ubigint::multiply_by_2,
which modifies ubigvalue. [4pt]
Question 10 on Free Response on cse111-2020q4-midterm.tt with accuracy 0.82:
Define the function find_if whose template
arguments are an iterator type and a predicate
type and whose function arguments are a pair of
iterators indicating a range and a boolean function
or function object. Return an iterator pointing at
the first element in the range for which the predicate
returns true. [4pt]
SCORE-TOTAL=40
Question 4 on Multiple Choice part 1 on multiple-choice.txt with accuracy 0.6428571428571429:
You are certain which three answers are wrong and which one
is correct. Obviously you answer.