This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2017:cprog:projects:mbe0 [2017/02/07 13:10] – [Submission] wedge | haas:spring2017:cprog:projects:mbe0 [2017/02/15 15:42] (current) – [Total output comparison] wedge | ||
---|---|---|---|
Line 8: | Line 8: | ||
======Project: | ======Project: | ||
+ | =====Errata===== | ||
+ | |||
+ | * Added verification section to facilitate project output specification compliance (20170207) | ||
+ | * Added automatic verification subsection to verification section (20170208) | ||
=====Objective===== | =====Objective===== | ||
To implement a programmatic solution (ie simulation) of a real life process- the mental math trick of multiplying any two- or three-digit number by eleven. | To implement a programmatic solution (ie simulation) of a real life process- the mental math trick of multiplying any two- or three-digit number by eleven. | ||
Line 168: | Line 172: | ||
* input should be in the form of a single **unsigned short integer** value | * input should be in the form of a single **unsigned short integer** value | ||
* no string processing! | * no string processing! | ||
- | * determine from the input if a two- or three-digit number | ||
* declare and utilize these 9 **unsigned char** variables, named and described as follows: | * declare and utilize these 9 **unsigned char** variables, named and described as follows: | ||
* **sum10000** (to store the 10000s place sum digit) | * **sum10000** (to store the 10000s place sum digit) | ||
Line 252: | Line 255: | ||
The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate. | The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate. | ||
+ | |||
+ | ====Output Specification==== | ||
+ | As you can see, there' | ||
+ | |||
+ | <cli> | ||
+ | Enter value: 967 | ||
+ | 967 x 11 = | ||
+ | | ||
+ | | ||
+ | | ||
+ | = (0+1) | ||
+ | | ||
+ | = 10637 | ||
+ | </ | ||
+ | |||
+ | With the exception of the final (packed together) 10637, everything is displayed to STDERR (that 10637 is the only thing to display to STDOUT). | ||
+ | |||
+ | Some important things of note: | ||
+ | * The input value should be //right justified// in a 3 space allocated location to just before the " x 11". | ||
+ | * The equal sign has a space padding it on each side: " = " | ||
+ | * The output is calibrated for working with 5 digits. If there are no digits in those further left places, blanks must be displayed instead (in the 10637 example above, the first four lines are only dealing with 4 digits, until a carry propagates over to a 5th digit). | ||
+ | * Each digit of output needs to be calibrated to potentially display an addition operation, wrapped in parenthesis (as you see in the above example: (9+1) | ||
+ | * if only a single value is being displayed, it must appear where the ' | ||
+ | * if the number to display is a 2-digit number (10-18), its one's place needs to line up with the ' | ||
+ | * each digit space has a single space separating it from the next digit space. | ||
+ | * The final digit column (which should never have a carry) has a newline immediately following it (no trailing spaces). | ||
+ | * At the beginning, the leftmost and rightmost digits are displayed, with the additions visualized on the inner digits, according to the length. | ||
+ | * If there are any additions, the next line needs to show the result of those additions. | ||
+ | * Following any result, carries should be checked for. If any carries are generated, a new line visualizing the additions must be displayed, then another line with the result. This process needs to propagate as many times as needed (thankfully, | ||
+ | * Obviously, if the problem resolves sooner, it does, without needing to display those extra lines. Study the other execution examples, they demonstrate this. | ||
+ | |||
+ | You will probably find some application for selection statements, gaining further experience with them and likely deploying them with more sophisticated relational conditions (even compound ones). | ||
+ | |||
+ | Output formatting is still an important aspect to keep in mind. The computer needs to be told exactly what to do, and our default habits would likely be to do " | ||
+ | |||
+ | Another aspect of the output requirements is that they will force a focus on the individual steps of processing using this algorithm. This should help add exposure to developing good habits of ceasing to automatically read between the lines, and to identify and focus on the discrete steps needed to accomplish the task at hand. | ||
+ | |||
+ | =====Verification===== | ||
+ | Following are some procedures you can follow to verify if your program' | ||
+ | |||
+ | ====STDOUT verification of answer==== | ||
+ | As the final answer (and ONLY the answer) is to be output to STDOUT, your can run the following to check to see if this is the case with your program: | ||
+ | |||
+ | ===3-digit result=== | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 704 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | ===4-digit result=== | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 5632 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | ===5-digit result=== | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 10197 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | ====Total output comparison==== | ||
+ | If you'd like to check if the entirety of your output is correct (especially in relation to spacing), you can do the following. | ||
+ | |||
+ | I have saved sample (correct) outputs on the system that you can check against. The following commands will let you do so: | ||
+ | |||
+ | ===First, save your output to a file=== | ||
+ | |||
+ | I have saved program outputs for the following inputs: | ||
+ | * 37 | ||
+ | * 73 | ||
+ | * 128 | ||
+ | * 480 | ||
+ | * 907 | ||
+ | * 933 | ||
+ | |||
+ | If you run your program with one of these same inputs, you can compare your results for correctness. | ||
+ | |||
+ | In the below example, I do this for an input value of 37: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | What we have done is fed in the input via a here string (form of STDIN redirect), and then output both STDERR and STDOUT into a common file (appending STDOUT, after the STDERR output). | ||
+ | |||
+ | You should now have a file called **output.37** in your current directory. | ||
+ | |||
+ | ===Next, check it against mine=== | ||
+ | I have these files (by the same names), saved in the CPROG Public Directory (under the **mbe0** directory). | ||
+ | |||
+ | By using the **diff** command, you can see differences, | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | If you see output, that means there are differences, | ||
+ | |||
+ | You can repeat this for the other data files (output.73 for an input of 73, etc.) | ||
+ | |||
+ | ===Isolate just the STDOUT or the STDERR=== | ||
+ | Additionally, | ||
+ | |||
+ | To do this, you can do the following. | ||
+ | |||
+ | To isolate STDOUT and STDERR into separate files, you can do the following: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | You can then compare those particular collections of information against my copies (located in the **mbe0** subdirectory of the CPROG Public Directory, by the same file names). | ||
+ | ====automated verification==== | ||
+ | I have rigged up **pchk** to work for this project; it will check for differences and compare MD5sum hashes for stderr, stdout, and total (combined) output. | ||
+ | |||
+ | Once you have everything complete, this is a good final check to do to ensure everything is in order. | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | =================================================== | ||
+ | = mbe0 output validation check = | ||
+ | =================================================== | ||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [ 37] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | |||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [ 73] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | |||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [128] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | |||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [480] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | |||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [907] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | |||
+ | stderr diff: MATCH stderr md5sum: MATCH | ||
+ | [933] stdout diff: MATCH stdout md5sum: MATCH | ||
+ | output diff: MATCH output md5sum: MATCH | ||
+ | =================================================== | ||
+ | = | ||
+ | =================================================== | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Since your project submission will be evaluated in part by compliance to output specifications, | ||
=====Reflection===== | =====Reflection===== | ||
Be sure to provide any commentary on your journal regarding realizations had and discoveries made during your pursuit of this project. | Be sure to provide any commentary on your journal regarding realizations had and discoveries made during your pursuit of this project. | ||
Line 263: | Line 425: | ||
* Code must compile cleanly (no warnings or errors) | * Code must compile cleanly (no warnings or errors) | ||
+ | * Again, I will be compiling as follows: gcc -Wall -o mbe0 mbe0.c | ||
* Submit the program in a file called **mbe0.c** | * Submit the program in a file called **mbe0.c** | ||
* Output must be correct, and match the form given in the sample output above. | * Output must be correct, and match the form given in the sample output above. | ||
Line 293: | Line 456: | ||
52: | 52: | ||
*: | *: | ||
- | *: | + | *: |
*: | *: | ||
*:mbe0:sum variables declared and used appropriately in processing [4/4] | *:mbe0:sum variables declared and used appropriately in processing [4/4] | ||
Line 299: | Line 462: | ||
*: | *: | ||
*: | *: | ||
+ | *: | ||
*: | *: | ||
*:mbe0:no negative compiler messages for code [4/4] | *:mbe0:no negative compiler messages for code [4/4] | ||
*:mbe0:code is pushed to lab46 repository [4/4] | *:mbe0:code is pushed to lab46 repository [4/4] | ||
</ | </ |