Sei sulla pagina 1di 2

ECOR 1606 Section C - Exercise 1

Rules for all assignments:


In each program, put a comment as the first line, writing your name and student number Submit your files using the submit program (available on the course web site) before the deadline. Warning: File names must match exactly the names given below. If you have questions, instead of mailing the instructor, please post your question on the assignment discussion group (on the course website) so that all may benefit from your question. And other students will answer your question. The instructor will only monitor the conversation and intervene when needed. This is an exercise in collaborative learning. Please try it and get used to it. It will be your lifeline when do software development. Always submit an assignment even if you dont get it working. Some marks are for executing programs but some marks are for logic and method.

Question 1
The device illustrated below consists of a single digit display (possible values 0 to 9) controlled by a thumbwheel. Moving the thumbwheel up increases the digit displayed and moving the thumbwheel down decreases the digit displayed. The only basic actions permitted are "move thumbwheel up by one" and "move thumbwheel down by one". Your instructions must work properly regardless of value initially display (do NOT assume that the initial value will always be 6). Conditions should be based upon the "desired value" and the "displayed value".

On the course website, you are given a partial C program (called assign1a.c) that acts like this thumbwheel. You must complete the program so that it sets the thumbwheel to a particular desired value. Remember to build a Pelles C project (as you did in Lab 1). Create a new file (of the proper name) and copy-paste the code from the web-posting to this file. Build the program it will build (i.e. compile) correctly but if you run it, it will do nothing useful because all the key code is missing. You have to fill it in. Use the comments as a guide for where code is needed. One set of test values are given (under the comment Test 1). Just because your program works for these values doesnt mean it is complete. You must test the program for different values too! You will do this by changing the initial values, re-building and

running the program again. However, we want to maintain a history of all the values you tested for, so o For each test, do not delete or overwrite the old values. Instead, comment out the old values and insert new values using the comment symbol //. o You will end up with multiple lines of assignment statements, with all commented out except the last one. o See the code for further instructions.

Question 2
You are given another partial C program (called assign1b.c) so that it calculates xy (i.e. x to the yth power) and stores the result in answer. x is any real number and y is an integer (negative, zero, or positive). You may only use addition, subtraction, multiplication, and division in your instructions. As in Question 1, you must test your program using different initial values of x and y. Remember to just comment out old values so we have a trace of your testing practices.

Bonus (2 marks + 3 marks)


Only attempt after doing the Question 1 and 2. Bonus parts are intended for advanced or repeating students. The solutions require independent knowledge of conditional if-statements and first-time students are not expected to be able to do this. Do not panic over the difficulty level. Bonus 1: Actually, the thumbwheel device is circular - moving the thumbwheel up when 9 is displayed changes the displayed digit to 0 (and vice versa). Re-work the program so that it performs optimally - it ensures that it uses the smallest possible number of thumbwheel movements. Bonus 2: Assume a three digit display made up of three devices like the one above. Expand the program increasing the displayed value by 1. Identify the three components as "hundreds", "tens", and "units". If the initially displayed value is 999 applying your instructions should produce a displayed value of 000.

Marking Scheme (Total: 10 marks + 5 Bonus)


Question 1 - 5 marks 1 mark: Correct compilation and execution 3 marks: Code inspection: 1 mark each for whiles condition, increase and decrease 1 mark: Testing Coverage: Have you tried multiple and meaningful test combinations? 3 marks: Bonus Question 2 - 5 marks 1 mark: Correct compilation and execution 3 marks: Code inspection. 1 mark each for exceptions, positive range and negative range. 1 mark: Testing Coverage: Have you tried multiple and meaningful test combinations?

Potrebbero piacerti anche