CSCI 1320 (Principles of Computer Science I), Fall 2014:
Homework 7

Credit:
10 points.

Reading

Be sure you have read chapter 10.

Programming Problems

Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu, with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1320 homework 7'' or ``CS1 hw7''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.

  1. (10 points) Your mission for this problem is to write a Scala program that defines and tests a case class for a simple implementation of rational numbers. The program should include a definition for a case class Rational and the following functions: It can also include, for extra credit, either or both of the following functions:

    The program should prompt for numerators and denominators for two rational numbers and print the result of calling the four arithmetic-operation functions and any optional functions. (It should just print an error message if either denominator is zero.) Sample output for inputs 1, 2, 6, and 10:

    r1 = 1/2
    r2 = 6/10
    r1 in lowest terms = 1/2
    r2 in lowest terms = 3/5
    r1 + r2 (lowest terms) 11/10
    r1 - r2 (lowest terms) -1/10
    r1 * r2 (lowest terms) 3/10
    r1 / r2 (lowest terms) 5/6
    r1 < r2
    

    Notes/hints:



Berna Massingill
2014-12-09