This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2019:c4eng:projects:mtf1 [2019/09/22 19:05] – [Sample run using addition] wedge | haas: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, | + | 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, |
+ | =====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 | ||
- | | + | * I will make an exception for the use of ' |
- | * properly store this in a variable of type (signed) | + | |
- | * check for a literal ' | + | * 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 ' |
+ | * 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 | + | * properly store this in a variable of type **unsigned |
- | * prompt for the endisg | + | * prompt for the ending |
- | * properly store this in a variable of type **unsigned | + | * properly store this in a variable of type **unsigned |
* prompt for the starting column (0-9) | * prompt for the starting column (0-9) | ||
- | * properly store this in a variable of type **unsigned | + | * properly store this in a variable of type **unsigned |
* prompt for the ending column (0-9) | * prompt for the ending column (0-9) | ||
- | * properly store this in a variable of type **unsigned | + | * properly store this in a variable of type **unsigned |
- | * 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 |
- | * 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/ | * display both row and column headers, in uniform fashion/ | ||
* 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, | ||
+ | * Only the table (headers/ | ||
+ | * For the math operations that are not associative, | ||
+ | * To display a ' | ||
+ | =====Compiling===== | ||
+ | As we have been doing all along, use the following options to gcc when compiling: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
=====Execution===== | =====Execution===== | ||
Line 67: | Line 85: | ||
Ending Column (0-9): 7 | Ending Column (0-9): 7 | ||
+ | 2 3 4 5 6 7 | + | 2 3 4 5 6 7 | ||
- | ---+------------------ | + | ---+------------------- |
5 | 7 8 9 10 11 12 | 5 | 7 8 9 10 11 12 | ||
6 | 8 9 10 11 12 13 | 6 | 8 9 10 11 12 13 | ||
Line 74: | Line 92: | ||
</ | </ | ||
+ | ====Sample run using subtraction==== | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | 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: | ||
+ | </ | ||
+ | |||
+ | ====Sample run using division==== | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 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: | ||
+ | </ | ||
+ | |||
+ | ====Sample run using remainder==== | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 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: | ||
+ | </ | ||
====Sample run with invalid operation given==== | ====Sample run with invalid operation given==== | ||
<cli> | <cli> | ||
lab46: | lab46: | ||
- | Which operation | + | Which operation: x |
- | ERROR: Must specify | + | ERROR: Must specify ' |
lab46: | lab46: | ||
</ | </ | ||
- | ====Sample run with invalid | + | ====Sample run with invalid |
<cli> | <cli> | ||
lab46: | lab46: | ||
- | Which operation | + | Which operation: + |
- | Row (0-9): 5 | + | Starting |
- | Starting Column | + | Ending |
- | Ending | + | ERROR: Starting |
- | ERROR: Starting | + | |
lab46: | lab46: | ||
</ | </ | ||
+ | |||
+ | =====Reference===== | ||
+ | In the C4ENG public directory, inside the **mtf1** subdirectory, | ||
=====Submission===== | =====Submission===== | ||
Line 125: | Line 197: | ||
*: | *: | ||
*: | *: | ||
- | *: | ||
*: | *: | ||
*:mtf1:no negative compiler messages for program [13/13] | *:mtf1:no negative compiler messages for program [13/13] |