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]$ 
    

  2. grader: Extend your grader program from Assignment-1 in the following ways:

    > grader < even
    Average = 76.2916666666667
    Min =  13
    Max =  100
    Median = 83.5
    Mode = 73 (4 times)
    > grader < odd
    Average = 75.76
    Min =  13
    Max =  100
    Median =  82
    Mode = 73 (4 times)
    >
    

To hand in your assignments, send me one and only one email with two separate text-file attachments named as specified above. The Subject line should be Perl ASSIGNMENT-2. Please put your name as it appears in De Anza College records in the body of the message.

Even though I have provided sample input for each program above, you are responsible for the correctness of your program, regardless of the input used. In other words: test, Test, TEST! If your program contains logic errors that would appear only with other input files, you'll still lose points. Sharing test cases with other students is encouraged.