Executables and test input files are in the directory /home/plank/cs140/Labs/Lab6. As usual, if you have questions about how these programs should work, try these.
This Lab consists of two programs: mydc and histogram. In the first you should use a stack, and in the second you should use a queue.
MYDC(1) USER COMMANDS MYDC(1)
NAME
mydc - desk calculator
SYNOPSIS
mydc
DESCRIPTION
mydc is an arithmetic package. It operates on integers. The
overall structure of mydc is a stacking (reverse Polish)
calculator. Input comes from standard input.
The following input constructs are recognized:
Commands
number Push a number onto the stack.
+ - / * %
The top two values on the stack are: added (+),
subtracted (-), multiplied (*), divided (/),
or remaindered (%). The two entries are popped off
the stack and the result is pushed in their place.
d Duplicate the top value on the stack.
p Print the top value on the stack. The top value
remains unchanged.
q Exit the program.
P Pop the top value off the stack (don't print it).
s Swap the top two values on the stack.
c Clear the stack (i.e. pop off all values)
EXAMPLE
INPUT: 5 6 + p OUTPUT: 11
INPUT: 3 4 5 - * p 2 - p OUTPUT: -3
-5
INPUT: c p OUTPUT: main stack: empty
INPUT: + OUTPUT: not enough operands
INPUT: + 1 2 + p OUTPUT: not enough operands
3
For hints, see the hints file.
For example, suppose the data is composed of the numbers 3, 3, 4, 5, 5, 6, 7:
Histogram reads the data, figures out the lowest and the highest bins, and then for each potential bin from the highest to the lowest, it prints out the identity of the bin, left-justified and padded to 15 characters, a space, and then an asterisk for each element that is in the bin.
So, the input file Simpex.txt contains the example data above:
3 3 4 5 5 6 Ignore text before the last word, which is the data: 7 |
Here are a few example calls of histogram:
UNIX> histogram 1 < Simpex.txt [7] * [6] * [5] ** [4] * [3] ** UNIX> histogram 2 < Simpex.txt [6-7] ** [4-5] *** [2-3] ** UNIX> histogram 3 < Simpex.txt [6-8] ** [3-5] ***** UNIX> histogram 8 < Simpex.txt [0-7] ******* UNIX>I have some fun data files below:
UNIX> histogram 1 < Masters-Final.txt [83] * [82] * [81] * [80] ** [79] ** [78] * [77] ******* [76] ****** [75] ****** [74] ****** [73] ******* [72] ******* [71] ******* [70] *** [69] *** UNIX>
UNIX> histogram 5 < CS140-Grades.txt [95-99] ************* [90-94] ********************************** [85-89] ****************************** [80-84] **************************** [75-79] ************************ [70-74] ****************** [65-69] ************ [60-64] ************* [55-59] ***** [50-54] ******** [45-49] * [40-44] ***** [35-39] ** [30-34] [25-29] * [20-24] ** [15-19] ** UNIX>
UNIX> histogram 5 < Super-14-2007.txt [90-94] * [85-89] [80-84] [75-79] [70-74] [65-69] [60-64] * [55-59] * [50-54] * [45-49] ** [40-44] **** [35-39] ************* [30-34] *********************** [25-29] ************************ [20-24] ******************************* [15-19] ************************** [10-14] *************************** [5-9] ******************** [0-4] ******** UNIX>
UNIX> histogram 100 < Bridge-Example.txt [1400-1499] * [1300-1399] ******* [1200-1299] * [1100-1199] *** [1000-1099] *** [900-999] [800-899] ** [700-799] [600-699] ************************** [500-599] *********** [400-499] **************************************** [300-399] *** [200-299] ************** [100-199] *********************************************************************** [0-99] ****************************** [-100--1] **************************************************************** [-200--101] ************************************************************************* [-300--201] ******** [-400--301] **** [-500--401] ******************* [-600--501] ******** [-700--601] ******************** [-800--701] *** [-900--801] [-1000--901] ** [-1100--1001] [-1200--1101] [-1300--1201] [-1400--1301] [-1500--1401] [-1600--1501] *** UNIX>