subject
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 )))

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 14:00
Rint "censored" if userinput contains the word "darn", else print userinput. end with newline. #include #include using namespace std; int main() { string userinput; userinput = "that darn cat."; /* your solution goes here */ return 0; }
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Which software would you use to create a print design? a. illustrator b. audacity c. reaper d. dreamweaver
Answers: 2
question
Computers and Technology, 23.06.2019 13:30
Best laptops for college [$100-$500 range]?
Answers: 2
question
Computers and Technology, 23.06.2019 23:40
Which of the following calculates the total from the adjacent cell through the first nonnumeric cell by default, using the sum function in its formula? -average -autosum -counta -max
Answers: 1
You know the right answer?
Complete the function definitions in scala for creating and manipulating Rational Numbers. You will...
Questions
question
Mathematics, 11.03.2020 00:54
Questions on the website: 13722363