CIS 33A - Programming in PERL

Summer Session 2009 - De Anza College

Assignment-2 (Due Saturday, 07/11 at midnight)

Instructions: Write two small programs:

1. dec_to: This program is an extension of your dec_to_bin program. It prompts the user for two numbers: the decimal number to be converted, and the base of the desired conversion (2 for binary, 8 for octal, 16 for hexadecimal).

You must use a subroutine to solve this program, one with two parameters which correspond to the two numbers input by the user. Your subroutine should return the result to the main program, which should then print it out.

Below is sample output from my program which I want you to mimic exactly:

```[voyager solutions]\$ dec_to
Enter decimal number to convert: 256
Enter base of number for desired conversion: 2
100000000
[voyager solutions]\$ dec_to
Enter decimal number to convert: 256
Enter base of number for desired conversion: 16
100
[voyager solutions]\$ dec_to
Enter decimal number to convert: 269
Enter base of number for desired conversion: 16
10D
[voyager solutions]\$ dec_to
Enter decimal number to convert: 68
Enter base of number for desired conversion: 8
104
[voyager solutions]\$
```

• Output the mode (most frequent grade). If there is a "tie" for the mode, your program can output whichever one of the "winners" you want. Your program should also output the number of times the mode occurred in the input.

• Your program should store all the input in an array. This array must be passed as a parameter to five different subroutines: &sum, &min, &max, &median, and &mode.

Hint: Perl's sort does lexicographical sorting by default, which is not what you need! Consider "blank-padding" your array in order to make sort work for you.

• Your program should not use any feature beyond Chapter 5 of your textbook other than the int function in order to truncate the results of division to an integer result.
```> grader < even
Average = 76.2916666666667
Min =  13
Max =  100
Median = 83.5
Mode = 73 (4 times)