void mystery(string &name) { ... }Use no more than 3 sentences for your answer.
h(key) = key % 11Please write the keys into the hash tables, and also, for each key, please complete the following table showing the list of entries you would probe in order to insert the key:
key | linear probing | quadratic probing |
---|---|---|
22 | 0 | 0 |
28 | 6 | 6 |
17 | 6, 7 | 6, 7 |
48 | ||
39 | ||
62 |
Linear Probing Quadratic Probing ----------------------- ----------------------- 0 | 22 | | 22 | | | | | ----------------------- ----------------------- 1 | | | | | | | | ----------------------- ----------------------- 2 | | | | | | | | ----------------------- ----------------------- 3 | | | | | | | | ----------------------- ----------------------- 4 | | | | | | | | ----------------------- ----------------------- 5 | | | | | | | | ----------------------- ----------------------- 6 | | | | | 28 | | 28 | ----------------------- ----------------------- 7 | | | | | 17 | | 17 | ----------------------- ----------------------- 8 | | | | | | | | ----------------------- ----------------------- 9 | | | | | | | | ----------------------- ----------------------- 10 | | | | | | | | ----------------------- -----------------------
string name = "am"; unsigned char h = 19; int i; for (i = 0; i < name.size(); i++) { h = (h << 3) ^ name[i]; } where 'a' = 0x61 and 'm' = 0x6dWhat is the hexadecimal value of h after each iteration of the above loop?
iteration | h |
---|---|
0 | |
1 |
If you cannot figure out the hexadecimal value, you can give the base-10 value for a 2 point deduction.
char value = 'a' + 6; printf("%c", value);
string licensePlate, state, count;licensePlate is a string variable that represents a license plate of the form "state-digits", such as "tennessee-941". Assume that you do not know how many letters precede the dash, nor how many digits are in the number. Write a fragment of C++ code to extract the strings representing the letters and the digits from license plate and assign these two strings to state and count respectively.
string name; double salary; int age;
0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
12 | 17 | 25 | 36 | 43 | 48 |
and your function is asked to pad by 3 digits with a value of 6, the resulting vector should be:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|---|
6 | 6 | 6 | 12 | 17 | 25 | 36 | 43 | 48 |
Your code does not have to do any error checking.
89 75 93 53 BabyDaisy 86 45 100 SmileyWrite a main function that reads student scores from stdin, and that outputs the student's name and the student's maximum score. For example, for the above file your program should output:
BabyDaisy 93 Smiley 100You are guaranteed that there is at least one score for each student, that all scores are greater than 0, that all scores are integers, and that every set of scores ends with a one word name. You may use either printf or cout to create your output. Please do not write any include statements.
0 1 1 0 1 1 0 0should become
1 1 1 1 0 0 0 0Your friend explains that the code is supposed to skip over 1's until it comes to a 0. When it comes to a 0, it searches ahead for a 1. If it finds a 1, then it swaps the 0 and the 1. It then repeats these steps until it fails to find a 1 when it searches ahead for a 1.
Here is the code that your friend wrote (you do not have to know how BitVector's methods are implemented--it is enough to know what they do for you):
class BitVector { protected: vectorbits; public: void swap(int x, int y) // swaps the integers at index locations x and y int getBit(int x); // returns the integer at index location x int getSize(); // returns the size of the bits vector }; void moveBits(BitVector &vec) { int i, j; int size = vec.getSize(); 1 i = 0; 2 j = 0; 3 while (j < size) { 4 while (vec.getBit(i) == 1 && i < size) { 5 i++; 6 } 7 j = i+1; 8 while (vec.getBit(j) == 0 && j < size) { 9 j++; 10 } 11 if (j < size) 12 vec.swap(i, j); 13 i = j; 14 } }
swap(0, 6) swap(4, 7)you would be indicating that the code first swapped entries 0 and 6, and then swapped entries 4 and 7.
Swaps Final Vector ------------------------------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ------------------------------------------------- | | | | | | | | | | | | | | | | | | | | | | | | | | | -------------------------------------------------