Here is the distribution of the scores, along with my assignment of grades to scores. Please see https://web.eecs.utk.edu/~jplank/General-Teaching/Final_Grades.html for explanation on how exam grades are incorporated into the final grade.
The exam was on Canvas, and I used question banks for a lot of questions, so I won't have the exact exam here, but I will describe it:
The answer is that an interface defines the prototypes of methods that a class may implement. If a class implements those, then the class may "belong" to the interface, and then one may program with an instance of the interface, and it will work with all classes that belong to the interface.
The interface does not define common variables -- that is inheritance, and if you said such, you were penalized for it. I also penalized vagueness ("interfaces allow you to group together like classes and they simplify code").
The answer to this question is 12.
The answer to this question is 7.
The answer to this question is 9.
The answer here is that links[6] is set to 16, and that sizes[16] is set to 11.
The answer to this question is "23 23 9 9".
This is a map question. For all of the ages < 80, you need a map keyed on an integer (the age), whose val is a multiset of names. You print it with a nested traversal -- the outer loop loops over the ages and the inner loop loops over the names.
You have to treat values >= 0 differently. Either you have to have a separate multiset for them, or you can simply set any age ≥ 80 to 80. The code below does the former approach:
#include <map> #include <set> #include <iostream> using namespace std; int main() { int age; string name; map <int, multiset <string> > u80; map <int, multiset <string> >::iterator uit; multiset <string> o80; multiset <string>::iterator oit; while (cin >> age >> name) { if (age < 80) { u80[age].insert(name); } else { o80.insert(name); } } for (uit = u80.begin(); uit != u80.end(); uit++) { for (oit = uit->second.begin(); oit != uit->second.end(); oit++) cout << *oit << endl; } for (oit = o80.begin(); oit != o80.end(); oit++) cout << *oit << endl; return 0; } |
A lot of the points in grading this question came from your choice of a data structure. If you simply had a map whose key was an integer and whose val was a string, you lost roughly 8 points, because you lose names when you insert duplicate ages into the map. You lost more points if you chose to store things in a vector, and then to have O(n2) code to traverse the vector and print things out.
We went over code like this in class with the ThreeTeleports question. It's just like the regular permutation code, except you check to see if the last element is the "ending" element, and if it is, you print it out and return. This is as opposed to only printing the vector when index is v.size():
#include <iostream> #include <vector> using namespace std; void permute(vector <int> &v, int index, int terminate) { size_t i, j; int tmp; for (i = index; i < v.size(); i++) { tmp = v[i]; v[i] = v[index]; v[index] = tmp; if (v[index] == terminate) { for (j = 0; j <= index; j++) cout << " " << v[j]; cout << endl; } else { permute(v, index+1, terminate); } tmp = v[i]; v[i] = v[index]; v[index] = tmp; } } int main() { size_t i; int val; vector <int> v; while (cin >> val) v.push_back(val); if (v.size() == 0) return 0; permute(v, 0, v[v.size()-1]); return 0; } |