User Tools

Site Tools


haas:spring2017:cprog:projects:sof0

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:sof0 [2017/01/24 14:29] – [Execution] wedgehaas:spring2017:cprog:projects:sof0 [2017/01/31 21:25] (current) – [Program] wedge
Line 15: Line 15:
 The allure of using (and learning) a programming language is to be able to effectively use it to solve problems, which in and of themselves are simulations of some process we can do in "the real world". The allure of using (and learning) a programming language is to be able to effectively use it to solve problems, which in and of themselves are simulations of some process we can do in "the real world".
  
-In this case, we will be writing a program which will implement the mental math techniques for computing the square of any two-digit number that ends with 5.+In this case, we will be writing a program which will implement the mental math techniques for computing the square of any one, two-, or three-digit number that ends with 5.
  
 =====Background===== =====Background=====
Line 118: Line 118:
     * display the resulting number to STDOUT (right-justified in a space supporting the largest possible value -- see output example below)     * display the resulting number to STDOUT (right-justified in a space supporting the largest possible value -- see output example below)
     * display any supporting text to STDERR (display of source values left-justified in a space supporting 3-digit values -- see output example below).     * display any supporting text to STDERR (display of source values left-justified in a space supporting 3-digit values -- see output example below).
 +  * because we have not officially learned how to do selection/have the computer react to conditions, please implement with the assumption that the user will ALWAYS input a correct value. Do not worry about having to check for invalid or illegal input values (I will not be checking for such when I evaluate your project).
 =====Execution===== =====Execution=====
  
Line 141: Line 142:
  
 The 'x' and '=' padding persists, but because we're squaring a 3-digit value vs. a 2-digit value, we occupy the entire allocated space on the screen. The 'x' and '=' padding persists, but because we're squaring a 3-digit value vs. a 2-digit value, we occupy the entire allocated space on the screen.
 +
 +If you'd like to verify successful output to STDOUT/STDERR, you can perform the following tests. First, verify that the answer (and ONLY the answer), is being sent to STDOUT -- we do this by eliminating STDERR entirely:
 +
 +<cli>
 +lab46:~/src/cprog/sof0$ ./sof0 2> /dev/null <<< 105
 + 11025
 +lab46:~/src/cprog/sof0$ 
 +</cli>
 +
 +What we are doing here is two-fold:
 +
 +  * We are using command-line I/O redirection to redirect STDERR (which is bound to file descriptor #2) to the system bit-bucket.
 +  * We are "redirecting" STDIN using a **here string**, providing the program's input of **105** right on the command-line at time of execution.
 +
 +Similarly, if we were to eliminate STDOUT entirely (for verifying STDERR output):
 +
 +<cli>
 +lab46:~/src/cprog/sof0$ ./sof0 1> /dev/null
 +Enter value: 75
 +75  x 75  = lab46:~/src/cprog/sof0$ 
 +</cli>
 +
 +What we are doing here:
 +
 +  * We are using command-line I/O redirection to redirect STDOUT (which is bound to file descriptor #1) to the system bit-bucket.
 +
 +=====Verification=====
 +One of the tests I will perform for output compliance of your code will involve comparing your program's output against a range of input values, to see if they all output in conformance with project specifications.
 +
 +I will make use of a checksum to verify exactness.
 +
 +You will need to run this from your sof0 project directory with a compiled and operational binary by the name of **sof0**.
 +
 +You can check your project by typing in the following at the prompt:
 +
 +<cli>
 +lab46:~/src/cprog/sof0$ pchk cprog sof0
 +</cli>
 +
 +If all aligns, you will see this:
 +
 +<cli>
 +==================================================
 +=   CPROG sof0 project output validation tool    =
 +==================================================
 +sof0 checksum is: 822a47fb2a45845500b6c10878045bd5
 +your checksum is: 822a47fb2a45845500b6c10878045bd5
 +==================================================
 +    verification: SUCCESS!
 +==================================================
 +</cli>
 +
 +If something is off, your checksum will not match the sof0 checksum, and verification will instead say "**MISMATCH**", like follows (note that a mismatched checksum can be anything, and likely not what is seen in this example):
 +
 +<cli>
 +==================================================
 +=   CPROG sof0 project output validation tool    =
 +==================================================
 +sof0 checksum is: 822a47fb2a45845500b6c10878045bd5
 +your checksum is: 92af264c86823a61529948caaeac53e0
 +==================================================
 +    verification: MISMATCH
 +==================================================
 +</cli>
 +=====Questions / Food for Thought=====
 +These are things I'd like you to contemplate, even use as potential material on your weekly journal entry. The more you think about and understand the problem, the better your ability to solve it and other problems.
 +
 +  * Why/how does this trick work for 1-digit numbers?
 +  * Considering our 1-, 2-, and 3-digit domain restriction for this project, how many candidate values are there for input?
 +  * What is the smallest input value?
 +  * What is the largest input value?
 +  * How many input values are there that end in **5**?
 +  * What is the largest square that can be calculated given the project input restrictions?
 +  * How many digits is the largest square?
 +  * How can knowing how many digits the largest square is help you implement your solution?
 =====Submission===== =====Submission=====
 To successfully complete this project, the following criteria must be met: To successfully complete this project, the following criteria must be met:
haas/spring2017/cprog/projects/sof0.1485268144.txt.gz · Last modified: 2017/01/24 14:29 by wedge