![]() |
.. (לתיקייה המכילה) | |
Can we use our implementation of a linked list from Homework 2 ? | |
You should definitely not, for the simple reason it is written in C, not C++. (even though it might compile as C++, it's still not using C++'s new concepts) |
BigInt and Map: what Standard Library classes can we use? | |
None. In particular, you may not use std::string, std::list, std::vector and so on. An exception to this is ostream. |
Hint for Question 1 in the dry part: | |
Solving this question requires a small piece of knowledge from Tutorial 12: Regardless of whether a class is a template or not, you can define templated methods in it:
Here, we define the method C::f<T>(const T& t). |
Can a | |
Yes, in which case the leading zeros should be ignored. |
When iterating over a | |
There is no requirement on the order. You can return the items in whichever order you wish, so long as all items are accessed exactly once. |
Errata: In the wet part, in Map, you should assume the type V (Value) has a default constructor, as well as an assignment operator (operator=). | |
. |
Can we assume the number of digits of our BigInt can be represented as | |
Yes. |
Should we allow for the following code to compile ? | |
You can assume an iterator will only be created through begin/end. |
In 3.2.1, the "find" operation is said to return a value, while according to the example file it returns an iterator. Which is the correct one ? | |
In code, find() should return an iterator. |
Question 2.2 - when doing | |
Yes - your output should be the same as if it was passed to cout .
|
Can we use | |
Yes. Anything which is not an STL class. |
Can we perform multiplications in | |
As we said in the exercise, you should use long-multiplication. Using something simpler might lead to an algorithm whose running time is proportional to the size of the number. This means that computing a 30-digit number on a modern computer will take about 10^20 seconds, which is around a 1000 times more than the age of the universe. The auto-checker might give up... |
Map: can we assume KeyType has a default ctor ? | |
No. Please make sure your code compiles with such type. |
Shake: one of the nouns is "summer's day". What should we do with it? | |
You can ignore this expression, it will not be used. |
Question 2.2 (DebugStream) - the macro says | |
Yes. It should be DebugStream in the macro.
|
Shake: if a result is negative, what should be the state of the stack? | |
Untouched. That is, if the command is Romeo : Angel Angel Beautiful Without you should print that the result is negative, and the stack should still contain two numbers :
|
What is | |
You should look for references for this class on the internet. One such resource is http://www.cplusplus.com/reference/iostream/ostringstream/ |
Shake: Where should we print errors to? cerr? | |
You should send all of the output/errors of Shake to the same place. |
Shake: Is the following command legal? "<variable name> : bla bla bla bla bla sjhaklehja dajsldjaklsjd sadkjakld speak" ? | |
You can assume that if "speak" is not the third word in a line, it will not appear at all. |
Shake: can "speak" appear more than once in one line ? | |
No, you can assume it will appear at most once. |
BigInt: BigInt(12) and BigInt(012) return different numbers; is it ok ? | |
Yes; 012, in C/C++, is treated as an octal number, and actually equals 10 in decimal. You can ignore it, and in fact, you can't do anything about it - because in the code itself, you have no way to know if the number was prefixed with 0 or not. |
BigInt: what should we do with | |
You may assume we will not initialize a BigInt with a negative number. |
Is there a way to know the size of a C-style array ? | |
sizeof(name of array)/sizeof(type of elements in array) Note that this only works for arrays, not arrays which were converted to pointers (such as what happens when you pass an array to a function) |
Map: should we define an operator[] for const maps ? | |
No, you don't have to. |
BigInt: What should the following do, BigInt b("+1") ? Same question for BigInt b(""). | |
Throw an exception, in both cases. |
Shake: if an error occurs (.e.g, a result is negative) should we keep on executing commands from the rest of the line ? | |
Yes. So, if the program is
You should print an error, and then 3. |