Conditional practice

posted by: Ms. Martin 13 September 2010 No Comment

Recall you can use string-length to get the length of a string and string=? to see if two strings are equal.

HtDP1.0 Exercise 4.4.2. Develop the function tax, which consumes the gross pay and produces the amount of tax owed. For a gross pay of $240 or less, the tax is 0%; for over $240 and $480 or less, the tax rate is 15%; and for any pay over $480, the tax rate is 28%.

Also develop netpay. The function determines the net pay of an employee from the number of hours worked. The net pay is the gross pay minus the tax. Assume the hourly pay rate is $12.

Pens with slogan. A store sells pens for 75 cents each for fewer than 10 or 50 cents each for 10 or more. Write a function to model the cost PER PEN given a quantity.

The store allows printing slogans on the pens. Slogans add 2 cents per letter of the slogan and a $3 charge for the full order. Write a function to model the total cost of an order given a slogan and a pen count.

Make sure you are testing all possible slogan cases (what if it’s empty)? Make sure your code is not redundant.

Done already? Here, have some Google interview questions:

  • You are given 8 identical looking balls. One of them is heavier than the rest of the 7 (all the others weigh exactly the same). You a provided with a simple mechanical balance and you are restricted to only 3 uses. Find the heavier ball.  Can you find it with 2 uses?
  • How would you cut a rectangular cake into two equal pieces if a rectangular piece has already been cut out of it? The cut piece can be of any size and orientation. You are only allowed to make one straight cut.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>