Assignment 2 FAQ
FAQ assembled by Marty Stepp.
- Q: Can I work with a partner on this assignment?
A: Yes! This is a pair assignment. You can also choose to work individually. If you work in a pair, submit only a single copy of your solution, not two.
- Q: Is it okay if my partner does Part A, and I do Part B?
A: We do not recommend that. You're both responsible for knowing and understanding all of the material covered by this assignment. You are much less likely to understand the material if you didn't practice it. We highly recommend that you sit together with your partner to do the work for both parts. Another style that works well is to each write code for both parts separately, then meet together to compare them and produce a best solution that is a mix of the two.
- Q: How do I construct a compound collection? It doesn't compile.
A: You may need a space between nested
<>(requirement for the space was supposed to end with C++11, but some compilers still require it).Vector<Vector<int>> foo; // no Vector<Vector<int> > foo; // yes-
Q: Why can't I make a nested collection that is a
SetorMapof other collections? AKA, why am I getting this error?no match for 'operator<' (operand types are '.... A: In order for an element to go into a
SetorMap, it must have some kind of ordering so that theSet/Mapcan sort them into order. Collections likeVectorsorStacksdon't have a sorting to them, so they can't be put into aSetor used as a key in aMap. If you want this kind of nesting, you could use aHashSetorHashMap.- Q: When I try to construct my compound collection, it gives a strange compiler error about "no match for 'operator <'." What is that?
A: If you use a collection that tries to arrange their elements or keys into order, it needs to be able to compare the elements to each other. It uses the standard relational operators such as
<to do this. So you can't store an element type that doesn't have a<operator and therefore cannot be ordered. Choose a different type of compound collection.-
Q: In Part A, am I allowed to use a
Lexicon? A: Yes, though you are not required to do so.
- Q: In Part A, why is my program veeeeeeery slow?
A: Usually this happens for one of two reasons: Either you have chosen the wrong data structure somewhere, or you have not properly followed the pseudocode algorithm we have you. A common bug is that students will loop over the entire dictionary to look for words. You should not need to do that. The purpose of the dictionary is to look up words, to test whether something is a valid word or not; not to loop over. If you want to loop over all possible "neighbor" words that are one letter away from a given word, do this by looping over the indexes of the string and over the letters a-z, as described in the pseudocode; not by looping over the dictionary.
- Q: In Part A, why does my program spit out a VERY long (20-30+ word) ladder even for simple cases?
A: Maybe you're accidentally adding words to an existing collection rather than making a copy of it and adding to the copy. Run with a very small input, then print out your collections along the way and make sure everything is what you expect.
- Q: In Part B, how do I get a random number?
A:
#include "random.h" ... int r = randomInteger(min, max); // inclusive- Q: In Part B, how do I get a random element of a collection?
A: If it's an indexed collection, such as a
Vector, just pick a random index and then go access that index. If it doesn't have indexes, like a set or queue, pick a random index based on the size, and then advance forward (e.g. in aforeachorwhileloop) that many times and grab the element found there.- Q: Do I have to use the exact collections the spec says to use? I want to use a different one.
A: Follow the spec.
- Q: I can't see this assignment in the list of assignments to turn in. How do I turn in the assignment?
A: Try opening an Incognito Tab and opening the Paperless system in that tab. Did the assignment show up?
- Q: When I try to turn in the myinput.txt file, the system doesn't display it. Did the turnin system accept my file?
A: Check the page that displays information about your past submission. Do you see myinput.txt there? If so, we received it successfully. If not, you may need to submit again. Sometimes this issue comes from the input file being very large (over ~2mb).
- Q: Can I use one of the STL containers from the C++ standard library?
A: No.
- Q: I already know a lot of C/C++ from my previous programming experience. Can I use advanced features, such as pointers, on this assignment?
A: No; you should limit yourself to using the material that was taught in class so far.
- Q: Can I add any other files to the program? Can I add some classes to the program?
A: No; you should limit yourself to the files and functions in the spec.
-
Q: In Part B, what should go in my
myinput.txtfile? A: Copy/paste a fun source of text from the web. For example, grab lyrics from your favorite band, or text of a book or movie script you like, or just make up any text you want.