COMP 1672 Sections 1 & 2 Homework #3 Due Tuesday morning, January 28, 2002 1. What is the output from the following program? Give an explanation of what is happening line-by-line #include #include using namespace std; void bar(int *input); int main() { int nums[5]; nums[0] = 10; nums[1] = 100; nums[2] = 1000; nums[3] = 2000; nums[4] = 3000; bar(nums); return 0; } void bar(int *input) { cout << *input << endl; input++; cout << *input << endl; input+=2; cout << *input << endl; input++; cout << *input << endl; } 2. What is the output from the following code segment? As part of your explanation, draw a picture of memory. Decide on your own memory addresses, but use them consistently. int x = 6; int y = 7; int *p = &x; int *q = &y; cout << x << " " << y << " " << p << " " << q << " " << *p << " " << *q << endl; *p = 7; cout << x << " " << y << " " << p << " " << q << " " << *p << " " << *q << endl; if(p == q) { cout << "Equal" << endl; } p = q; y = 10; cout << x << " " << y << " " << p << " " << q << " " << *p << " " << *q << endl; 3. Write a program using vectors that does the following (in order). Puts the integer 3 into the vector Puts 6 in the last position in the vector Puts 8 in the last position in the vector Removes the last element from the vector Prints out the vector's size Puts 5 into the list position in the vector Uses an iterator to print out all the elements contained in the vector on separate lines Empties the vector