CIS 33A - Programming in PERL

Summer Session 2009 - De Anza College

Assignment-1 (Due Saturday, 07/04 at midnight)

 

Instructions: Write four small programs:

  1. bmi: This program should prompt the user for two pieces of information: his or her height in inches, and his or her weight in pounds. It should then calculate the user's BMI (Body Mass Index) based on the following formula: (weight / height / height) * 703. The program's output should consist of two lines: one giving the user's BMI, and another explaining whether the user is considered underweight, normal, overweight, or obese, based on his or her BMI. Below is sample output from my program which I want you to mimic exactly:
    [voyager]$ bmi
    Enter your height in inches: 73
    Enter your weight in pounds: 135
    Your BMI is 17.8091574404203
    Underweight: < 18.5 BMI
    [voyager]$ 
    [voyager]$ bmi
    Enter your height in inches: 73
    Enter your weight in pounds: 155
    Your BMI is 20.4475511352974
    Normal: 18.5 to 24.9 BMI
    [voyager]$ 
    [voyager]$ bmi
    Enter your height in inches: 73
    Enter your weight in pounds: 195
    Your BMI is 25.7243385250516
    Overweight: 25 to 29.9 BMI
    [voyager]$ 
    [voyager]$ bmi
    Enter your height in inches: 73
    Enter your weight in pounds: 235
    Your BMI is 31.0011259148058
    Obese: 30 and above BMI
    [voyager]$ 
    
    

  2. grader: This program should get its input via the redirection of standard input on the command line that invokes it, i.e.,

    grader < grades

    The program should calculate the arithmetic mean (average) of the grades, along with determining the minimum and maximum grade. Below is the invocation of my program, along with its output, which I want you to mimic exactly:

    > grader < grades
    Average = 80.9166666666667
    Min =  39
    Max =  100
    >
    

  3. unique: This program should get its input via the redirection of standard input on the command line that invokes it, i.e.,

    unique < fruits

    The program should look for consecutive identical lines and output just one of those lines, preceded by a count of how many times that line appeared. Below is the invocation of my program, along with its output, which I want you to mimic exactly:

    [voyager]$ unique < fruits
    1: red apple
    2: yellow banana
    3: cherries
    4: fig
    5: ruby grapefruit
    6: green kiwi
    3: yellow banana
    1: red apple
    [voyager]$
    

  4. dec_to_bin

    Write a program that prompts the user for a decimal number, and then outputs the binary equivalent. Below is the invocation of my program, along with its output, which (as usual!) I want you to mimic exactly:

    [voyager solutions]$ ./dec_to_bin
    Enter decimal number to convert to binary: 274
    100010010
    [voyager solutions]$
    

    Be sure your program works with all sorts of test cases: 0, 1, 2, 3, 255, 256, etc.

To hand in your assignments, send me one and only one email with four separate attachments named as specified above. The Subject line should be Perl ASSIGNMENT-1. Please put your name as it appears in De Anza College records in the body of the message. instructions once I've posted the requirements for the fourth program.

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.