CSCI 3055 Assignment 1

$30.00

Download Details:

  • Name: A1-gppxe9.zip
  • Type: zip
  • Size: 118.65 KB

Category:

Description

5/5 - (1 vote)

Programming Languages
All programming questions are to be implemented using Scala.
1. Convert the following object oriented code to an implementation that uses closure and functions as
values.
Object oriented version in Java:
classPerson{
privateintage;
privateStringname;
publicPerson(Stringname,intage){
this.name=name;
this.age=age;
}
publicintgetAge(){returnthis.age;}
publicintgetName(){returnthis.name;}
publicintgrow(){this.age+=1;returnthis.age;}
}
You are to provide an alternative implementation that can be used as follows:
val(age,name,grow)=makePerson(“ClarkKent”,28);
println(age()) //28
println(name()) //ClarkKent
println(grow()) //29
println(grow()) //30
println(grow()) //31
2. Implement the quicksort algorithm using functional programming. You should only use immutable
data structures. Your implementation takes on the form of a function with the following signature:
defquicksort[K](comparator:(K,K)=>Int)(input:List[K]):List[K]{

}
3. For (2), answer the following questions.
3.1 What is the advantage of making quicksort a curried function?
3.2 What would be the Java-equivalent way of achieve the curried version of quicksort ?
Submission:
1. part1.scala [40]
This should contain both the implementation of makePerson function, and the test code as
indicated above.
2. part2.scala [40]
This should contain both the implementation of quicksort, and a testing code to ensure that the
implementation is correct.
3. part3.pdf [20]
This contains the answers to 3.1 and 3.2.
All submissions are to be made via blackboard.com.