Programming Assignment 4 - Long Division

Advanced Programming II, Fall 2001


Due Date

This assignment is due by 2:00 p.m. on Thursday, 1 November.

See the assignment turn-in page (last modified on 11 September 2001) for instructions on turning in your assignment.

The Problem

Write a program that reads from std-in two numbers A and B and writes to std-out the long division calculation for B divided by A. For example, if the program reads A = 1.7 and B = 37.2, the program should output

      21 
    ------
1.7 | 37.2
      34
      --
       3.2
       1.7
       ---
       1.5

Remember that the result of dividing A by B is a pair of numbers (q, r) with the properties

  1. A = B*q + r

  2. 0 <= r < B

Input

The syntax for a number is

  1. A positive base-10 integer followed by an optional decimal point followed by an optional positive base-10 integer. The numbers "1", "1." and "1.2" are examples.

  2. A decimal point followed by a positive base-10 integer. The number ".1" is an example.

  3. A minus sign may immediately precede a number to indicate a negative value.

  4. Unnecessary leading and trailing zeros should be suppressed on output.

Input will be a sequence of number pairs, separated by white space. invalid input should terminate execution with an error message.

Output

Output should be formatted to the example given above. Use use space characters to align the numbers properly; do not use tabs to align the output lines.

Testing

You're on your own; I won't be providing any test cases for this problem.


This page last modified on 18 October 2001.