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:
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.
=====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
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.
=====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.
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.
====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.
=====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 **submit** tool, 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 runtime tests of submitted script succeed [6/6]
Additionally:
* 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 **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