Shockingly, the entire world does not use our splendid inches-feet-miles
units of measurement! For this assignment, you will write a program
called units.c
, which will translate between various units of measurement.
                
Your program does not have to handle all possible units. It only has to handle those units given in a data file. This file will have two columns: the unit name, and its value relative to meters.                 
An example of a data file follows:                 
INCH 0.0254 FOOT 0.3048 YARD 0.9144 MILE 1609.344 MM 1e-3 CM 1e-2 METER 1 KM 1e3 AU 149597870700.0
This file indicates that an inch is 0.0254 meters, a foot is 0.3048 meters, and so on. From this, one could deduce that there are 1609.344/0.3048, or 5280, feet in a mile.                 
We will test your program with other similar data files, with different names. Do not assume that all data files have any particular name, or that they will contain exactly those units, or in that order.                 
Here are several sample runs, using the data file above,
which we will call lengths
.
                
% c11 -Wall units.c -o u % ./u lengths 12 inch foot 12.00 inch is 1.00 foot. % ./u lengths 30 inch foot 30.00 inch is 2.50 foot. % ./u lengths 1 foot inch 1.00 foot is 12.00 inch. % ./u lengths 1 inch foot 1.00 inch is 0.08 foot. % ./u lengths 1 au mile 1.00 au is 92955807.27 mile. % ./u lengths 1000 meter km 1000.00 meter is 1.00 km. % ./u lengths 1 inch mile 1.00 inch is 0.00 mile. % ./u usage: ./u <unitfile> <amount> <from> <to> % ./u lengthz 1 inch foot ./u: can’t open file lengthz % ./u lengths 1 inch feet ./u: no such unit "feet"
double
variables, rather than float
, so that your
results will match ours.
argv[0]
must be sent to stderr
.
argv[0]
, and the data file name, must be sent to
stderr
.
argv[0]
and the unit name,
must be sent to stderr
.
char
constants for char
values, not int
ASCII values:
'A'
, not 65
.
Use                 
~cs157/bin/checkin HW1 units.c
or web checkin.                 
Turn in someone else’s work.                 
Modified: 2017-08-26T16:41                  User: Guest                  Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |