Corning Community College CSCS1730 UNIX/Linux Fundamentals ======Project: MULTIPLICATION TABLE FUN (mtf0)====== =====Objective===== To utilize bash scripting in order to achieve a desired ends: the generation of a multiplication table for use in a specified number base. =====Background===== Everyone is familiar with the venerable multiplication table, that quintessential grade school aid that enabled us to more easily memorize our "multiplication facts", supercharging our basic math abilities and understanding of numbers without the constant need of a calculator. The standard table (for base 10) is as follows: (10) 1 2 3 4 5 6 7 8 9 x--------------------------- 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 Where we line up on the heading row/column the two numbers we wish to multiply, and its product at the intersection of those two within the body of the table. For example, 6 x 7 is 42, as you should be able to find (twice: 6x7 and 7x6). While you've likely had little need, due to your solid memorization and recall, for years of the base 10 multiplication table, we're going to bring it back to the forefront, like many good mental aids, in that they make for excellent exercises to have the computer generate. =====grabit===== Some projects encountered this semester, or in other classes that utilize lab46, will provide you resources that you can access via the '**grabit**' tool. This is one such project, where your successful utilization of the **grabit** tool, before a certain point in the project lifecycle, will be evaluated. Using your investigative skills cultivated in this class, figure out how to use the **grabit** tool to obtain the project files provided for this project. Do note: as an attempt to ensure some element of time management is practiced, you will want to perform this step by the Sunday prior to the due date of the project. =====Script===== Your task for this project is to write a bash script to generate a multiplication table. If run without any arguments, the default action is to display a base 10 table from 1 to 9. The table itself: * has a delineated heading row and column * that line of delineation * the operation symbol represented in the top left of the table (in our case, an 'x' for multiplication) * all values aligned, allowing for the padding of a single space for the largest value represented * in the upper-left corner, in parentheses, the base is displayed Additionally, with the specification of command-line arguments, we can change: * $1: the base (2-16) * $2: the ending point (0-) * $3: the starting point (0-) NOTE that the ending value comes before the starting value in the order of command-line arguments. =====Toolbox===== Some commands you will want to explore and reference the manual pages of: * bash(1) * variables * if statements * for loops * bc(1) * outputting in specified number bases * printf(1) * formatted print strings * format substitutions * padding * [(1) * wc(1) =====bash scripts===== We have been using the **bash** shell on lab46 and our pi systems this semester, so in many ways, the various "steps" files you've created have largely been bash scripts. There are a few formalities to really ensure that is the case. ====the shabang==== One thing that makes a bash script an actual **bash** script is the shabang, a mechanism for ensuring our script is run using a particular shell or interpreter. The VERY FIRST LINE of our script, to set this up, will therefore be as follows: #!/usr/bin/env bash ====the trailing exit==== Commonly considered good practice, our script will end with a call to the shell's **exit** command, sending back a status to the operating system (in our case, a 0 indicating successful operation). exit 0 Your script will then occur between the shabang and this final exit command. Scripts lacking these two bounding elements will not be considered complete and will be subject to credit lost during evaluation. ====for loops==== Bash provides us a number of looping facilities, and for this project we will be making use specifically of the **for** loop. We have the typical numeric for loop (conforming largely to as you'd see it in various programming languages): for ((index=0; index < 9; index++)); do echo "index is ${index}" done And also a list-based for loop: LIST="1 2 4 8 16 32 64 128 256" for item in ${LIST}; do echo "item is ${item}" done ====bc==== **bc** is a powerful text-based calculator, which will provide the core of our mathematical and number representation functionality for this project. lab46:~/src/SEMESTER/DESIG/mtf0$ bc -q 4*5 20 Because it takes input from STDIN, and sends output to STDOUT, it can be especially useful in a command pipeline. lab46:~/src/SEMESTER/DESIG/mtf0$ echo "4*5" | bc -q 20 By default, it expects input values to be in base 10, and outputs the result in base 10. But it possesses the ability to change the base used for output and input transactions. NOTE: when changing the base, unless you take into account the representation of the base once the input base has been modified, change the output base before changing the input base. ====printf==== The **printf** tool is an especially powerful output formatter. =====sample outputs===== For checking purposes, here are some sample outputs of what your script should be able to generated, given various command-line arguments: Standard base 11 table: lab46:~/src/SEMESTER/DESIG/PROJECT$ ./mtf0 11 10 1 (11) 1 2 3 4 5 6 7 8 9 A x------------------------------ 1 | 1 2 3 4 5 6 7 8 9 A 2 | 2 4 6 8 A 11 13 15 17 19 3 | 3 6 9 11 14 17 1A 22 25 28 4 | 4 8 11 15 19 22 26 2A 33 37 5 | 5 A 14 19 23 28 32 37 41 46 6 | 6 11 17 22 28 33 39 44 4A 55 7 | 7 13 1A 26 32 39 45 51 58 64 8 | 8 15 22 2A 37 44 51 59 66 73 9 | 9 17 25 33 41 4A 58 66 74 82 A | A 19 28 37 46 55 64 73 82 91 Subset of base 9: lab46:~/src/SEMESTER/DESIG/PROJECT$ ./mtf0 9 5 2 ( 9) 2 3 4 5 x------------ 2 | 4 6 8 11 3 | 6 10 13 16 4 | 8 13 17 22 5 | 11 16 22 27 Base 15: lab46:~/src/SEMESTER/DESIG/PROJECT$ ./mtf0 15 17 0 (15) 0 1 2 3 4 5 6 7 8 9 A B C D E 10 11 12 x------------------------------------------------------------------------ 0 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 7 8 9 A B C D E 10 11 12 2 | 0 2 4 6 8 A C E 11 13 15 17 19 1B 1D 20 22 24 3 | 0 3 6 9 C 10 13 16 19 1C 20 23 26 29 2C 30 33 36 4 | 0 4 8 C 11 15 19 1D 22 26 2A 2E 33 37 3B 40 44 48 5 | 0 5 A 10 15 1A 20 25 2A 30 35 3A 40 45 4A 50 55 5A 6 | 0 6 C 13 19 20 26 2C 33 39 40 46 4C 53 59 60 66 6C 7 | 0 7 E 16 1D 25 2C 34 3B 43 4A 52 59 61 68 70 77 7E 8 | 0 8 11 19 22 2A 33 3B 44 4C 55 5D 66 6E 77 80 88 91 9 | 0 9 13 1C 26 30 39 43 4C 56 60 69 73 7C 86 90 99 A3 A | 0 A 15 20 2A 35 40 4A 55 60 6A 75 80 8A 95 A0 AA B5 B | 0 B 17 23 2E 3A 46 52 5D 69 75 81 8C 98 A4 B0 BB C7 C | 0 C 19 26 33 40 4C 59 66 73 80 8C 99 A6 B3 C0 CC D9 D | 0 D 1B 29 37 45 53 61 6E 7C 8A 98 A6 B4 C2 D0 DD EB E | 0 E 1D 2C 3B 4A 59 68 77 86 95 A4 B3 C2 D1 E0 EE 10D 10 | 0 10 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 100 110 120 11 | 0 11 22 33 44 55 66 77 88 99 AA BB CC DD EE 110 121 132 12 | 0 12 24 36 48 5A 6C 7E 91 A3 B5 C7 D9 EB 10D 120 132 144 =====Submission===== To successfully complete this project, the following criteria must be met: * Code must compile cleanly (no notes, warnings, nor errors) * Output must be correct, and match the form given in the sample output above. * Code must be nicely and consistently indented * Code must be well commented * Do NOT double space your code. Group like statements together. * Output Formatting (including spacing) of program must conform to the provided output (see above). * 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 provided Makefile, run the following command at your lab46 prompt: lab46:~/src/SEMESTER/DESIG/mtf0$ make submit Project backup process commencing Taking snapshot of current project (mtf0) ... OK Compressing snapshot of mtf0 project archive ... OK Setting secure permissions on mtf0 archive ... OK Project backup process complete Submitting DESIG project "mtf0": -> ../mtf0-DATESTAMP-HOUR.tar.gz(OK) SUCCESSFULLY SUBMITTED lab46:~/src/SEMESTER/DESIG/mtf0$ 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. What I'll be looking for: 78:mtf0:final tally of results (78/78) *:mtf0:obtained via grabit by Sunday before deadline [6/6] *:mtf0:script contains no syntax errors [6/6] *:mtf0:script contains no logical errors [6/6] *:mtf0:script contains no runtime errors [6/6] *:mtf0:script performs stated task/algorithm [6/6] *:mtf0:script output conforms to formatting expectations [6/6] *:mtf0:proper error checking and status reporting performed [6/6] *:mtf0:code implements solution using relevant concepts [6/6] *:mtf0:code updates committed/pushed to lab46 semester repo [6/6] *:mtf0:code uses readable variable names describing action [6/6] *:mtf0:project is submitted with relevant and complete script [6/6] *:mtf0:project is submitted on lab46 using 'make submit' [6/6] *:mtf0:runtime tests of submitted script succeed [6/6] Additionally: * Solutions not abiding by **SPIRIT** of project will be subject to a 50% overall deduction * Solutions not utilizing descriptive why and how **COMMENTS** will be subject to a 25% overall deduction * Solutions not utilizing **INDENTATION** to promote scope and clarity will be subject to a 25% overall deduction * Solutions lacking **ORGANIZATION** ior are not easy to read (within 90 char width) are subject to a 25% overall deduction