Homework 9 UCR CS10: Introduction to Computer Science Winter Quarter 2004, Lecturer: Kris Miller Due Wednesday, March 10 before 8:00pm by web turnin. YOU MUST TURN THIS IN AS A .CPP, .CC, OR .C FILE. The turnin system will no longer accept other types of files. Your file names should not have spaces or non-alphanumeric characters. A good file name to use is hw9.cpp. ------------------------------------------------------------------------------- Note: Collaboration policy for this homework assignment Collaboration on this homework is strongly ENCOURAGED. The homework is intended for practice, not assessment -- most people who turn in decent work should get most if not all points for this assignment. Forming study groups is strongly encouraged. You shouldn't simply copy answers from any source -- each other, the book, the web, other books, previous solutions, etc. But you can certainly discuss how to solve the problems, look over each others solutions and help "debug" them, compare answers and redo problems if you determine your answer is wrong, and most importantly, explain concepts related to the problems and solutions. ------------------------------------------------------------------------------- 1. Self-test Exercise #7-42 (Chapter 7, #42) 2. Predict the output of the following nested loops int n, m; for (n = 1; n <= 10; n++) { for (m = 10; m >= 1; m--) { if (m < 10) { break; } cout << n << " times " << m << " = " << (n * m) << endl; } } 1 times 10 = 10 2 times 10 = 20 3 times 10 = 30 4 times 10 = 40 5 times 10 = 50 6 times 10 = 60 7 times 10 = 70 8 times 10 = 80 9 times 10 = 90 10 times 10 = 100 3. Self-test Exercise #7-43 4. Self-test Exercise #10-1 (Chapter 10, #1) 5. Self-test Exercise #10-2 6. Self-test Exercise #10-3 7. Self-test Exercise #10-5 8. Self-test Exercise #10-6 9. Self-test Exercise #10-16 10. Programming Project #2 - Chapter 10 (CodeMate) void deleteRepeats(char a[], int& size) { // for each element STILL in the array for (int i = 0; i < size; ++i) { // for each element after the one we're comparing to for (int j = (i + 1); j < size; ++j) { if (a[i] == a[j]) { remove(a, j, size); // the next value to check has been moved up by remove() --j; } } }