Assignment 1 Feedback and Assignment 2

Save this PDF as:

Size: px
Start display at page:

Download "Assignment 1 Feedback and Assignment 2"


1 Outline COMP105 Lecture 20 Assignment 1 Feedback and Assignment 2 Today Assignment 1 feedback Assignment 2 introduction Assignment 1 feedback Part A Average mark: 79 Average on part A: 33/35

2 Part B General feedback Average on part B: 31.9/35 Almost everyone produced solutions for parts A and B Common errors: Incorrect base cases Missing the '0' case in char_to_int/int_to_char Incorrect dropchar If you solved parts A and B, then you ve demonstrated a good knowledge of recursion. Part C Part C was attempted in 73/107 submissions. Average mark 14.6/30 General feedback Part C was attempted in 73 submissions 31 submissions got full marks Common problems in part C Issues with numbers > 99 Issues with lone-characters, ie., "a11bc11" If you got a non-zero mark on part C then very well done!

3 General feedback: coding style Assignment 1 worked solutions Some solutions used very long lines Think about using lets to break it down a little more Some solutions used long chains of ifs Think about using the guard syntax Some solutions used head and tail to break up lists Think about using pattern matching No marks were lost due to coding style Assignment 2 Assignment 2 Assignment 2 is out now The handout is available on the COMP105 website The assignment is to use higher-order programming to process the transaction history of a stock portfolio Some questions require you to use certain functions The deadline is Wednesday the 21st of November 2018 at 12:00 (midday) Q2 requires map Q4 requires filter Q7 requires foldr Otherwise, there are no restrictions on what functions you can use

4 Transactions Transactions A transaction is a tuple ('B', 100, 1104, "VTI", 1), The first element is whether we 'B'ought or 'S'old The second element is the number of units The third element is the price The fourth element is the stock The fifth element is the day A transaction log is a list of transactions type Transaction = (Char, Int, Int, String, Int) test_log :: [Transaction] test_log = [('B', 100, 1104, "VTI", 1), ('B', 200, 36, "ONEQ", 3), ('B', 50, 1223, "VTI", 5), ('S', 150, 1240, "VTI", 9), ('B', 100, 229, "IWRD", 10), ('S', 200, 32, "ONEQ", 11), ('S', 100, 210, "IWRD", 12) ] Part A (worth 40%) Part B (worth 30%) Part A is to build a program to report the trade history on a given stock Using map and filter Part B is to build a program to calculate the profit for a given set of stocks Using foldr ghci> trade_report "VTI" test_log "Bought 100 units of VTI for 1104 pounds each on day 1\n Bought 50 units of VTI for 1223 pounds each on day 5\n Sold 150 units of VTI for 1240 pounds each on day 9\n" ghci> profit_report ["VTI", "ONEQ"] test_log "VTI: 14450\nONEQ: -800\n"

5 Computing profit The profit is the amount of money that we make We spend units * price pounds when we buy We gain units * price pounds when we sell Part C (worth 30%) Part C is to build a profit report program But the data is given as a string So if we Bought 10 units at 100 pounds Sold 5 units at 110 pounds Sold 5 units at 120 pounds Then our profit is BUY 100 VTI 1 BUY 200 ONEQ 3 BUY 50 VTI 5 5SELL 150 VTI 9 BUY 100 IWRD 10 SELL 200 ONEQ 11 SELL 100 IWRD 12 -(10 * 100) + (5 * 110) + (5 * 120) = 150 Part C (worth 30%) Part C (worth 30%) The prices are given in a price database type Prices = [(String, [Int])] Given a log string and a price database Compute a profit report like in part B Should include all stocks in the database test_prices :: Prices test_prices = [ ("VTI", [1689, 1785, 177, 1765, 1739, 1725, ("ONEQ", [201, 203, 199, 199, 193, 189, 189, ("IWRD", [207, 211, 213, 221, 221, 222, 221, ] ghci> complex_profit_report test_str_log test_prices "VTI: -7600\nONEQ: -2600\nIWRD: -500\n"

6 Penalties Summary There is a 5% penalty for not following these guidelines: Your code should compile with no errors Assignment 1 feedback Assignment 2 introduction Do not alter the type signatures in the template file in any way Do not remove the module line Leave the stub error-messages if you do not answer a question Next time: More custom types