These came from a bank. You can see an example in Exam.pdf. Here are answers for those questions:
Part A: There are 265 ways to have 5 lower-case letters, and 104 ways to have four single numeric digits. Therefore, the answer is: (265)(104).
Part B: This is equal to the number of 6 digit numbers in base 17: (176).
Part C: 17 choose 5, plain and simple: C(17,5) or C(17,12).
Part D: This is equal to the number of permutations of the colors: (11!).
Part E: This is the power set of the juices: (212).
Grading: Three points per. You lost 0.25 points if you didn't follow the instructions, and gave me, for example (17!)/(5!12!) instead of C(17,12). I gave some partial credit, but not a huge amount.
![]() |
These came from a bank. You can see an example in Exam.pdf. Here are answers for those questions:
Part A: Since node 5's links is -1, it is the root of a set. Nodes 6, 12 and 18 link to node 5, so they are in the set. Node 8 links to 18, and node 19 links to 6, so those are also in the set. That's it. The answer is: 5 6 12 18 8 19 (They can be specified in any order).
Part B:
Part C: When we call Find(1), the links go 5, 17, 8, -1. Therefore, we change the links for 1 and 5, and their values change to 8. 17's value doesn't change.
Part B was worth 1.5 points per question.
Part C -- each node was worth 1 point and the final question was worth 1 point. You were deducted 0.5 points if you gave three nodes, and 1 point if you gave four nodes. You were deducted 2 points if you gave more than four nodes.
In the grading, if you see something like "2-19", it means that your answer was 19, and you were test #2 in the bank. Typically, you only see that on incorrect answers.
![]() |
![]() |
void binstrings(int n, int index, string &sofar)
{
if (index == n) {
cout << sofar << endl;
return;
}
sofar[index] = 'A';
binstrings(n, index+1, sofar);
sofar[index] = 'B';
binstrings(n, index+1, sofar);
}
|
Since I already resized sofar, you can simply set the characters, rather than doing push_back() and pop_back(). Doing push_back() and pop_back() is wrong because of the resizing in main().
If your grade says "See The Answer", then your program was not structured correctly.
![]() |
void enum_cd(int n)
{
int i, j, k;
for (i = 0; i < (1 << n); i++) {
for (j = 0; j < n; j++) {
if (i & (1 << j)) printf("C"); else printf("D");
}
printf("\n");
}
}
|
Here's the Div/Mod:
void enum_cd(int n)
{
int top, i, j, k;
top = (1 << n);
for (i = 0; i < top; i++) {
j = i;
for (k = 0; k < n; k++) {
printf("%c", 'C' + j%2);
j /= 2;
}
printf("\n");
}
}
|
Grading was 8 points, and I took off deductions. The most common deductions were on the div/mod enumerations, where you would div and mod by n rather than two. If your grading file says "Please see the answer", then your code didn't have the right structure for either enumeration.
![]() |
#include <string>
#include <map>
#include <vector>
#include "collection.hpp"
using namespace std;
class MyImp : public Collection { // This says it is a subclass of Collection
public:
void Add_Item(int id, const string &item); // And these implement the virtual methods
void Print();
protected:
map < int, vector <string> > Clxn; // Here's the protected data
};
|
You also need to implement Add_Data() and Print(). Add_Data() simply adds the thing to the vector in the id's map entry:
void MyImp::Add_Item(int id, const string &item)
{
Clxn[id].push_back(item); // You can be more complex, but this does everything you need.
}
|
Print is a simple nested for loop:
void MyImp::Print()
{
map <int, vector <string> >::iterator cit;
size_t i;
for (cit = Clxn.begin(); cit != Clxn.end(); cit++) {
cout << cit->first << ":";
for (i = 0; i < cit->second.size(); i++) {
cout << " " << cit->second[i];
}
cout << endl;
}
}
|
map <int, string> |
Then you lost two points for inserting the thing into the map. This is because you need to store multiple things for each id.
![]() |