Computers and Technology, 29.07.2020 02:01 bshreve
Complete the function definitions in scala for creating and manipulating Rational Numbers. You will represent a rational number as a pair of integers in reduced form, i. e. the rational number 3/9 will be reduced to 1/3 and stored as (1,3). Also, if the rational number is positive, neither the numerator nor the denominator should be stored as negative and if the rational number is negative then you will store only the numerator as negative. Use the following templates. You should add additional test cases in Driver. scala. Submit just Rational. scala. We will use our own Driver. scala while grading.
Rational. scala
import scala. math. abs
object Rational {
type Rational = (Int, Int)
def makeRational(n:Int, d:Int): Rational = ???
def numer(r:Rational):Int = ???
def denom(r:Rational):Int = ???
def addRational(r1:Rational, r2:Rational): Rational = ???
def subRational(r1:Rational, r2:Rational): Rational = ???
def mulRational(r1:Rational, r2:Rational): Rational = ???
def divRational(r1:Rational, r2:Rational): Rational = ???
def equalRational(r1:Rational, r2:Rational): Boolean = ???
def to_string(r: Rational): String = ???
def printRational(r: Rational): Unit = ???
}
Driver. scala
object Driver extends App {
import Rational._
val r0 = makeRational(1,0)
val r1 = makeRational(-1,3)
val r2 = makeRational(-1,-3)
println(to_string(addRational(r1,r2 )))
Answers: 2
Computers and Technology, 24.06.2019 15:50, coralaguilar1702
Andy would like to create a bulleted list. how should he do this? andy should click on the bullet icon or select the bullet option from the menu and then type the list. andy should press the shift key and the 8 key at the beginning of each line of text. andy should type the text and then click on the bullet command. andy should press return and the bullets will automatically
Answers: 2
Computers and Technology, 24.06.2019 23:30, clairajogriggsk
What is the opening page of a website called? a. web page b. landing page c. homepage d. opening page
Answers: 1
Computers and Technology, 25.06.2019 05:50, jonmorton159
Acolor class has three public, integer-returning accessor methods: getred, getgreen, and getblue, and three protected, void-returning mutator methods: setred, setgreen, setblue, each of which accepts an integer parameter and assigns it to the corresponding color component. the class, alphachannelcolor-- a subclass of color-- has an integer instance variable, alpha, containing the alpha channel value, representing the degree of transparency of the color. alphachannelcolor also has a method named dissolve (void-returning, and no parameters), that causes the color to fade a bit. it does this by incrementing (by 1) all three color components (using the above accessor and mutator methods) as well as the alpha component value. write the dissolve method.
Answers: 2
Complete the function definitions in scala for creating and manipulating Rational Numbers. You will...
English, 08.12.2021 03:20
Mathematics, 08.12.2021 03:20
Mathematics, 08.12.2021 03:20
Chemistry, 08.12.2021 03:20
Mathematics, 08.12.2021 03:20
Spanish, 08.12.2021 03:20
English, 08.12.2021 03:20