Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
pp:2024:scala:l03 [2024/03/13 19:21] tudor.condrea Am modificat portiunea cu split si am scos 2 exercitii |
pp:2024:scala:l03 [2024/03/13 19:27] (current) tudor.condrea Am modificat increment sa ia predicat si am scos percentage pentru a da mai mult timp la merge sort |
||
---|---|---|---|
Line 117: | Line 117: | ||
Add this type alias to your code before solving the following exercises. | Add this type alias to your code before solving the following exercises. | ||
- | **3.3.1.** Write a function which adds one point to all students which have a passing grade (>= 5), and leaves all other grades unchanged. | + | **3.3.1.** Write a function which adds one point to all students that satisfy a given predicate (ex: grade >= 5), and leaves all other grades unchanged. |
<code scala> | <code scala> | ||
- | def increment(g: Gradebook): Gradebook = | + | def increment(g: Gradebook, p: (Str, Int) => Boolean): Gradebook = |
g.map(???) | g.map(???) | ||
</code> | </code> | ||
Line 128: | Line 128: | ||
</code> | </code> | ||
- | **3.3.3.** Write a function which takes a gradebook and returns the percentage of failed vs. passed students, as a pair (x,y). | + | **3.3.3.** Write a function which takes a gradebook and returns the list of names which have passed. Use filter and map from Scala. |
- | <code scala> | + | |
- | def percentage(g: Gradebook): (Double,Double) = ??? | + | |
- | </code> | + | |
- | + | ||
- | **3.3.4.** Write a function which takes a gradebook and returns the list of names which have passed. Use filter and map from Scala. | + | |
<code scala> | <code scala> | ||
def pass(g: Gradebook): List[Str] = ??? | def pass(g: Gradebook): List[Str] = ??? | ||
</code> | </code> | ||
- | **3.3.5.** Implement merge-sort (in ascending order) over gradebooks: | + | **3.3.4.** Implement merge-sort (in ascending order) over gradebooks: |
<code scala> | <code scala> | ||
def mergeSort(l: Gradebook): Gradebook = { | def mergeSort(l: Gradebook): Gradebook = { | ||
Line 146: | Line 141: | ||
</code> | </code> | ||
- | **3.3.6** Write a function which takes a gradebook and reports all passing students in **descending** order of their grade. | + | **3.3.5** Write a function which takes a gradebook and reports all passing students in **descending** order of their grade. |
<code scala> | <code scala> | ||
def honorsList(g: Gradebook): List[Str] = ??? | def honorsList(g: Gradebook): List[Str] = ??? | ||
</code> | </code> |