User Tools

Site Tools


haas:fall2019:c4eng:projects:mtf1

Differences

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

Link to this comparison view

Next revision
Previous revision
haas:fall2019:c4eng:projects:mtf1 [2019/09/22 18:42] – created wedgehaas:fall2019:c4eng:projects:mtf1 [2019/10/01 12:07] (current) – [Specifications] wedge
Line 13: Line 13:
  
 =====Program===== =====Program=====
-It is your task to enhance the program you wrote last week (**mtf0**) that will use loops and other programming concepts learned this far to automate the display of entire mathematical operation tables (addition, subtraction, multiplication, or division; as indicated by the user). This information is potentially of value to some of your letter division efforts in the pctX projects.+It is your task to enhance the program you wrote last week (**mtf0**) that will use loops and other programming concepts learned this far to automate the display of entire mathematical operation tables (addition, subtraction, multiplication, division, or remainder; as indicated by the user). This information is potentially of value to some of your letter division efforts in the pctX projects.
  
 +=====Specifications=====
 Your program should: Your program should:
 +
   * have valid, descriptive variable names of length //no shorter than// 4 symbols   * have valid, descriptive variable names of length //no shorter than// 4 symbols
-  * prompt the user for the operation ('+' for addition, '-' for subtraction, '*' for multiplication, and '/' for division) +    * I will make an exception for the use of 'row' 
-    * properly store this in a variable of type (signed) **char** +  * prompt the user for the operation ('+' for addition, '-' for subtraction, '*' for multiplication, '/' for division, and '%' for remainder
-    * check for a literal '+', '-', '*', or '/' symbol to determine operation to perform +    * properly store this in a variable of type **char** 
-      * if invalid input, display an error and exit with a non-zero value+    * check for a literal '+', '-', '*', '/', or '%' symbol to determine operation to perform 
 +      * if invalid input, display an error and exit with a non-zero value of 1
   * prompt for the starting row (0-9)   * prompt for the starting row (0-9)
-    * properly store this in a variable of type **unsigned short int** +    * properly store this in a variable of type **unsigned char** 
-  * prompt for the endisg row (0-9) +  * prompt for the ending row (0-9) 
-    * properly store this in a variable of type **unsigned short int**+    * properly store this in a variable of type **unsigned char**
   * prompt for the starting column (0-9)   * prompt for the starting column (0-9)
-    * properly store this in a variable of type **unsigned short int**+    * properly store this in a variable of type **unsigned char**
   * prompt for the ending column (0-9)   * prompt for the ending column (0-9)
-    * properly store this in a variable of type **unsigned short int** +    * properly store this in a variable of type **unsigned char** 
-  * check to make sure starting column, row is less than or equal to ending column, row +  * check to make sure starting column, row is less than or equal to the corresponding ending column, row 
-    * if not, display an error (to STDERR) and exit with non-zero status code+    * if not, display an error (to STDERR) and exit with non-zero status code of 2 (for row) or 3 (for column)
   * display the table, performing the indicated operation   * display the table, performing the indicated operation
 +    * display both row and column headers, in uniform fashion/formatting throughout
     * display each numerical value in organized, consistent fashion, assuming two-digit numbers     * display each numerical value in organized, consistent fashion, assuming two-digit numbers
   * 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
 +
 +Some additional points of consideration:
 +  * Note that the driving variables in your loops need to be at least of type **short int**, otherwise you may get a warning when you compile it.
 +  * Some results may be negative, allow for the display of negative values in your output.
 +  * with certain (not all) operations on certain values, you might end up with a mathematically impossible result. In these cases, check for and avoid performing the computation, instead displaying "NA" in its place.
 +  * Only the table (headers/dividers included)should be output to STDOUT. Everything else (the input prompts) should be displayed to STDERR.
 +  * For the math operations that are not associative, the row value is the one to be operated against (ie result=row-col).
 +  * To display a '%' character using fprintf, repeat it: %%. That will cancel the otherwise substitutive properties of the symbol in the context of fprintf.
 +=====Compiling=====
 +As we have been doing all along, use the following options to gcc when compiling:
 +
 +<cli>
 +lab46:~/src/c4eng/mtf1$ gcc -Wall --std=gnu99 -o mtf1 mtf1.c
 +lab46:~/src/c4eng/mtf1$ 
 +</cli>
  
 =====Execution===== =====Execution=====
Line 40: Line 59:
 <cli> <cli>
 lab46:~/src/c4eng/mtf1$ ./mtf1 lab46:~/src/c4eng/mtf1$ ./mtf1
-Which operation ('+' or '*'): * +Which operation: * 
-Row (0-9): 4+Starting Row (0-9): 4 
 +Ending Row (0-9): 8
 Starting Column (0-9): 1 Starting Column (0-9): 1
 Ending Column (0-9): 5 Ending Column (0-9): 5
- 4  8 12 16 20+ * |  1  2  3   5 
 +---+---------------- 
 + 4 |   8 12 16 20 
 + 5 |  5 10 15 20 25 
 + 6 |  6 12 18 24 30 
 + 7 |  7 14 21 28 35 
 + 8 |  8 16 24 32 40
 lab46:~/src/c4eng/mtf1$  lab46:~/src/c4eng/mtf1$ 
 </cli> </cli>
Line 53: Line 79:
 <cli> <cli>
 lab46:~/src/c4eng/mtf1$ ./mtf1 lab46:~/src/c4eng/mtf1$ ./mtf1
-Which operation ('+' or '*'): + +Which operation: + 
-Row (0-9): 5+Starting Row (0-9): 5 
 +Ending Row (0-9): 7
 Starting Column (0-9): 2 Starting Column (0-9): 2
 Ending Column (0-9): 7 Ending Column (0-9): 7
- 5  8  9 10 11 12+ + |  2  3  4   
 +---+------------------- 
 + 5 |   8  9 10 11 12 
 + 6 |  8  9 10 11 12 13 
 + 7 |  9 10 11 12 13 14
 lab46:~/src/c4eng/mtf1$  lab46:~/src/c4eng/mtf1$ 
 </cli> </cli>
  
 +====Sample run using subtraction====
 +
 +<cli>
 +lab46:~/src/c4eng/mtf1$ ./mtf1
 +Which operation: -
 +Starting Row (0-9): 2
 +Ending Row (0-9): 6
 +Starting Column (0-9): 1
 +Ending Column (0-9): 4
 + - |  1  2  3  4
 +---+-------------
 + 2 |  1  0 -1 -2
 + 3 |  2  1  0 -1
 + 4 |  3  2  1  0
 + 5 |  4  3  2  1
 + 6 |  5  4  3  2
 +lab46:~/src/c4eng/mtf1$ 
 +</cli>
 +
 +====Sample run using division====
 +<cli>
 +lab46:~/src/c4eng/mtf1$ ./mtf1
 +Which operation: /
 +Starting Row (0-9): 6
 +Ending Row (0-9): 9
 +Starting Column (0-9): 0
 +Ending Column (0-9): 4
 + / |  0  1  2  3  4
 +---+----------------
 + 6 | NA  6  3  2  1
 + 7 | NA  7  3  2  1
 + 8 | NA  8  4  2  2
 + 9 | NA  9  4  3  2
 +lab46:~/src/c4eng/mtf1$ 
 +</cli>
 +
 +====Sample run using remainder====
 +<cli>
 +lab46:~/src/c4eng/mtf1$ ./mtf1
 +Which operation: %
 +Starting Row (0-9): 5
 +Ending Row (0-9): 8
 +Starting Column (0-9): 1
 +Ending Column (0-9): 5
 + % |  1  2  3  4  5
 +---+----------------
 + 5 |  0  1  2  1  0
 + 6 |  0  0  0  2  1
 + 7 |  0  1  1  3  2
 + 8 |  0  0  2  0  3
 +lab46:~/src/c4eng/mtf1$ 
 +</cli>
 ====Sample run with invalid operation given==== ====Sample run with invalid operation given====
 <cli> <cli>
 lab46:~/src/c4eng/mtf1$ ./mtf1 lab46:~/src/c4eng/mtf1$ ./mtf1
-Which operation ('+' or '*'): x +Which operation: x 
-ERROR: Must specify either '+' or '*'.+ERROR: Must specify '+', '-', '*', '/', or '%'.
 lab46:~/src/c4eng/mtf1$  lab46:~/src/c4eng/mtf1$ 
 </cli> </cli>
  
-====Sample run with invalid column configuration====+====Sample run with invalid row configuration====
 <cli> <cli>
 lab46:~/src/c4eng/mtf1$ ./mtf1 lab46:~/src/c4eng/mtf1$ ./mtf1
-Which operation ('+' or '*'): + +Which operation: + 
-Row (0-9): 5 +Starting Row (0-9): 7 
-Starting Column (0-9): 7 +Ending Row (0-9): 2 
-Ending Column (0-9): 2 +ERROR: Starting row is greater than ending row
-ERROR: Starting column is greater than ending column+
 lab46:~/src/c4eng/mtf1$  lab46:~/src/c4eng/mtf1$ 
 </cli> </cli>
  
 +
 +=====Reference=====
 +In the C4ENG public directory, inside the **mtf1** subdirectory, will be a copy of my implementation (in executable form), which abides by the project specifications. Please compare its output against that of your implementation.
  
 =====Submission===== =====Submission=====
Line 112: Line 197:
 *:mtf1:correct variable types and name lengths used [13/13] *:mtf1:correct variable types and name lengths used [13/13]
 *:mtf1:proper output formatting per specifications [13/13] *:mtf1:proper output formatting per specifications [13/13]
-*:mtf1:submission conforms to project specifications [13/13] 
 *:mtf1:runtime tests of submitted program succeed [13/13] *:mtf1:runtime tests of submitted program succeed [13/13]
 *:mtf1:no negative compiler messages for program [13/13] *:mtf1:no negative compiler messages for program [13/13]
haas/fall2019/c4eng/projects/mtf1.1569177720.txt.gz · Last modified: 2019/09/22 18:42 by wedge