CMSC 104, Spring 2010
Homework 2
Basic Algorithms
- Out: Monday 2/22/2010
- Due at the beginning of the class period: Monday 3/01/2010
- Note that late homeworks will NOT be accepted.
- All assignments must be typed. No handwritten assignments will be accepted.
- Save your document as a plain text file, using the editor of your choice.
- You must name your file: hw2.txt and mail it as an attachment to your instructor (dondim1@umbc.edu) before class on Monday
- The subject of your assignment should say: Algorithms Homework
The Objectives
- To practice solving problems in a generic manner
- To practice writing basic pseudocode for the solution of a problem
- To practice converting numbers in different base systems
- To learn basic HTML code
The Assignment
- The answer to each of the first two problem will have two parts: the specific solution and the general solution.
- You do not have to do any error checking of user input.
- First solve each of the two problems shown below. You should show the specific answer to the problem using the numbers given. (5 points each, so make sure you show your work, no matter how simple you think it is)
- Then write an algorithm for each of these two problems in pseudocode.(20
points each. Hence each problem is 25 points total: 5 points for the specific solution and 20 points for the general solution.)
- Mrs. Smith is on a cruise to the Bahamas. On a rainy day, she decides to go to the casino bar and play blackjack. She pays a $5.00 cover charge to enter the casino bar. She plays at one table, doubles her money and tips the dealer $25.00. She goes again the next day, again, pays the $5.00 cover charge and doubles her money. After tipping the dealer another $25.00, she has no money. How much money did she start with?
- Mrs. Smith must always have no money left at the end.
- The user should specify the number of days she plays blackjack.
- The user should specify the cover charge to enter the casino bar. You can assume it will be the same for each day.
- The user should specify the amount of the tip. You can assume it will be the same each time she plays.
- A Winter Games event is based on the following:
5 Compulsory Events (2% each) = 10% 3 Freestyle Events 10% each) = 30% 2 Open Events (30% each) = 60% Total = 100%
If you have the following compulsory, freestyle and open scores at the end of the games, calculate your final overall score:
Compulsory 1 = 10/10 Freestyle 1 = 8/10 Open 1 = 9/10 Compulsory 2 = 5/10 Freestyle 2 = 7/10 Open 2 = 10/10 Compulsory 3 = 10/10 Freestyle 3 = 9/10 Compulsory 4 = 9/10 Compulsory 5 = 8/10
Tips about problem # 2 :- You should allow the user to enter in each of the compulsory, freestyle and open scores.
- You can assume the percentages will always be 10%, 30% and 60%. You should not ask the user to enter in these values.
- Conversion problems: Worth 5 points each
- A. Convert 9873 to its equivalent binary form.
- B. Convert 10101101 to its equivalent decimal form.
- C. Convert FA3B to its equivalent decimal form.
- D. Convert 1011 0111 1111 1010 to its equivalent hexidecimal form.
- E. The number FF2AE7 represents a RGB color. What are the levels of red, green, and blue?
- Lab excercise: Learning Basic HTML elements
This excerise will be given out in the lab on Wednesday and will count for 25 points.
Tips about problem # 1 :