User Tools

Site Tools


Sidebar

projects

wcp1 (due 20220824)
ntr0 (due 20220831)
pct1 (bonus; due 20220831)
uom0 (due 20220831)
wcp2 (due 20220831)
pct2 (due 20220907)
pct3 (bonus; due 20220907)
rle0 (due 20220907)
wcp3 (due 20220907)
bdb0 (due 20220914)
wcp4 (due 20220914)
pct4 (due 20220915)
cnv0 (due 20220921)
wcp5 (due 20220921)
pct5 (bonus; due 20220922)
gfo0 (due 20220928)
lmr0 (due 20220928)
wcp6 (due 20220928)
pct6 (due 20220929)
pct7 (bonus; due 20221005)
rle1 (due 20221005)
wcp7 (due 20221005)
bwp1 (bonus; due 20221019)
pct8 (due 20221019)
wcp8 (due 20221019)
cnv1 (due 20221020)
pct9 (bonus; due 20221026)
wcp9 (due 20221026)
lmr1 (due 20221027)
gfo1 (due 20221102)
pctA (due 20221102)
wcpA (due 20221102)
rle2 (due 20221104)
pctB (bonus; due 20221109)
wcpB (due 20221109)
cnv2 (due 20221110)
pctC (due 20221116)
wcpC (due 20221116)
lmr2 (due 20221117)
bwp2 (bonus; due 20221201)
pctD (bonus; due 20221201)
wcpD (bonus; due 20221201)
pctE (bonus; due 20221207)
wcpE (bonus; due 20221207)
gfo2 (due 20221208)
EoCE (due 20221219)
haas:fall2022:discrete:projects:mtf1

Corning Community College

CSCS2330 Discrete Structures

Project: MATH TABLE FUN - MULTIBASE (mtf1)

Errata

Any changes that have been made.

  • Revision #: <description> (DATESTAMP)

Objective

To continue exploring your number base/number representation skills in implementing an multibase addition, subtraction, multiplication, division, or remainder table generating program.

Program

Write a program that generates a table:

  • argv[1] is the base specifier (2-36, default is 10)
  • argv[2] is an optional upper bound (default is base-1)
  • argv[3] is an optional lower bound (default is 1)
  • using getenv(3), check for a variable named MTF1_OPER
    • if it exists, check it for the mathematical operation to perform, one of '+', '-', '*', '/', or '%'
    • if it doesn't exist, default to multiplication
    • if it exists and doesn't contain a valid symbol, display an error and exit
  • for some operations, the result violates the properties of mathematics. In the case of such invalid results, display “NA” instead of a number (within the same fixed/formatted spacing)
  • for the non-associative operations, the variable driving the individual rows should be the one operated on (ie result = row - col)

Program Output

Default, no options or settings alterations

lab46:~/src/discrete/mtf1$ ./mtf1
      1  2  3  4  5  6  7  8  9 
  [*]--------------------------- 
 1 |  1  2  3  4  5  6  7  8  9
 2 |  2  4  6  8 10 12 14 16 18
 3 |  3  6  9 12 15 18 21 24 27
 4 |  4  8 12 16 20 24 28 32 36
 5 |  5 10 15 20 25 30 35 40 45
 6 |  6 12 18 24 30 36 42 48 54
 7 |  7 14 21 28 35 42 49 56 63
 8 |  8 16 24 32 40 48 56 64 72
 9 |  9 18 27 36 45 54 63 72 81

Altering the operation to perform (addition)

lab46:~/src/discrete/mtf1$ MTF1_OPER="+" ./mtf1
      1  2  3  4  5  6  7  8  9 
  [+]--------------------------- 
 1 |  2  3  4  5  6  7  8  9 10
 2 |  3  4  5  6  7  8  9 10 11
 3 |  4  5  6  7  8  9 10 11 12
 4 |  5  6  7  8  9 10 11 12 13
 5 |  6  7  8  9 10 11 12 13 14
 6 |  7  8  9 10 11 12 13 14 15
 7 |  8  9 10 11 12 13 14 15 16
 8 |  9 10 11 12 13 14 15 16 17
 9 | 10 11 12 13 14 15 16 17 18

Subtraction

lab46:~/src/discrete/mtf1$ MTF1_OPER="-" ./mtf1 7
      1  2  3  4  5  6 
  [-]------------------ 
 1 |  0 -1 -2 -3 -4 -5
 2 |  1  0 -1 -2 -3 -4
 3 |  2  1  0 -1 -2 -3
 4 |  3  2  1  0 -1 -2
 5 |  4  3  2  1  0 -1
 6 |  5  4  3  2  1  0

Division

