ANUC 1100 Introduction to Programming and Algorithms Semester 2, 2019
Assignment 1
Read ALL instructions in the following before working on the problems.
General guidelines for code writing:
1. Define each function with the exact name and type specified. You can (and in most cases, it will make your life easier) implement some helper functions in addition to the functions required.
2. For each function definition, provide a type profile and comprehensive comments where appropriate.
3. Unless said otherwise, functions must be as generic as possible, i.e. they should be defined for all of their possible input values.
4. Use the error function as output for functions that should terminate with a customized error message.
Marking & Submission
1. Your code will be assessed according to the general guidelines 1-4 above including adequate comments, capable of handling error and some illegal inputs, consistent indentation, easy to read, and the correctness of the functions developed.
2. If your code cannot be compiled, 0 mark will be given to the whole question. 3. Late submission will not be accepted.
4. Your function names, file names should follow the naming rule according to the assignment description. Failing to comply the rule will incur 5% of maximum score down for each name violation.
At the end of your source code, make sure you put some comments on any collaboration and your sources (websites, textbooks ) while doing this assignment. Name anybody with whom you collaborated with (and identify the form and scope of the collaboration), and name any sources which you drew inspiration from for a specific part of the assignment. Failing properly acknowledging this will normally trigger a plagiarism investigation.
All functions you developed for this assignment must be included in one single .hs file and submitted to the assignment link on Wattle. Make sure you include your name and student ID in the comment section at the top of your source file. If you have any other supporting documents, you can zip all files into a single archive Assignment_1_
Demonstration
In one of the weeks lab session, you will demonstrate the implementation of your code. Demonstration lab session will be advised beforehand. The idea is to allow you to demonstrate your understanding of your program and check whether the code is your own work. Some questions you may want to address during the demonstration are:
What is your rationale for your program designs? Did you consider alternatives? Which? What makes your solutions efficient and/or elegant? Or: are you solutions less efficient but more readable?
How did you come up with your solutions?
Did you learn anything during the assignment?
Students will be randomly picked (use online tools to take a random number for fairness) to present in the session.
In order to avoid the situation where students intentionally not participate the lab demonstration, 40% mark will be taken down from the score achieved in assignment 1. If student can provide evidence like working schedule conflict, medical certificate, etc., there will be no deductions. In this case, your employer or the doctor visited will be contacted, and you may be asked to do a one-on- one presentation with the lecturer.
For students who are unable to explain their own code, 0 mark will be given for the whole assignment. And also, if found the assignment was out sourced, student will fail this course automatically.
Question 1 (25%)
Some integers like 123321, 51015 when reading from right to left or left to right, they are actually the same. Write a function numCheck x such that it returns True when the input number x satisfies this property, returns False otherwise. However, if the input value is a float number, it shall return a customised error. E.g.
numCheck 1991 True
numCheck 59995 True
numCheck 6767 False
numCheck 123.45
*** Exception: Input is not an integer
You may assume all input in this question will be positive numbers. You should save your question 1 code as 1.hs. Please note if you code up your function that it always returns True or always returns False, you will not receive any marks for this question.
Question 2 (45%)
Write a function numToDecimal x y, such that it outputs the corresponding decimal value based on the input number x and its corresponding base y, where y is taken from {2, 3, 4, 5, 6, 7, 8, 9}.
Based on the property of the invalid input, you need to through one of two different customised error messages accordingly. If it violates both, either customized error message will be treated as correct. E.g.
numToDecimal 1101 2 13
numToDecimal 1101.11 2
*** Exception: My function is not smart enough to handle float yet
numToDecimal 7531 7
*** Exception: input value is illegal for the given base
numToDecimal 7531 8 3929
numToDecimal (-14) 6 -10
You may assume all input in this question are numbers and 2nd input argument y is always valid. You should save your question 2 code as 2.hs.
Question 3 (30%)
You need to implement a function semiAdd x. It takes a list x of integers, and output a list such that the first element equal to the sum of first and last element in the original list, 2nd element equals to the sume of second and second last element in the original, and so on until reach the middle of the list. E.g.
semiAdd [1,2,3,4,5] [6,6,3]
semiAdd [1,2,3,4,5,6] [7,7,7]
semiAdd [5,-2,9,1,1,1,8] [13,-1,10,1]
Note that if the length of the input list is odd, the number located in the middle will not be added to itself. You may assume all input in this question will be integer list. You should save your question 3 code as 3.hs.
Reviews
There are no reviews yet.