文件名称:rational
- 所属分类:
- JSP源码/Java
- 资源属性:
- 上传时间:
- 2018-03-10
- 文件大小:
- 1kb
- 下载次数:
- 0次
- 提 供 者:
- 可爱的***
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
创建一个分数类Rational,用来执行分数的算术运算,并编写一个程序来测试该类。
(1)该类有两个成员变量,即分子和分母,均为整数类型
(2)定义一个构造函数,用来对类对象进行初始化。该构造函数必须对输入参数进行约减。例如,若给定的分数为2/4(即分子为2,分母为4),那么要把它约减为1/2,然后存储在相应的成员变量中,即分子为1,分母为2。
(3)定义一个add成员函数,实现两个分数的加法,其结果也应该是约减形式;
(4)定义一个sub成员函数,实现两个分数的减法,结果为约减形式(Create a fractional class Rational, used to perform arithmetic operations for fractions, and write a program to test the class.
(1) the class has two member variables, that is, molecules and denominator, all of which are integral types
(2) define a constructor to initialize the class object. The constructor must reduce the input parameters. For example, if a given fraction is 2/4 (i.e. the molecule is 2, the denominator is 4), we need to reduce it to 1/2, and then store it in the corresponding member variable, that is, the molecule is 1 and the denominator is 2.
(3) a add member function is defined to implement the addition of two fractions, and the result should also be reduced.
(4) a sub member function is defined to implement a subtraction of two fractions, and the result is reduced form.)
(1)该类有两个成员变量,即分子和分母,均为整数类型
(2)定义一个构造函数,用来对类对象进行初始化。该构造函数必须对输入参数进行约减。例如,若给定的分数为2/4(即分子为2,分母为4),那么要把它约减为1/2,然后存储在相应的成员变量中,即分子为1,分母为2。
(3)定义一个add成员函数,实现两个分数的加法,其结果也应该是约减形式;
(4)定义一个sub成员函数,实现两个分数的减法,结果为约减形式(Create a fractional class Rational, used to perform arithmetic operations for fractions, and write a program to test the class.
(1) the class has two member variables, that is, molecules and denominator, all of which are integral types
(2) define a constructor to initialize the class object. The constructor must reduce the input parameters. For example, if a given fraction is 2/4 (i.e. the molecule is 2, the denominator is 4), we need to reduce it to 1/2, and then store it in the corresponding member variable, that is, the molecule is 1 and the denominator is 2.
(3) a add member function is defined to implement the addition of two fractions, and the result should also be reduced.
(4) a sub member function is defined to implement a subtraction of two fractions, and the result is reduced form.)
(系统自动生成,下载前可以参看下载内容)
下载文件列表
文件名 | 大小 | 更新时间 |
---|---|---|
rational | 0 | 2018-03-10 |
rational\Rational.java | 2343 | 2018-03-10 |
rational\Test.java | 585 | 2018-03-10 |