Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.