CS 115 – Dubai – Fall 2012
Assignment 01
Due: Thursday, September 27, 2012 at 11:59 p.m.
• You are not allowed to use cond or if statements in your solutions for this assignment. This assignment is testing Modules 1 and 2 material only.
• For this and all subsequent assignments, you are expected to use the design recipe when writing functions from scratch, including helper functions.
• Do not copy the purpose directly from the assignment description. The purpose should be written in your own words and include reference to the parameter names of your functions.
• The solutions you submit must be entirely your own work. Do not look up either full or partial solutions on the Internet or in printed sources.
• Do not send any code files by email to your instructors or tutors. It will not be accepted by course staff as an assignment submission. Course staff will not debug code emailed to them.
• Test data for all questions will always meet the stated assumptions for consumed values.
• Read each question carefully for restrictions.
• Read the course Web page for more information on assignment policies and how to organize and submit your
work. Follow the instructions in the style guide. Specifically, your solutions should be placed in files a01qY.rkt,
where Y is a value from 1 to 3.
• Download the interface file from the course Web page.
• For full marks, it is not sufficient to have a correct program. Be sure to follow all the steps of the design recipe,
including the definition of constants and helper functions where appropriate. Language level: Beginning Student
Coverage: Modules 1 and 2
1. When making a purchase in a foreign country, you have several options. You may choose to pay for the purchase with a credit card in local currency or you may choose to withdraw money from a local bank machine and pay with the local currency cash. However, in the end it will cost you money in your own bank account’s currency. In both cases there will be an exchange rate charged to convert the currency. When you withdraw money from a local bank machine, there will be an extra service charge. Write a function called lower-cost that consumes three numbers: amount, exch-credit, and exch-debit, and produces the cost in Canadian dollars of the lower option. All the numbers are greater than 0. The amount is the cost of the purchase in local currency, exch-credit is the exchange rate charged by the credit card purchase, and exch-debit is the exchange rate charged by the bank machine withdrawal. The exchange rates represent the amount of Canadian currency it costs for 1 unit of local currency. The service charge for a bank machine withdrawal is always $5 Canadian. For example (lower-cost 100 0.25 0.22) produces 25 since the credit card cost would be $25 Canadian and the cash withdrawal cost would be $22 + $5 = $27 Canadian. Note that it is possible that the two amounts are the same, but in that case it would not matter which calculated value you produce.
2. Write a function called justified-last-line that consumes a string (text) and a natural number greater than 1 (line-length) and produces part of the original string. The string that is produced would appear as the last line in text that was justified to line-length. Justified text has the same number of characters on each line, except possibly the last line.
For example the text “abcdefghijklm nopqrstuvwxyz” justified to a line length of 5 would look like: abcde
—-PAGE—-
CS 115 – Dubai – Fall 2012
Assignment 01
Due: Thursday, September 27, 2012 at 11:59 p.m.
So the last line of this justified text, and the string that the function produces is “yz”. Note that the line length may be greater than the length of the string. You may assume that the last line contains more than 0 and less than line-length characters and that text is a non-empty string.
3. One of the events at the Olympics is synchronized diving. In this event there is a team of two divers who perform a dive at the same time. Judges score each team on the individual execution of the dive by each team member and the team is scored on the synchronization of the two divers. The scoring is a little complicated. There are three scores for each individual diver. The highest score and lowest score for each diver are eliminated. There are five scores for the synchronization of the dive. Again the highest score and lowest synchronized score are eliminated. All scores are in the range 0 through 10, inclusive. Each dive has a degree of difficulty between 1.2 and 5. The final score for a team dive will take the total of the individual and synchronized dives left after eliminating the appropriate top and bottom scores, and multiplying that sum by the degree of difficulty and by a constant of 0.6. For example for the following judges scores,
scores: 9, 9.5, 8.5
scores: 8, 8, 8.5
Synchronized scores: 9, 9.5, 8.5, 9, 8
Degree of difficulty: 3.6
will result in a final score of (9 + 8 + 9 + 8.5 + 9) * 3.6 * 0.6 = 93.96
For examples of actual diving scores you can go to: http://www.london2012.com/diving/event=diving- women-synchronised-3m/
Write a function called diving-score that consumes the 11 judges scores (3 for diver A, 3 for diver B and 5 for synchronization) and the degree of difficulty and produces the final team score for the synchronized dive.
—-PAGE—-