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, 22.06.2019 01:30
What “old fashioned” features of checking accounts is p2p replacing
Answers: 3
question
Computers and Technology, 23.06.2019 06:30
When early motion pictures played in movie theaters, they were often accompanied by live organ or piano music. which of the following are the most likely reasons that this happened? (select all that apply). the music was provided to distract audience members from the loud sounds made when filmstrips were changed. the music accompanied the movies because the movies were silent and audiences were used to hearing music during plays in theaters. the music usually was played before, and sometimes after the movie, as an alternative form of entertainment. the music viewers to interpret the dramatic action in the films.
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Facial expressions and gestures are examples of messages.
Answers: 3
question
Computers and Technology, 23.06.2019 20:00
What software programs are used to to create professional publication? a.) graphics programs b.) word processors c.) page layout programs d.) spreadsheet programs
Answers: 2
You know the right answer?
Complete the function definitions in scala for creating and manipulating Rational Numbers. You will...
Questions
question
Mathematics, 22.01.2021 01:00
question
Mathematics, 22.01.2021 01:00
question
Mathematics, 22.01.2021 01:00
Questions on the website: 13722367