CS157 |
Homework 1: Command-Line Arguments and scientific data typesDescriptionLearning a programming language, such as C, is cumulative. You are expected to be fluent in the basic syntax presented in CS156 and now are ready to move on to advanced C language topics and more complex programs. If you find yourself struggling with syntax on this assignment you need to attend office hours for help. For this assignment you will be using command line arguments to read in the name of the file to process, read in from a file and perform some calculations. Your program must run with one command-line argument: the name of the file to process. Your program must ensure that one and only one command-line argument is submitted to the program. If fewer, or more arguments are submitted, you must print an appropriate usage statement. Data FileThe data file you must process will have two fields per line: a country name, and the average life expectancy, in years, for people in that country. For example: Canada 80.34
Chile 76.96
Mexico 75.84
Poland 75.19
Dominica 75.1
Latvia 71.6
Egypt 71.57
Nicaragua 70.92
Iran 70.56
Uganda 51.75
Afghanistan 43.77
Swaziland 32.23
Here’s another, less orderly but still valid, example: Uganda 51.75
UK +78.7
Ukraine 067.88
Uruguay 7.593e+1
USA 0.7806e002
Uzbekistan 649.8e-1
DeathLand 9
Your program must work on these files or other such files. It should print out the country name, and the life expectancy in years, days, and microseconds. Sample Runs % ./a.out bogus
./a.out: can't open bogus
% ./a.out udata
NAME YEARS DAYS MICROSECONDS
------------- ----- -------- ------------
Uganda 51.75 18901.30 1.633e+15
UK 78.70 28744.58 2.484e+15
Ukraine 67.88 24792.66 2.142e+15
Uruguay 75.93 27732.86 2.396e+15
USA 78.06 28510.83 2.463e+15
Uzbekistan 64.98 23733.46 2.051e+15
DeathLand 9.00 3287.18 2.840e+14
For the purpose of this assignment, there are 365.2425 days in a year, and 24 hours in a day. Requirements
Required functionsThere are only two required functions. You have to write them, and use them: double years_to_days(double y);
double years_to_microseconds(double y);
GradingHomework 1 is worth 10 points. You’ll lose points if you submit a file that:
How to submit your homework:Go to the same directory as the ~cs157/bin/checkin HW1 life.c How to check your answer after you turn it in: ~cs157/bin/peek HW1 life.c How to receive negative points: Turn in someone else’s work.
|