lab46:~/src/discrete/mtf1$ MTF1_OPER="/" ./mtf1 16
      1  2  3  4  5  6  7  8  9  A  B  C  D  E  F 
  [/]--------------------------------------------- 
 1 |  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 2 |  2  1  0  0  0  0  0  0  0  0  0  0  0  0  0
 3 |  3  1  1  0  0  0  0  0  0  0  0  0  0  0  0
 4 |  4  2  1  1  0  0  0  0  0  0  0  0  0  0  0
 5 |  5  2  1  1  1  0  0  0  0  0  0  0  0  0  0
 6 |  6  3  2  1  1  1  0  0  0  0  0  0  0  0  0
 7 |  7  3  2  1  1  1  1  0  0  0  0  0  0  0  0
 8 |  8  4  2  2  1  1  1  1  0  0  0  0  0  0  0
 9 |  9  4  3  2  1  1  1  1  1  0  0  0  0  0  0
 A |  A  5  3  2  2  1  1  1  1  1  0  0  0  0  0
 B |  B  5  3  2  2  1  1  1  1  1  1  0  0  0  0
 C |  C  6  4  3  2  2  1  1  1  1  1  1  0  0  0
 D |  D  6  4  3  2  2  1  1  1  1  1  1  1  0  0
 E |  E  7  4  3  2  2  2  1  1  1  1  1  1  1  0
 F |  F  7  5  3  3  2  2  1  1  1  1  1  1  1  1

Remainder

lab46:~/src/discrete/mtf1$ MTF1_OPER="%" ./mtf1 9
      1  2  3  4  5  6  7  8 
  [%]------------------------ 
 1 |  0  1  1  1  1  1  1  1
 2 |  0  0  2  2  2  2  2  2
 3 |  0  1  0  3  3  3  3  3
 4 |  0  0  1  0  4  4  4  4
 5 |  0  1  2  1  0  5  5  5
 6 |  0  0  0  2  1  0  6  6
 7 |  0  1  1  3  2  1  0  7
 8 |  0  0  2  0  3  2  1  0

Altering the base

lab46:~/src/discrete/mtf1$ ./mtf1 8
      1  2  3  4  5  6  7 
  [*]--------------------- 
 1 |  1  2  3  4  5  6  7
 2 |  2  4  6 10 12 14 16
 3 |  3  6 11 14 17 22 25
 4 |  4 10 14 20 24 30 34
 5 |  5 12 17 24 31 36 43
 6 |  6 14 22 30 36 44 52
 7 |  7 16 25 34 43 52 61

Altering the base, extending the upper bound

lab46:~/src/discrete/mtf1$ ./mtf1 12 13
        1   2   3   4   5   6   7   8   9   A   B  10  11 
   [*]---------------------------------------------------- 
  1 |   1   2   3   4   5   6   7   8   9   A   B  10  11
  2 |   2   4   6   8   A  10  12  14  16  18  1A  20  22
  3 |   3   6   9  10  13  16  19  20  23  26  29  30  33
  4 |   4   8  10  14  18  20  24  28  30  34  38  40  44
  5 |   5   A  13  18  21  26  2B  34  39  42  47  50  55
  6 |   6  10  16  20  26  30  36  40  46  50  56  60  66
  7 |   7  12  19  24  2B  36  41  48  53  5A  65  70  77
  8 |   8  14  20  28  34  40  48  54  60  68  74  80  88
  9 |   9  16  23  30  39  46  53  60  69  76  83  90  99
  A |   A  18  26  34  42  50  5A  68  76  84  92  A0  AA
  B |   B  1A  29  38  47  56  65  74  83  92  A1  B0  BB
 10 |  10  20  30  40  50  60  70  80  90  A0  B0 100 110
 11 |  11  22  33  44  55  66  77  88  99  AA  BB 110 121

All of that, plus lower bound

lab46:~/src/discrete/mtf1$ ./mtf1 13 8 2
      2  3  4  5  6  7  8 
  [*]--------------------- 
 2 |  4  6  8  A  C 11 13
 3 |  6  9  C 12 15 18 1B
 4 |  8  C 13 17 1B 22 26
 5 |  A 12 17 1C 24 29 31
 6 |  C 15 1B 24 2A 33 39
 7 | 11 18 22 29 33 3A 44
 8 | 13 1B 26 31 39 44 4C

Spacing, formatting, and presentation are centrally important. I want those headers and headings, and dividing lines. Your output should match my output (all to STDOUT).

An issue you might run into is how much space will you have to allocate (you want it universal for the display of the entire table). For that, I say determine the length of the maximum value being output (ie the bottom-most right value). That value’s length should then influence all the other output in the table.

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
    • Use the -Wall and –std=gnu99 flags when compiling.
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must utilize the algorithm/approach presented above
  • Output must match the specifications presented above (when given the same inputs)
  • Code must be commented
    • be sure your comments reflect the how and why of what you are doing, not merely the what.
  • Track/version the source code in a repository
  • 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:

$ submit discrete mtf1 mtf1.c
Submitting discrete project "mtf1":
    -> mtf1.c(OK)

SUCCESSFULLY SUBMITTED

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.

haas/fall2022/discrete/projects/mtf1.txt · Last modified: 2019/09/26 17:59 by 127.0.0.1