Homework 1 UCR CS10: Introduction to Computer Science Winter Quarter 2004, Lecturer: Kris Miller Due Wednesday, January 14 before 8:00pm by web turnin. ------------------------------------------------------------------------------- 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 #1-22 (Chapter 1, #22) 2. Self-test Exercise #1-23 3. Self-test Exercise #1-24 4. Self-test Exercise #1-27 5. The following program has an error. What is the error? Which of the 3 main kinds of program errors is it? Rewrite the line containing the error so that the program works correctly. // This program outputs the sum of two numbers entered by the user. #include using namespace std; int main() { int num1, num2, sum; cout << "Enter an integer and press return\n"; cin >> num1; cout << "Enter a second integer and press return\n"; cin >> num2; num1 + num2 = sum; cout << num1 << " + " << num2 << " = " << sum << endl; return 0; } Hint: If you don't see the error, try compiling and running the program. 6. Self-test Exercise #2-2 (Chapter 2, #2) 7. Self-test Exersice #2-4 8. Self-test Exersice #2-5 9. Self-test Exersice #2-6 10. (a) Write an algorithm (in English) for the following problem definition. Past experience of science and engineering students have shown that to be successful, the average student should spend between 3 and 4 hours per unit per week studying and attending lectures and labs. Design an algorithm that will calculate the range of hours a student should be studying per week based on the number of units they are currently taking. So, if a student is taking 12 units, this algorithm should calculate that they need to be spending between 36 and 48 hours per week studying and attending lectures and labs if they want to be successful. (b) Translate this algorithm into a C++ program.