Question: #in scala (I need to code not the possible how it can be done) #no for loops and please don't import anything #please answer it

#in scala (I need to code not the possible how it can be done)

#no for loops and please don't import anything

#please answer it if you know how to do it, I really can't waste anymore questions

Problem: Please create a class Biguint (Big Unsigned Integer) which will allow us to store arbitrarily large unsigned integers. Using the additional information below, the class needs to have a member integer list, where each spot in the list stores one digit of the number. You will store the 1s digit in the first position, the 10s digit in the second position, the 100s digit in the third position, etc. An example of this would be the number 1,472 would be stored in the list: 2::7::4::1::Nil.

Additional information for the Biguint class (4 points to be covered)

-The primary constructor will take in a list of integers, and simply initialize the member variable. The list can have a public val if needed.

-include a constructor that takes no arguments and initializes the list to 0::Nil.

-Also include the following constructor that takes in a string; for example 1,472 would be represented as 1472 (this allows us to represent integers with an arbitrary number of digits). You need to use the given info below. (A note: In the body of a non-primary Scala constructor, ALL you're allowed to do is call the primary constructor. So if we want to call another function, we must actually bundle it as part of the parameter! Looking at the convert function, youll notice that Scala lets you treat a string as a list of characters. This function also uses the append operator ::: which joins two lists together.) def this(s:String) = this({def convert(s:String):List[Int] = {if(s.isEmpty) Nil else convert(s.tail):::List((s.head-'0'))}; convert(s)})

(expanded form)

def this(s:String) = this ( {

def convert(s:String):List[Int] = {

if(s.isEmpty) Nil

else convert(s.tail):::List((s.head-'0'))

};

convert(s)

} )

-Implement a + function that adds together two Biguints and returns a new Biguint holding the result. You may use a helper function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!