Homework 2 UCR CS10: Introduction to Computer Science Spring Quarter 2004, Lecturer: Kris Miller Due Wednesday, April 14 before 8:00pm by web turnin. ------------------------------------------------------------------------------- Turnin: Turnin this assignment to the folder, hw2, using the electronic turnin linked to from the class webpage. For homeworks only, you may turnin .doc (Microsoft Word) or .txt (Notepad) files. You may also turnin the homework as a .cc or .cpp (C++ source) file. Be sure to turn it into the correct folder. At best, you will be penalized 20%. At worst, your homework may not be graded at all. ------------------------------------------------------------------------------- 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 #2-12 (Chapter 2, Exercise #12) 2. Self-test Exercise #2-14 3. Self-test Exercise #2-15 4. Self-test Exercise #2-16 5. Self-test Exercise #2-19 **Self-test Exercise solutions are in the back of each chapter.** 6. Write a program that gets the users name and the name of their favorite movie. Then have the program output the statement: ___________'s favorite movie is _____________! For example, if the user enters Kris Miller for their name and Braveheart for their favorite movie, the program should output: Kris Miller's favorite movie is Braveheart! #include #include // must include this library to use string type using namespace std; int main() { string name, movie; // get user's name cout << "Enter your name\n"; getline(cin, name); // get name of favorite movie cout << "Enter your favorite movie\n"; getline(cin, movie); cout << name << "'s favorite movie is " << movie << "!\n"; return 0; } 7. Self-test Exercise #2-20 8. Self-test Exercise #2-21 9. Self-test Exercise #2-24 **Answers to 7, 8, and 9 in back of chapter 2** 10. CodeMate Programming Project #6 (Chapter 2) You can find this problem by clicking on the CodeMate link from the class page or by following the instructions in the CodeMate enhanced textbook. If you did not get the required CodeMate enhanced textbook, you can buy CodeMate by following this link as well. Once on the website for CodeMate, click "CodeMate Index" from the blue menu on the left. Then click Chapter 2 from the list of chapters and choose #6 from the Programming Projects. When you have completed this program, copy and paste the entire program to your homework file. **SOLUTION: If you copy-and-paste this code in between the boxes, "ENTER YOUR CODE HERE" and "END USER CODE" in CodeMate you will be able to compile (check code) and run it. // -------------------------------- // ----- ENTER YOUR CODE HERE ----- // -------------------------------- // Calculate gross pay if (hoursWorked > 40) { // if worked overtime grossPay = (40 * PAY_RATE) + ((hoursWorked - 40) * 1.5 * PAY_RATE) ; } else { // did not work overtime grossPay = hoursWorked * PAY_RATE; } // Calculate health insurance deduction if (numDependents >= 3) { insurance = HEALTH_INS; } else { insurance = 0; } // Calculate each tax deduction ssTax = grossPay * SOCIAL_SECURITY; federalTax = grossPay * FEDERAL_TAX_RATE; stateTax = grossPay * STATE_TAX_RATE; // Calculate total amount deducted from gross pay to get net pay totalDeductions = ssTax + federalTax + stateTax + UNION_DUES + insurance; netPay = grossPay - totalDeductions; // -------------------------------- // --------- END USER CODE -------- // --------------------------------