The Art of Shitposting
The Art of Shitposting
The Art of Shitposting
2020 Spring
Read this page thoroughly.
You are about to take an exam. The purpose of the exam is to fairly and accurately measure your knowledge
and skill in this course’s material.
● The exam must represent your work alone. You may not misrepresent anyone else’s work as your own.
You may not submit work of which you are not the sole author.
● The exam is to be completed in isolation. During the exam, you may not communicate with any other
person for any reason. This prohibition includes the use of electronic communication, such as email,
texting and phone.
● The exam is to be completed without additional resources. You must formulate your answers based only
on the contents of your brain. Specifically:
○ Do not use the internet.
○ Do not use other software on your computer, such as IDE, compiler, interpreter or debugger.
○ Do not consult written notes.
○ Do not consult other files on your computer, including other work you’ve completed for this
course.
○ Do not consult books.
● Do not copy or distribute the exam document or your answers at any time. After you submit your
answers delete the exam and your answers from your own computer.
How to take the exam Before starting, make sure that you are in a quiet place where you can work without
interruption. To avoid distraction, please turn off your phone before starting the exam. You will not need any
materials beside your computer and a reliable internet connection. Make sure your computer is sufficiently
charged or plugged in to a power source. In addition you may want to have some scrap paper and a pen or
pencil.
Download the file exam.txt and open it in your text editor. Enter your name and NYU NetID at the beginning
of the file. At the section “Affirmation” enter the following text exactly as it appears, substituting your name.
Without a typed affirmation, your exam will not be graded.
Enter all of your exam answers into exam.txt at the appropriate places. You will have 80 minutes to complete
the exam. At the end of that period, you will have a five minute window to upload your completed exam to NYU
Classes. After that time no work will be accepted.
You may upload as many times as you like. The last one before the deadline is what will be graded.
You also do not need to write any comments in any of your code.
Please, read all questions carefully! They may look familiar and yet be completely different.
Answering the short-answer questions, in particular, requires that you read and understand
the programs shown. You need to read them carefully if you are going to understand them.
If a question asks you to write a class or a function and provides you with test code, be sure
your class / function works with that test code. If the question provides you with sample
output, then your answer should match that output.
Questions Points
1 xtra
2-6 5
7-8 6
9 8
10 16
11 39
a. Callahan f. Stroustrup
b. Gosling g. Thompson
c. Hopper h. van Rossum
d. Ritchie i. Wall
e. Sterling j. None of the above
Thing thingOne;
What is the result of compiling and running the above code? (Circle only one answer)
a. The program will have a compilation f. The program will print out: 17 17
error at line A
g. The program will print out: 17 42
b. The program will have a compilation
h. The program will print out: 42 17
error at line B
i. The program will print out: 42 42
c. The program will have a compilation
error at line C j. The program will print out: 17 28
d. The program will have a compilation k. The program will print out: 42 28
error at line D
l. All of the above
e. The program will have a runtime
m. None of the above.
error (or undefined behavior) at line
D.
vector<int> things;
Later in the program you want to use a ranged for (also known as the “foreach”), to double the
value of each item in the vector things. Write that loop:
Output:
class Dragon {
public:
Dragon(string s) : s(s) {}
// ... possibly other methods
private:
string s;
// ... possibly other fields
};
class Falcon {
public:
Falcon(string s) : name(s), p(new Dragon(s)) {}
~Falcon() { delete p; }
private:
Dragon* p;
string name;
};
Implement an appropriate assignment operator, i.e. a deep copy, for the class Falcon. Write it
below. And yes, the class Dragon supports copy control.
__________________________________________________________________
b) Fill the array from part (a) with addresses of 100 Things that you allocate on the heap.
Each Thing will have its val field hold a value from 1 to 100. i.e. the first Thing will hold 1,
the second 2, ...
__________________________________________________________________
c) Now, modify those values by adding the index of the entry to the value that was stored in
the Thing, e.g. add 17 to the val field of the Thing pointed to by data[17].
__________________________________________________________________
d) Finally, free up all of the space that you allocated on the heap. Do not leave any dangling
pointers.
__________________________________________________________________
struct Thing {
vector<int> stuff;
};
write the following two functions,
fill: fills a vector of Things with data from a file stream.
Each Thing is represented by a single line in the file.
The first item in the line is the number of ints that the Thing will hold.
The rest of the line has that many ints.
Example file:
3 2 6 4
2 18 12
Put the ints that show up on a single line into the vector in a Thing object. There should
be one Thing object for each line in the file.
Note the stream is already open, so you don't have to worry about that. And we are
closing it for you, so you don’t have to worry about that either.
totalStuff:
Passed a vector of Things. Computes and returns a single int which is the total of all
the ints in all of Things in the vector.
For the above sample input file the function would return the sum 2+6+4+18+12
(so I think the answer is 42).
Below is an example program in which fill and totalStuff are called from main.
Note that neither of the functions fill or totalStuff are methods.
Do not modify the Thing struct.
Note the output. Your output operator should generate the output as shown, except possibly
for the order of the Bits in a group. (Remember, we don't care about order.)
And finally, no, this problem does not involve copy control or the heap.
And even more finally, again note that people’s names are not unique!!! Just knowing
someone’s name won’t be very useful.
Output: