User Tools

Site Tools


haas:spring2017:cprog:projects:mbe0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:spring2017:cprog:projects:mbe0 [2017/02/06 22:15] – [Program] wedgehaas:spring2017:cprog:projects:mbe0 [2017/02/15 15:42] (current) – [Total output comparison] wedge
Line 8: Line 8:
 ======Project: MENTAL MATH - MULTIPLY BY 11 (mbe0)====== ======Project: MENTAL MATH - MULTIPLY BY 11 (mbe0)======
  
 +=====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 183: Line 186:
   * output the final value to STDOUT   * output the final value to STDOUT
     * display each digit individually (all packed together)     * display each digit individually (all packed together)
 +  * no loops, repetition, recursion, nor goto statements
  
 =====Execution===== =====Execution=====
Line 251: 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's some spacing at work in the program's output:
 +
 +<cli>
 +Enter value: 967
 +967 x 11 =           (9+6) (6+7)   7
 +                    15    13     7
 +               (9+1) (5+1)       7
 +                10             7
 +         = (0+1)               7
 +                           7
 +         = 10637
 +</cli>
 +
 +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 '+' sign would be (so everything will line up in a digit-centered-like fashion).
 +    * if the number to display is a 2-digit number (10-18), its one's place needs to line up with the '+' sign.
 +    * 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, as you only have to consider 2- and 3- digit numbers and aren't allowed to use loops/gotos/repetition, there is a fixed upper bound on how many times you need to process these potential changes.
 +    * 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 "whatever works"... so I am maintaining an exactness on my requirements for output to ensure we continue to establish these good habits.
 +
 +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's output is in conformance with overall project specifications.
 +
 +====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:~/src/cprog/mbe0$ ./mbe0 2>/dev/null <<< 64
 +704
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +===4-digit result===
 +<cli>
 +lab46:~/src/cprog/mbe0$ ./mbe0 2>/dev/null <<< 512
 +5632
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +===5-digit result===
 +<cli>
 +lab46:~/src/cprog/mbe0$ ./mbe0 2>/dev/null <<< 927
 +10197
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +====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:~/src/cprog/mbe0$ ./mbe0 <<< 37 2>output.37 1>>output.37
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +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, if any. If there are no differences, the output matches (this is good, and what you want).
 +
 +<cli>
 +lab46:~/src/cprog/mbe0$ diff output.37 /var/public/cprog/mbe0/output.37
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +If you see output, that means there are differences, and that your output likely isn't in conformance with project specifications.
 +
 +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, you may want to specifically look at your program's STDOUT or STDERR independent of each other.
 +
 +To do this, you can do the following.
 +
 +To isolate STDOUT and STDERR into separate files, you can do the following:
 +
 +<cli>
 +lab46:~/src/cprog/mbe0$ ./mbe0 <<< 37 1>stdout.37 2>stderr.37
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +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:~/src/cprog/mbe0$ pchk cprog mbe0
 +===================================================
 +=          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
 +===================================================
 +=     matches: 36, mismatches:  0, total: 36      =
 +===================================================
 +lab46:~/src/cprog/mbe0$ 
 +</cli>
 +
 +Since your project submission will be evaluated in part by compliance to output specifications, you probably want to check to see how you are doing before submitting.
 =====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 262: 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**
   * 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.
   * Code must be nicely and consistently indented (you may use the **indent** tool)   * Code must be nicely and consistently indented (you may use the **indent** tool)
Line 285: Line 450:
  
 You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
 +
 +What I'll be looking for:
 +
 +<code>
 +52:mbe0:final tally of results (52/52)
 +*:mbe0:adequate indentation and comments in code [4/4]
 +*:mbe0:program correctly implements specified algorithm [8/8]
 +*:mbe0:input obtained from STDIN as single unsigned short integer [4/4]
 +*:mbe0:sum variables declared and used appropriately in processing [4/4]
 +*:mbe0:carry variables declared and used appropriately in processing [4/4]
 +*:mbe0:processing output properly spaced and displayed to STDERR [4/4]
 +*:mbe0:final output displayed to STDOUT as packed individual digits [4/4]
 +*:mbe0:effective usage of fprintf() and fscanf() [4/4]
 +*:mbe0:runtime tests succeed [8/8]
 +*:mbe0:no negative compiler messages for code [4/4]
 +*:mbe0:code is pushed to lab46 repository [4/4]
 +</code>
haas/spring2017/cprog/projects/mbe0.1486419345.txt.gz · Last modified: 2017/02/06 22:15 by wedge