CSE2050 Exam 2, open books, open notes. Name ____________________________ 1. What does the following print? (3 pts each) Hint, draw a picture. char* t[] = {"HELLO", "WORLD"}; +---+ const char** p = t+1; t --> | 0 | --> "HELLO\0" cout << t[1]; _______________ WORLD +---+ cout << t[1][1]; _______________ O p --> | 1 | --> "WORLD\0" cout << *p; _______________ WORLD +---+ cout << **p; _______________ W cout << p[-1][1]; _______________ E cout << ++*--p; _______________ ELLO (the -- moves p to point to t[0] and the ++ moves t[0] to point to the 'E' in "HELLO"). How many elements are in t? _______________ 2 Circle the objects that are const (1 pt each): t *t **t p *p **p t and **p are const (cannot appear on the left side of = ). Is this legal? char** q=p; _______________ no, because **p='x' is illegal (changing the 'W' to 'x' after declaring the chars to be const), but the above would allow **q='x' which would have the same effect. The correct declaration is: const char** q=p; 2. The following code reads a list of real numbers into a map. Your task is to write code to check if the map is empty, and if not, then to print the difference between the highest and lowest numbers input. For instance, if the input is "5 3.2 8 4.52" then your code should print "4.8" (which is 8 - 3.2). (20 pts). map m; double x; while (cin >> x) m[x] = true; // Answer if (!m.empty()) { // or m.size()>0 or m.begin()!=m.end() map::iterator last = m.end(); // or const_iterator --last; // not m.end()-1 because iterators are bidirectional cout << last->first - m.begin()->first; // or (*last).first, etc. } // If you did it the hard way, searching the whole map for the // lowest and highest, I gave you credit, but the map is already sorted. 3. Write a templated function alt_copy(b, e, d) that copies from the sequence denoted by the input iterators [b, e) to the sequence starting with the output iterator d, but skipping every other element after the first one. For instance (20 pts). const int a[5] = {1,2,3,4,5}; vector b(3); alt_copy(a, a+5, b.begin()); // b now contains {1,3,5} // Answer template void alt_copy(In b, In e, Out d) { while (b!=e) { // not b