This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:fall2020:cprog:projects:cnv0 [2020/03/27 14:08] – external edit 127.0.0.1 | haas:fall2020:cprog:projects:cnv0 [2020/10/08 15:04] (current) – [Submission] wedge | ||
---|---|---|---|
Line 7: | Line 7: | ||
=====Objective===== | =====Objective===== | ||
- | To create a program that can calculate and determine the number of factor pairs (nary value) over a given range of numbers. | + | To create a program that can calculate and determine the number of factor pairs of a given number, starting with values composed of exactly 2 sets of factor pairs. |
=====Reading===== | =====Reading===== | ||
- | In [[https://lab46.g7n.org/_media/haas/the_c_book.pdf|"The C Book"]], please read through Chapter 6. | + | In "The C Book", please read through Chapter 8. |
+ | |||
+ | Review needed concepts in [[https://www.tutorialspoint.com/cprogramming/|this tutorial]] and also [[https:// | ||
=====Background===== | =====Background===== | ||
Line 87: | Line 89: | ||
Because there are 3 factor pairs, 12 would be considered an nary(3) value (or a tertiary number). | Because there are 3 factor pairs, 12 would be considered an nary(3) value (or a tertiary number). | ||
+ | |||
+ | =====grabit===== | ||
+ | There is a grabit for this project, which will provide you with some files pertinent for performing this project. | ||
+ | |||
+ | Run ' | ||
+ | |||
+ | =====Compiling===== | ||
+ | Since there is a provided Makefile in the project grabit, we can use that to compile, either regularly: | ||
+ | |||
+ | <cli> | ||
+ | yourpi: | ||
+ | </ | ||
+ | |||
+ | Or, with debugging support: | ||
+ | |||
+ | <cli> | ||
+ | yourpi: | ||
+ | </ | ||
=====Program===== | =====Program===== | ||
- | It is your task to write a program that, upon accepting various pieces of input from the user, computes the number of factor pairs of a given number | + | It is your task to write a program that, upon accepting various pieces of input from the user, computes the number of factor pairs of a given number, displaying |
=====Specifications===== | =====Specifications===== | ||
Line 97: | Line 117: | ||
* have consistent, well-defined indentation (no less than 4 spaces per level of indentation) | * have consistent, well-defined indentation (no less than 4 spaces per level of indentation) | ||
* all code within the same scope aligned to its indentation level | * all code within the same scope aligned to its indentation level | ||
- | * have proximal comments explaining your rationale and what is going on, throughout your code | + | * have proximal comments explaining your rationale |
- | * from the command-line, | + | * to STDERR, |
- | * argv[1]: N-ary value (how many factor pairs are we requiring; 1 for prime, 2 for secondary, 3 for tertiary, etc.); this should be stored and managed as an **unsigned char**. | + | * properly store this in a variable of type **unsigned |
- | * argv[2]: lower-bound | + | * immediately after the input, check to make sure the input number |
- | * argv[3]: upper-bound (where to stop processing, inclusive of the upper bound value); | + | * proceed to evaluate the input number, determining whether or not it is a secondary (nary(2)) |
- | * immediately after parameter processing, check to make sure the specified parameters are positive numbers. Any deviations should be displayed as error messages to STDERR: | + | * if it is, display to STDOUT |
- | * N-ary value must be between 1 and 16 (inclusive of 1 and 16) | + | * if it is not, display to STDOUT |
- | * on error display " | + | |
- | * lower bound must be between 2 and 40000 (inclusive of 2 and 40000) | + | |
- | * on error display " | + | |
- | * upper bound must be between | + | |
- | * on error display " | + | |
- | * on situation of lower bound being greater than upper bound, display | + | |
- | * proceed to evaluate the appropriate | + | |
- | * if it is, display | + | |
- | * if it is not, do not display | + | |
* using a single return statement at the conclusion of the code, return a 0 indicating successful operation | * using a single return statement at the conclusion of the code, return a 0 indicating successful operation | ||
- | * for all error results, use **exit()** instead; there should only be exactly ONE **return()** statement per function | ||
Some additional points of consideration: | Some additional points of consideration: | ||
Line 121: | Line 131: | ||
=====Execution===== | =====Execution===== | ||
- | ====Primary | + | ====Secondary |
<cli> | <cli> | ||
- | lab46: | + | yourpi: |
- | 11 13 17 19 23 | + | Enter a number: 6 |
- | lab46: | + | 6 is a secondary number |
+ | yourpi: | ||
</ | </ | ||
- | ====Secondary | + | ====Non-secondary |
<cli> | <cli> | ||
- | lab46: | + | yourpi: |
- | 4 6 8 9 10 | + | Enter a number: 7 |
- | lab46: | + | 7 is NOT a secondary number |
</ | </ | ||
- | ====Tertiary number (nary(3)) output==== | + | ====Additional outputs==== |
<cli> | <cli> | ||
- | lab46: | + | yourpi: |
- | 12, 16, 18, 20, 28, 32 | + | Enter a number: 8 |
- | lab46: | + | 8 is a secondary number |
+ | yourpi: | ||
+ | Enter a number: | ||
+ | 16 is NOT a secondary number | ||
+ | yourpi: | ||
+ | Enter a number: 21 | ||
+ | 21 is a secondary number | ||
+ | yourpi: | ||
</ | </ | ||
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. | ||
- | |||
- | =====Compiling===== | ||
- | As we have been doing all along, use the following options to gcc when compiling: | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | lab46: | ||
- | </ | ||
=====Reference===== | =====Reference===== | ||
- | In the CPROG public directory, inside | + | Copied as part of the grabit, inside |
<cli> | <cli> | ||
- | lab46: | + | yourpi: |
- | 4 6 8 9 10 14 15 21 22 25 26 27 33 34 35 38 39 | + | Enter a number: 6 |
- | lab46: | + | 6 is a secondary number |
+ | yourpi: | ||
</ | </ | ||
=====Verification===== | =====Verification===== | ||
- | In addition, I have also placed a **cnv0verify** script in that same subdirectory, | + | In addition, I have also placed a **cnv0verify** script in that same subdirectory, |
<cli> | <cli> | ||
- | lab46: | + | yourpi: |
- | ERROR CHECK | + | [ 1] you have: err, should be: err [ 2] you have: no, should be: no |
- | ================= | + | [ 3] you have: no, should be: |
- | invalid nary (0): ERROR: invalid nary value (0)! | + | [ 5] you have: no, should be: |
- | exit status: 1, should be: 1 | + | [ 7] you have: no, should be: |
- | - - - - - - - | + | [ 9] you have: yes, should be: yes [ 10] you have: yes, should be: yes |
- | invalid nary (17): ERROR: invalid nary value (17)! | + | [ 11] you have: no, should be: |
- | exit status: 1, should be: 1 | + | [ 13] you have: no, should be: |
- | - - - - - - - | + | [ 15] you have: yes, should be: yes [ 16] you have: no, should be: no |
- | invalid lower (1): ERROR: invalid lower bound (1)! | + | [ 17] you have: no, should be: no [ 18] you have: no, should be: no |
- | exit status: 2, should be: 2 | + | [ 19] you have: no, should be: no [ 20] you have: no, should be: no |
- | - - - - - - - | + | [ 21] you have: yes, should be: yes [ 22] you have: yes, should be: yes |
- | invalid lower (43100): ERROR: invalid lower bound (43100)! | + | [ 23] you have: no, should be: no [ 24] you have: no, should be: no |
- | exit status: 2, should be: 2 | + | [ 25] you have: yes, should be: yes [ 26] you have: yes, should be: yes |
- | - - - - - - - | + | [ 27] you have: yes, should be: yes [ 28] you have: no, should be: no |
- | invalid upper (0): ERROR: invalid upper bound (0)! | + | [ 29] you have: no, should be: no [ 30] you have: no, should be: no |
- | exit status: 3, should be: 3 | + | [ 31] you have: no, should be: no [ 32] you have: no, should be: no |
- | - - - - - - - | + | [ 33] you have: yes, should be: yes [ 34] you have: yes, should be: yes |
- | invalid upper (65501): ERROR: invalid upper bound (65501)! | + | [ 35] you have: yes, should be: yes [ 36] you have: no, should be: no |
- | exit status: 3, should be: 3 | + | yourpi: |
- | - - - - - - - | + | |
- | lower (300) bigger than upper (65): ERROR: lower bound (300) is larger than upper bound (65)! | + | |
- | exit status: 4, should be: 4 | + | |
- | - - - - - - - | + | |
- | Press ENTER to continue verification tests | + | |
- | nary( 1) | + | |
- | ======== | + | |
- | have: >23 29 31 < | + | |
- | need: >23 29 31 < | + | |
- | + | ||
- | nary( 2) | + | |
- | ======== | + | |
- | have: >21 22 25 26 27 33 34 35 < | + | |
- | need: >21 22 25 26 27 33 34 35 < | + | |
- | + | ||
- | nary( 3) | + | |
- | ======== | + | |
- | have: >20 28 32 < | + | |
- | need: > | + | |
- | + | ||
- | nary( 4) | + | |
- | ======== | + | |
- | have: > | + | |
- | need: >24 30 < | + | |
- | + | ||
- | nary( 5) | + | |
- | ======== | + | |
- | have: >36 < | + | |
- | need: >36 < | + | |
- | + | ||
- | lab46: | + | |
</ | </ | ||
Line 223: | Line 203: | ||
* Code must compile cleanly (no notes, warnings, nor errors) | * Code must compile cleanly (no notes, warnings, nor errors) | ||
* 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, to show scope and maximize readability | + | * Code must be nicely and consistently indented |
- | * Code must be well commented | + | * Code must be well commented |
* Do NOT double space your code. Group like statements together. | * Do NOT double space your code. Group like statements together. | ||
* Output Formatting (including spacing) of program must conform to the provided output (see above). | * Output Formatting (including spacing) of program must conform to the provided output (see above). | ||
- | * Track/ | + | * Track/ |
* Submit a copy of your source code to me using the **submit** tool. | * Submit a copy of your source code to me using the **submit** tool. | ||
Line 233: | Line 213: | ||
<cli> | <cli> | ||
- | $ submit | + | lab46: |
- | Submitting cprog project " | + | |
- | -> cnv0.c(OK) | + | |
- | + | ||
- | SUCCESSFULLY SUBMITTED | + | |
</ | </ | ||
+ | |||
+ | And make sure you get no error messages. | ||
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. | ||
Line 245: | Line 223: | ||
< | < | ||
- | 78:cnv0:final tally of results (78/78) | + | 91:cnv0:final tally of results (91/91) |
+ | *: | ||
*: | *: | ||
*: | *: | ||
Line 257: | Line 236: | ||
* Solutions not abiding by spirit of project will be subject to a 25% overall deduction | * Solutions not abiding by spirit of project will be subject to a 25% overall deduction | ||
* Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction | * Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction | ||
- | * Solutions not utilizing | + | * Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction |
* Solutions not organized and easy to read are subject to a 25% overall deduction | * Solutions not organized and easy to read are subject to a 25% overall deduction |