Colorado State University

This file defines the header for each page. An optional "icon" image (I use the textbook):

Three headers follow: ! Long name of class !! Semester !!! HW 4, replaced by the name of the current page.

CS155: Introduction to Unix

Spring 2013

HW 4

Links to the various pages for this class:

Wish I could do this: * Schedule

CS155 HW4: Unit Conversion

Summary

The traditional system of measurements, as used in the U.S.A., is the best! It’s so simple to understand! “meters”—who needs ’em? We have yards, furlongs, miles, and leagues! ☹

In this assignment, you will write a bash script called unity which will do some length conversions. Specifically, it will recognize these units:

UnitConversion
inches 
hands4 inches
feet12 inches
yards3 feet
furlongs220 yards
miles5280 feet
leagues3 miles
au92,955,807 miles

You only have to recognize those names, which are all plural. You don’t have to recognize “foot” or “mile”. No other units (meters, angstroms, light-years, etc.) should be recognized.

Sample runs:

    % ./unity 4 feet as inches
    4 feet = 48 inches
    % ./unity 10 miles as feet
    10 miles = 52800 feet
    % ./unity 17 furlongs as furlongs
    17 furlongs = 17 furlongs
    % ./unity 3 yards as feet
    3 yards = 9 feet
    % ./unity 10 feet as yards
    10 feet = 3 yards
    % ./unity 1 au as inches
    1 au = 5889679931520 inches
    % ./unity
    usage: ./unity <number> <units> as <units>
    % ./unity XYZ inches as feet
    usage: ./unity <number> <units> as <units>
    % ./unity 1X inches as feet
    usage: ./unity <number> <units> as <units>
    % ./unity 1 inches as feet extra stuff here
    usage: ./unity <number> <units> as <units>
    % ./unity 3 yard as feet
    Unrecognized unit: yard
    % ./unity 1 feet as meters
    Unrecognized unit: meters

Your program will convert between all pairings of those units. That is, the second and fourth arguments can be any of the recognized units.

Requirements

How to submit your homework:

Follow the directions on the homework page.

How to receive negative points:

Turn in someone else’s work.
Page: Main.HW4
Modified: February 17, 2013, at 05:11 PM
Wiki: pmwiki-2.2.35
CS Department
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2012 Colorado State University