2009年5月4日 星期一

Homework 4-27-2009

Do project 2 of Chapter 4.



題目:
Define a class called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of numerator or denominator as a double. Include an additional member function that output the value of the fraction reduced to lowest terms (e.g., instead of outputting 20/60 the method should output 1/3). This will require finding the greatest common divisor for the numerator and denominator, then dividing both by that number. Embed your class in a test program










=> 利用最大公因數相除後,可得到分數之最簡化。大致上的方法都相同,都看幾次後就可顯的較容易上手了。

沒有留言: