CMSC 104, Fall 2008
Homework 2
Basic Algorithms
Out: Monday 9/22/08 and Tuesday 9/23/08
Due at the beginning of the class period:
Section 0201 -- Monday 9/29/08
Section 0401 -- Tuesday 9/30/08
Note that late homeworks will NOT be accepted.
The Objectives
- To practice solving problems in a generic manner
- To practice writing basic pseudocode for the solution of a problem
The Assignment
- The answer to each 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. (25 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.(25
points each)
- 1) Ms. Block passed around a bowl of candy to the students in her class. Before
class, she ate 1 piece and gave 3 pieces to Mr. Frey. Eight students arrived for class.
The first student took a piece of candy, the second student took 3 pieces, the third
student took 5 pieces and so on. After the last student took his/her candy, the basket
was empty. How many pieces of candy were in the bowl at the beginning?
- The bowl will always be empty at the end.
- The user should specify the number of pieces Ms. Block eats, as well as the number she gives to Mr Frey.
- The algorithm should work with any number of students, so the user should specify the number of students.
- The user should specify the number of pieces that that one student eats "more" than the previous student.
Tips about problem # 1 :
- 2) Your grade in CMSC104 is based on the following:
4 Homeworks (4% each) = 16% 3 Projects (8% each) = 24% 3 Exams (20% each) = 60% Total = 100%
If you have the following homework, project and exam grades at the end of the semester, calculate your final average for the course:
Homework 1 = 100/100 Project 1 = 87/100 Exam 1 = 85/100 Homework 2 = 75/100 Project 2 = 95/100 Exam 2 = 80/100 Homework 3 = 100/100 Project 3 = 90/100 Exam 3 = 85/100 Homework 4 = 80/100
Tips about problem # 2 :
- You should allow the user to enter in each of the homework, project and exam grades individually, one at a time, and store each in its own variable.
- You can assume the percentages will always be 4%, 8% and 20%. You should not ask the user to enter in these values.