CMSC 104, Spring 2011
Homework 2 - Basic Algorithms Solutions
- Problem 1:
- The answer to the specific solution was $15.
- The generic algorithm:
Display "Enter the number of days"
Read <num days>
Display "Enter the cover charge"
Read <cover charge>
Display "Enter the amount of tip"
Read <amount tip>
<start money> = 0
While( <num days> > 0 )
<start money> = ( <start money> + <amount tip> ) / 2
<start money> = <start money> + <cover charge>
<num days> = <num days> - 1
End_while
Display "Mrs. Smith started with", <start money>
- Problem 2:
- The answer to the specific solution was 81.05%.
- The generic algorithm:
Display "Enter the grade for homework 1"
Read <hw1>
Display "Enter the grade for homework 2"
Read <hw2>
Display "Enter the grade for homework 3"
Read <hw3>
Display "Enter the grade for project 1"
Read <proj1>
Display "Enter the grade for project 2"
Read <proj2>
Display "Enter the grade for project 3"
Read <proj3>
Display "Enter the grade for project 4"
Read <proj4>
Display "Enter the grade for exam 1"
Read <exam1>
Display "Enter the grade for exam 2"
Read <exam2>
Display "Enter the grade for exam 3"
Read <exam3>
<hw points> = (<hw1> + <hw2> + <hw3>) * .04
<proj points> = (<proj1> + <proj2> + <proj> + <proj4>) * .07
<exam points> = (<exam1> + <exam2> + <exam3>) * .20
<final percentage> = <hw points> + <proj points> + <exam points>
Display "The grade for the course is", <final percentage>
NOTE: There are other correct ways of doing these problems.
Last Modified: Saturday, 12-Mar-2011 15:49:15 EST