This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:fall2022:cprog:projects:sof0 [2021/09/03 14:42] – created - external edit 127.0.0.1 | haas:fall2022:cprog:projects:sof0 [2022/09/18 13:26] (current) – [RUBRIC] wedge | ||
---|---|---|---|
Line 4: | Line 4: | ||
</ | </ | ||
- | ======Project: MENTAL MATH - SQUARES OF FIVES (sof0)====== | + | ======PROJECT: MENTAL MATH - SQUARES OF FIVE (SOF0)====== |
+ | =====OBJECTIVE===== | ||
+ | To begin our exploration of programming, | ||
- | =====Objective===== | + | =====GRABIT===== |
- | To implement a programmatic solution (ie simulation) of a real life process- the mental math trick of computing the square of any number ending | + | To assist |
- | + | ||
- | =====Scope===== | + | |
- | 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 | + | |
- | + | ||
- | =====Background===== | + | |
- | Mental Math constitutes an intersection of mental techniques and math- instead of utilizing a purely math-only solution, textual manipulations or simplifications in the computational process may take place enabling an individual to, once having learned the process, solve such problems in their head, and typically without the use of a calculating device. | + | |
- | + | ||
- | The process in this case is one of numeric manipulation and simple (reduced) multiplication. To wit: | + | |
- | + | ||
- | ====Squaring a value==== | + | |
- | Squaring is essentially multiplying a number by itself- | + | |
- | + | ||
- | * 5 squared (5< | + | |
- | * 8 squared (8< | + | |
- | + | ||
- | While not outwardly a difficult procedure, the nature of multiplying multiple digit numbers in your head can quickly result in more steps (and more steps means more time, if doing things the traditional way). | + | |
- | + | ||
- | Finding a shortcut through this process enables it to remain solidly within the realm of mental math, and makes for a good algorithm to practice implementing | + | |
- | + | ||
- | This particular trick relies on a subset of the squares: those ending with a 5 (a five in the ones place). | + | |
- | + | ||
- | The implementational scope of this trick will be just values of one-, two-, and three-digits ending with 5: | + | |
- | + | ||
- | | + | |
- | | + | |
- | | + | |
- | * 35 | + | |
- | * 45 | + | |
- | * 55 | + | |
- | * 65 | + | |
- | * 75 | + | |
- | * 85 | + | |
- | * 95 | + | |
- | * 105 | + | |
- | * 115 | + | |
- | * 125 | + | |
- | | + | |
- | * 235 | + | |
- | * 245 | + | |
- | * ... | + | |
- | * 485 | + | |
- | * 495 | + | |
- | * 505 | + | |
- | * ... | + | |
- | * 995 | + | |
- | + | ||
- | + | ||
- | ====Squaring values ending with 5==== | + | |
- | The trick here is two-fold. First, we separate the one's place 5 from the rest of the number (which can be accomplished in our mind's easily enough, but on the computer we must resort | + | |
- | + | ||
- | We then take that isolated five and square | + | |
- | + | ||
- | Next, we take the remaining digits of the original value, and multiply it by its increment: | + | |
- | + | ||
- | * 1's increment (1+1) is 2, so 1*2 | + | |
- | * 2's increment (2+1) is 3, so 2*3 | + | |
- | * 3's increment (3+1) is 4, so 3*4 | + | |
- | * 4's increment (4+1) is 5, so 4*5 | + | |
- | * ... | + | |
- | * 9's increment (9+1) is 10, so 9*10 | + | |
- | + | ||
- | We take this result and append the 25 after it. | + | |
- | + | ||
- | For example: | + | |
- | + | ||
- | < | + | |
- | 15 * 15 = 1*(1+1) 5*5 | + | |
- | = 1*2 5*5 | + | |
- | = 2 25 | + | |
- | = 225 | + | |
- | </ | + | |
- | + | ||
- | and: | + | |
- | + | ||
- | < | + | |
- | 75 * 75 = 7*(7+1) 5*5 | + | |
- | = 7*8 5*5 | + | |
- | = 56 25 | + | |
- | = 5625 | + | |
- | </ | + | |
- | + | ||
- | For a single digit number like 5, when you take the 5 away, what do you get? **ZERO**. Zero times anything is zero, so the result is 0 25, or 25 (ie this process still works). | + | |
- | + | ||
- | For three digit numbers like 105, we have 10, and its increment is 11, so 10 x 11 = 110. | + | |
- | + | ||
- | < | + | |
- | 105 * 105 = 10*(10+1) 5*5 | + | |
- | = 10*11 5*5 | + | |
- | = 110 25 | + | |
- | = 11025 | + | |
- | </ | + | |
- | =====Program===== | + | |
- | It is your task to write the program that will use the above method to compute the square of the input value ending | + | |
- | + | ||
- | Your program should: | + | |
- | * prompt the user for the number (input) | + | |
- | * input number as an unsigned short integer | + | |
- | * perform the task (process) | + | |
- | * isolate one's digit mathematically, | + | |
- | * isolate remaining digits mathematically, | + | |
- | * perform the algorithm on the two pieces, storing their results in two separate variables (of type unsigned short int) | + | |
- | * display the final value (output) | + | |
- | * display the beginning and ending parts together (but stored in separate variables) | + | |
- | * 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). | + | |
- | * because we have not officially learned how to do selection/ | + | |
- | + | ||
- | =====Execution===== | + | |
<cli> | <cli> | ||
- | yourpi: | + | lab46: |
- | Enter value: 75 | + | |
- | 75 x 75 = | + | |
- | yourpi: | + | |
</ | </ | ||
- | The execution | + | =====OVERVIEW===== |
+ | Your task is to write a program that performs the mental math technique | ||
- | Note how the two " | + | Contributing to project documentation is also a core part of this project. If from reading |
- | Similarly, | + | You want the project documentation to provide you (as if coming in with no awareness of the project) with sufficient information so as to allow you to proceed. Asking questions on the discord is a great way of getting more information that you can use to add content. |
+ | =====EDIT===== | ||
+ | You will want to go [[/ | ||
- | < | + | * [[/notes/cprog/fall2022/ |
- | yourpi: | + | |
- | Enter value: 105 | + | |
- | 105 x 105 = 11025 | + | |
- | yourpi:~/src/SEMESTER/cprog/sof0$ | + | |
- | </cli> | + | |
- | The ' | + | {{page> |
- | If you'd like to verify | + | =====SUBMISSION===== |
+ | To be successful | ||
- | <cli> | + | * Project must be submit on time, by the deadline. |
- | yourpi: | + | * Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline. |
- | 11025 | + | * All code must compile cleanly (no warnings or errors) |
- | yourpi: | + | * Compile with the **-Wall** and **--std=gnu18** compiler flags |
- | </cli> | + | * all requested functionality |
+ | * Executed programs must display in a manner similar to provided output | ||
+ | * output | ||
+ | * Processing must be correct based on input given and output requested | ||
+ | * Output, if applicable, must be correct based on values input | ||
+ | * Code must be nicely and consistently indented | ||
+ | * Code must be consistently written, to strive for readability from having a consistent style throughout | ||
+ | * Code must be commented | ||
+ | * Any "to be implemented" | ||
+ | * these " | ||
+ | * Sufficient | ||
+ | * No global variables (without instructor approval), no goto statements, no calling of main()! | ||
+ | * Track/version the source code in your lab46 semester repository | ||
+ | * Submit | ||
- | What we are doing here is two-fold: | + | ====Submit Tool Usage==== |
- | + | Let' | |
- | | + | submit, you would do the following |
- | | + | uom0.c): |
- | + | ||
- | Similarly, if we were to eliminate STDOUT entirely (for verifying STDERR output): | + | |
<cli> | <cli> | ||
- | yourpi: | + | lab46: |
- | Enter value: 75 | + | |
- | 75 x 75 = yourpi: | + | |
</ | </ | ||
- | What we are doing here: | + | 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. | ||
- | * We are using command-line I/O redirection to redirect STDOUT (which is bound to file descriptor #1) to the system bit-bucket. | + | =====RUBRIC===== |
- | + | I'll be evaluating | |
- | =====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: | + | |
- | + | ||
- | < | + | |
- | lab46: | + | |
- | </ | + | |
- | + | ||
- | If all aligns, you will see this: | + | |
- | + | ||
- | < | + | |
- | ================================================== | + | |
- | = CPROG sof0 project output validation tool = | + | |
- | ================================================== | + | |
- | sof0 checksum is: 822a47fb2a45845500b6c10878045bd5 | + | |
- | your checksum is: 822a47fb2a45845500b6c10878045bd5 | + | |
- | ================================================== | + | |
- | verification: | + | |
- | ================================================== | + | |
- | </ | + | |
- | + | ||
- | If something is off, your checksum will not match the sof0 checksum, and verification will instead say " | + | |
- | + | ||
- | < | + | |
- | ================================================== | + | |
- | = CPROG sof0 project output validation tool = | + | |
- | ================================================== | + | |
- | sof0 checksum is: 822a47fb2a45845500b6c10878045bd5 | + | |
- | your checksum is: 92af264c86823a61529948caaeac53e0 | + | |
- | ================================================== | + | |
- | verification: | + | |
- | ================================================== | + | |
- | </ | + | |
- | =====Questions / Food for Thought===== | + | |
- | These are things I'd like you to contemplate, | + | |
- | + | ||
- | * 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? | + | |
- | + | ||
- | =====Review of Compiling/ | + | |
- | Just to review the compilation/ | + | |
- | + | ||
- | If compiling | + | |
- | + | ||
- | < | + | |
- | lab46: | + | |
- | lab46: | + | |
- | </ | + | |
- | + | ||
- | If compiling on your pi system: | + | |
- | + | ||
- | < | + | |
- | yourpi: | + | |
- | yourpi: | + | |
- | </ | + | |
- | + | ||
- | Assuming there are no syntax errors or warnings, and everything compiled correctly, you should just get your prompt back. In the event of problems, the compiler will be sure to tell you about them. | + | |
- | + | ||
- | Conceptually, | + | |
< | < | ||
- | gcc -Wall --std=gnu99 -funsigned-char -o BINARY_FILE SOURCE_FILE | + | 39: |
+ | *:sof0:used grabit to obtain project by the Sunday prior to duedate [6/6] | ||
+ | *: | ||
+ | *: | ||
+ | *:sof0:code tracked in lab46 semester repo [6/6] | ||
</ | </ | ||
- | The BINARY_FILE comes **immediately after** | + | ===Pertaining to the collaborative authoring of project documentation=== |
- | The **-Wall** (treat all warnings as errors, increase general verbosity about warnings) and **< | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | To execute your binary, we need to specify a path to it, so we use **./**, which basically references the current directory. | + | ===Additionally=== |
- | + | ||
- | On lab46: | + | |
- | + | ||
- | < | + | |
- | lab46: | + | |
- | </ | + | |
- | + | ||
- | On your pi system: | + | |
- | + | ||
- | < | + | |
- | yourpi: | + | |
- | </ | + | |
- | + | ||
- | =====Submission===== | + | |
- | To successfully complete this project, the following criteria must be met: | + | |
- | + | ||
- | * Code must compile cleanly (no warnings or errors) | + | |
- | * Use the **-Wall** and **< | + | |
- | * Executed program must display a total of 2 lines, one for input, one for output. | + | |
- | * The computed number must be output to STDOUT | + | |
- | * Any supporting output must be output to STDERR | + | |
- | * Output is formatted in the manner in the sample above | + | |
- | * Output must be correct, and match the form given in the sample output above. | + | |
- | * Code must be nicely and consistently indented | + | |
- | * Code must implement solution using the mental math technique described above | + | |
- | * Code must be commented | + | |
- | * have a properly filled-out comment banner at the top | + | |
- | * have at least 20% of your program consist of **< | + | |
- | * Output Formatting (including spacing) of program must conform to the provided output (see above). | + | |
- | * Track/ | + | |
- | * 33% late penalty per day after deadline | + | |
- | * Program is submit in a C source file called **sof0.c** and compiles without warning, note, nor error with gcc on lab46. | + | |
- | * Submit a copy of your source code to me using the **submit** tool. | + | |
- | + | ||
- | To submit this program to me using the **submit** tool, run the following command at your lab46 prompt: | + | |
- | + | ||
- | < | + | |
- | lab46: | + | |
- | </ | + | |
- | + | ||
- | 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. | + | |
- | + | ||
- | I'll be looking for the following: | + | |
- | + | ||
- | < | + | |
- | 39: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *:sof0:code implements solution using relevant concepts [3/3] | + | |
- | *:sof0:code updates committed/ | + | |
- | *:sof0:code uses correct variable types and name lengths [3/3] | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | </ | + | |
- | Additionally: | + | |
- | | + | * Solutions |
- | * Solutions not utilizing descriptive why and how **COMMENTS** | + | * Solutions not utilizing |
- | * Solutions not utilizing | + | * Solutions |
- | * Solutions | + |