Homework 1 UCR CS10: Introduction to Computer Science Spring Quarter 2004, Lecturer: Kris Miller Due Wednesday, April 7 before 8:00pm by web turnin. ------------------------------------------------------------------------------- Turnin: Turnin this assignment to the folder, hw1, 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. ------------------------------------------------------------------------------- **Answers for Self-test Exercises are in the back of each chapter** 1. Self-test Exercise #1-2 (Chapter 1, #2) 2. Self-test Exercise #1-4 3. Self-test Exercise #1-6 4. Self-test Exercise #1-15 5. Self-test Exercise #1-22 6. Write an algorithm you could give to a complete stranger that explains how to throw a surprise party for your best friend. Assume this stranger knows nothing about you, your friends, or how to throw a party. The more precise your steps are, the more likely you will get the party you desire. I will put in the solution for homework 1 one of the more interesting, creative submissions (anonymously, of course), so have fun with this one. -Solutions to #6 **This solution is one of the more precise algorithms submitted:** 1. Get the list of people invited to the surprise party. 2. Mail each of them a separate postcard explaining the surprise party for whom. On the postcard tell them what time they must arrive by and the address. 3. For the guest of honor, the person the party will be held for, send that person a postcard but do not mention the party. Tell him what time to arrive and where. Make sure that the time you tell the guest of honor is a least an hour later than the time you told the other guests. 4. These invitations must be sent out at least two weeks before the party. 5. At least one week before the party drive to a party store and grocery store to buy decorations, party favors, and food. 6. At the grocery store buy at least 10 packs of 50 cookies, 10 12 packs, a vegetable patter, and 10 pounds of candy. Try to buy as many varieties as possible. 7. At the party store, buy 5 rolls of streamers, 2 packs of party favors, 2 packs of party hats, and 3 packs of helium balloons. 8. Rent a helium tank from the party store. 9. Drive back home. 10. On the day of the party, in the morning, put up the streamers. Climbing on to a ladder, take one end of the streamers and tape it to a corner where the wall and the ceiling meet. Climbing on to a ladder, in the middle of the ceiling, tape a middle part of the streamer. Tape the other end to the other side of the room where the ceiling meets the wall. Make sure the parts between point's droops. Repeat with the rest of the streamers but make sure that they begin and end at different parts of the room. 11. Fill up the helium balloons by putting the open end on the nozzle of the helium take and bending the nozzle. The balloon should get bigger. Let it stay on the nozzle for two seconds. Then let it float to the ceiling. Repeat with the rest of the balloons. 12. Now prepare the food. 13. The vegetable platter is already prepared so all you have to do is remove the lid. 14. Open the package of three packs of cookies and dump all the cookies on a large platter. During the party when cookies are running low refill one package at a time. 15. Get a large bowl and fill it with two pounds of candy. 16. Place all three platters on a table where the guests will be hanging out. 17. Soda does not have to be opened but put it close by. 18. When the guests arrive give them each a party hat and a party favor. 19. When you hear the guest of honor's car door slam tell everyone to hide. 20. Unlock the front door and hide. 21. When the guest of honor opens the door and walks in, everyone must jump out of their hiding place and yell surprise. **This one's short but very precise (ie., explicitly states how many and what kind of pizza, what exact games to set up, etc.)** 1. Tell the stranger that the surprise party is to be held at my house. 2. Give to the stranger all the phone numbers of my best friend's friends. 3. Have the stranger buy 2 cheese pizzas and 2 meat lovers' pizzas from Pizza Hut, 3 soda 1-liter bottles (Dr. Pepper, Pepsi, and Sierra Mist), and a German chocolate cake. 4. Set up entertainment systems (PC, Xbox, and PS2), board games (Monopoly, Clue, Risk, Scrabble, and Stratego), and a basketball court outside my house. 5. Tell the stranger to leave everything else to me. ** This one just scares me :-) ** Input: favorite food, favorite color, favorite type of beverage, and blood type. Rent a large room somewhere. Prepare food Spray paint room favorite color Hit subject over head with large blunt object If subject loses too much blood, tell EMT's his blood type. Else, drag his carcass to the room Try to wake him Repeat previous step until subject is awake. Give subject food, beverage, etc Point out that the room is nicely colored, no? Hide all evidence that the room was spray-painted. 7. Self-test Exercise #2-2 (Chapter 2, #2) 8. Self-test Exercise #2-3 9. Self-test Exercise #2-7 10. CodeMate Programming Project #6 (Chapter 1) 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 1 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 to #10 //******************************************************** // // cs.cpp // // This program prints a pattern and a message about // computer science. // //******************************************************** // -------------------------------- // ----- ENTER YOUR CODE HERE ----- // -------------------------------- #include using namespace std; int main() { cout << "*****************************************************\n" << "\n" << "\n" << " C C C S S S S !!\n" << " C C S S !!\n" << " C S !!\n" << " C S !!\n" << " C S S S S !!\n" << " C S !!\n" << " C S !!\n" << " C C S S\n" << " C C C S S S S OO\n" << "\n" << "*****************************************************\n\n"; // -------------------------------- // --------- END USER CODE -------- // -------------------------------- cout << "Computer Science is Cool Stuff!!!\n"; cout << "\n"; return 0; }