| Overview | Schedule | Resources | Assignments | Home |
This exam is open-book and open-note. Please allow some time to check your work. If you need extra space, write on the back.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | |
| input: | E | A | S | Y | O | N | E |
| pass 1: | |||||||
| pass 2: | |||||||
| pass 3: | |||||||
| pass 4: | |||||||
| pass 5: | |||||||
| pass 6: |
x is declared as a stack<char>?
x.push('h'); x.push('e'); x.push('l');
cout << x.top(); x.pop();
cout << x.top(); x.pop();
x.push('l'); x.push('o');
cout << x.top(); x.pop();
cout << x.top(); x.pop();
cout << x.top(); x.pop();
What would the output be from the same sequence if x were
declared as a priority_queue<char> (where characters later in
the alphabet have higher priority)?
Finally, what would the output be from the same sequence if x
were declared as a queue<char> and the x.top() operations
were replaced by x.front()?
int countBelow(const vector<int> &v, int n) which will
return the number of items strictly less than n found in the vector
v. You should not assume anything about the ordering of the items
in the vector.
list<int> argument
instead of a vector<int>.
int a[N] when N is a million; instead, you can declare
a to be an object of class test, and the only space
required on the system stack will be for the data pointer--the
million ints will be allocated from the heap):
const int N = 1000000;
class test {
public:
test() : data(new int[N]) { }
test(const test& x);
~test();
test& operator=(const test& rhs);
int& operator[](int i) { return data[i]; }
const int& operator[](int i) const { return data[i]; }
private:
int *data;
};
test::test(const test& x) : data(new int[N])
{ for (int i = 0; i < N; i++) data[i] = x[i];
}
test::~test()
{ // FINISH THIS:
}
test& test::operator=(const test& rhs)
{ // AND THIS:
}
What will be the output from the following program using this class?
void f(test x, test& y) { x[42] = 2 * y[42]; y = x; }
int main()
{ test a;
a[42] = 17;
test b = a;
f(a, b);
cout << a[42] << " " << b[42] << endl;
}
How many times will the test destructor be called in the above
program?
| Overview | Schedule | Resources | Assignments | Home |
![]()
DePauw University,
Computer Science Department,
Fall 2006
Maintained by Brian Howard
(bhoward@depauw.edu).
Last updated