#include <vector> #include <string> class Animal { public: Animal(); Animal(const Animal &a); void ggg(std::string x, std::string &y) const; void ggg(int &i) const; void hhh(std::string x, const std::string &y); void iii(const int &i); std::string tiger; protected: int lion; std::string jaguar; }; |
And the following is in the file Animaltest.cpp:
#include <vector> #include <iostream> #include "Animal.hpp" using namespace std; int main() { Animal a1, a2, a3, a4; vector <Animal> av; string s1, t1, s2, t2; int i1, i2; i1 = 75; i2 = 85; s1 = "simba"; t1 = "tony"; s2 = "jaba"; t2 = "speedy"; a1.tiger = "sherekhan"; a2 = a1; a3.tiger = "speedy"; a4.tiger = "hangry"; av.resize(1); av.at(0).tiger = "lazy"; av.resize(4, a3); a1.ggg(s1, t1); a2.ggg(i1); a3.hhh(s2, t2); a4.iii(i2); } |
Now, suppose that a friend has implemented all of the methods defined in Animal.hpp in the file Animal.cpp. Please answer the following questions. Every answer should be one word. For parts D through O, if there can be multiple answers, then answer multiple If the answer is the empty string, then answer empty.
A. Animal is a class that exhibits polymorphism. Please answer T or F: [A]
B. Animal defines a customized copy constructor. Please answer T or F: [B]
C. Animal defines a customized assignment overload. Please answer T or F: [C]
D. Please tell me the value of s1 just before main() returns: [D]
E. Please tell me the value of s2 just before main() returns: [E]
F. Please tell me the value of t1 just before main() returns: [F]
G. Please tell me the value of t2 just before main() returns: [G]
H. Please tell me the value of i1 just before main() returns: [H]
I. Please tell me the value of i2 just before main() returns: [I]
J. Please tell me the value of a1.tiger just before main() returns: [J]
K. Please tell me the value of a2.tiger just before main() returns: [K]
L. Please tell me the value of a3.tiger just before main() returns: [L]
M. Please tell me the value of a4.tiger just before main() returns: [M]
N. Please tell me the value of av.at(0).tiger just before main() returns: [N]
O. Please tell me the value of av.at(1).tiger just before main() returns: [O]
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
- | - | - | X | X | - | - | - | - | X | - | - | X | X | X | X | X | - | - | X |
In the following table, you are wanting to insert a new value into the hash table above. Please tell me into which index the new value will go. The table includes the hash value, the collision resolution function, and if necessary, a second hash value. Put your answers into the slot in the table. If there is no answer, then please answer -1.
Please answer each question independently -- in other words, answer each question according to the table above, as if you haven't answered any of the previous questions.
Question | Hash Value | Collision Resolution Strategy | 2nd Hash Value if Necessary | Your Answer |
A | 369033 | Linear Probing | - | [A] |
B | 1077784 | Double Hashing | 1686145 | [B] |
C | 62794 | Double Hashing | 1945959 | [C] |
D | 1320609 | Linear Probing | - | [D] |
E | 342232 | Quadratic Probing | - | [E] |
F | 418294 | Quadratic Probing | - | [F] |
G | 1573160 | Linear Probing | - | [G] |
H | 413252 | Double Hashing | 44968 | [H] |
I | 1108415 | Quadratic Probing | - | [I] |
UNIX> cat aft.cpp #include <iostream> using namespace std; int main() { string s, o; while (cin >> s) o.push_back(s[0]); cout << o << endl; return 0; } UNIX> cat mop.txt quo nnw chi abo omy dun ete UNIX> g++ aft.cpp UNIX> ./a.out < mop.txt
UNIX> cat teal.cpp #include <iostream> using namespace std; int main() { int i; int sum; sum = 0; while (cin >> hex >> i) sum += i; cout << sum << endl; return 0; } UNIX> cat dunk.txt e a 1 x 6 UNIX> g++ teal.cpp UNIX> ./a.out < dunk.txt
UNIX> cat shin.cpp #include <iostream> using namespace std; int main() { int i; int j; int p; j = -1; p = 0; while (cin >> i) { if (j == -1) j = i; p = p ^ i; } cout << (p ^ j) << endl; return 0; } UNIX> g++ shin.cpp UNIX> echo 1061 2915 | ./a.out
UNIX> cat sat.cpp #include <iostream> using namespace std; int main() { int n, i; string s; string p; while (cin >> n) { for (i = 0; i < n; i++) { if (cin >> s) p += s[0]; } } cout << p << endl; return 0; } UNIX> cat most.txt 3 3 8 2 4 1 9 4 5 5 0 6 7 UNIX> g++ sat.cpp UNIX> ./a.out < most.txt
UNIX> cat jeep.cpp #include <vector> #include <iostream> using namespace std; int main() { int n, i; string s; vector <string> sv; sv.resize(5); while (cin >> n >> s) sv[n%5] += s; s = ""; for (i = 0; i < sv.size(); i++) s += sv[i]; cout << s << endl; return 0; } UNIX> cat icy.txt 64 40 96 32 10 69 31 99 0 17 89 25 UNIX> g++ jeep.cpp UNIX> ./a.out < icy.txt
UNIX> cat deck.cpp #include <vector> #include <iostream> using namespace std; int main() { int i, j; string rv; vector < vector <int> > dv; dv.resize(5); for (i = 3; i <= 15; i += 3) { dv[i%5].push_back(i/3); } for (i = 0; i < dv.size(); i++) { for (j = 0; j < dv[i].size(); j++) { rv.push_back('a' + dv[i][j]); } } cout << rv << endl; return 0; } UNIX> g++ deck.cpp UNIX> ./a.out
#include <vector> #include <iostream> #include <sstream> using namespace std; int main() { vector <int> a; vector <int *> p, q; vector <int> *dp; int *b; int i, n; dp = &a; for (i = 0; i < 4; i++) p.push_back(new int); for (i = 0; i < 4; i++) { cin >> n; *(p[i]) = n; } for (i = 0; i < 4; i++) { cin >> n; q.push_back(p[n]); a.push_back(*(p[n])); } for (i = 0; i < 4; i++) { cin >> n; b = p[i]; *b += n; } for (i = 0; i < 4; i++) { cin >> n; a[i] += n; } for (i = 0; i < 4; i++) cout << *(p[i]) << ":"; cout << endl; for (i = 0; i < 4; i++) cout << *(q[i]) << ":"; cout << endl; for (i = 0; i < 4; i++) cout << a[i] << ":"; cout << endl; for (i = 0; i < 4; i++) cout << (*dp)[i] << ":"; cout << endl; return 0; } |
We compile and run the program on the following input (given to the program as standard input):
44 69 24 88 2 0 0 1 1 8 3 5 10 6 9 2 |
There are four lines of output, and each output is a word composed of four numbers separated by colons, with a colon at the end. Like:
1:2:3:4: |
There are no spaces in the output.
Please enter the first line of output:
Please enter the second line of output:
Please enter the third line of output:
Please enter the fourth line of output:
After that, implement a main() that tests ltovl(). It reads strings on standard input and appends them to a list. It then calls ltovl() on the list and stores the answer. It prints the answer by traversing the vector, and for each element of the answer, it:
Remember to set the format of your essay box to "preformatted", and you can resize it to make it bigger while you write your program.
Here's example input and output to the whole program:
UNIX> g++ program.cpp UNIX> cat input.txt fred Luther binky Baby-Daisy Toad thorpaw aesthete persecute Seagram escadrille Heterodyne UNIX> ./a.out < input.txt 0 Luther Baby-Daisy Toad Seagram Heterodyne 1 fred binky thorpaw aesthete persecute escadrille UNIX>