Due by 11:59pm on Friday, December 1, in my email inbox. Send your program as an attachment.
The late penalty is 5% per hour.
Using the language you selected, write a program to solve the problem below. The precise input and output format is specified (including filenames), and your output must match byte-for-byte. Your program must consist of one source file called "round.zzz", where zzz is an appropriate extension for your language.
Grading will be on a 100-point scale, based on an assortment of test cases I have prepared.
Rational numbers are numbers that are ratios of two integers. In other words, if r is a rational number then there are two integers p and q (with q ≠ 0) such that r = p/q. If p and q are chosen so that they have no common factors (i.e. their greatest common divisor is 1; gcd(p, q) = 1) then we say that the ratio is in lowest terms. For example 6/13, 27/4, and 24/125 are all rational numbers in lowest terms.
There are times when a ratio in lowest terms consists of unruly or awkward integers that make it difficult to quickly or easily understand the relative value of the rational number they represent. Often these numbers are very close to other rational numbers that are easier to interpret because in lowest form they consist of smaller integers. For example, 6/13 is close to 1/2, 27/4 is close to 7/1, and 24/125 is close to 1/5.
Wim Lewis has published a web page that details an algorithm for finding the closest rational number to a given p/q, such that both the integers in that ratio are at most some value N.
Write a program that includes an implementation of this algorithm, and applies it to a list of rational numbers read from a text file.
Input: Each line of the input file contains three positive integers (except the last line, which contains a single 0). The first number is p, the second number is q, and the third number is N.
Output:For each line in the input file, display the rational number closest to it within the given bound.
Example Input: | Example Output: |
58 129 10 58 129 7 25 56 10 24 125 25 24 125 15 13 41 10 0 |
4/9 3/7 4/9 4/21 1/5 1/3 |
Plagiarism Copying all or part of anyone else's code, regardless of the source, is prohibited. Exception: you may use code that I provide in class. Excessive collaboration is a more subtle form of plagiarism involving two or more students in the class; see below.
Collaboration Here's the rule:
You are encouraged to discuss ideas with other students but you may not share any code or answers.
That's it. If you turn in code or answers that are the same as (or very similar to) someone else's, then you have cheated. I don't care what your intentions were. If, after analyzing your code/answers, I think it is statistically very likely that sharing has occurred, I will divide the credit among the offending parties (on the first offense), assign a 0 (on the second offense), or assign an F for the course (on the third offense). Note: when determining whether two pieces of code are the same, I ignore irrelevant differences such as variable names, whitespace, comments, indentation, parentheses, brackets, literal strings, declaration order, and simple logical and/or algebraic code translations.
Unacceptable excuses