CS253: Software Development with C++

Spring 2020

HW 3

CS253 HW3: Options!                

Description                

For this assignment, you will improve upon your previous work in HW1, adding command-line options, and reading from files or standard input.                 

Arguments                

The first command-line arguments should be options:                 

-f format
Specify the format, to be given to strftime(). For example, a format of "%A %B %d" would give output of Thursday May 28 for a date of today.
-i
Specify a format that will write the date in the ISO 8601 format of YYYY-MM-DD, exactly four digits (year), a hyphen, exactly two digits (month), another hyphen, and exactly two more digits (day of month). Today would produce 2020-05-28.
-v
Announce, to standard output, each file as it is read. Display *** Processing filename for each file, and *** Processing standard input for standard input.

Any remaining arguments are files that should contain one date per line. If no files are given, then read from standard input.                 

Input Format                

Input lines can be in any of these formats:                 

year.day
As in HW1. The year should be 1≤year ≤9999, and the day is either 1≤day ≤365 or 1≤day ≤366, depending on leap year. Today is 2020.149.
YYYY-MM-DD
YYYY is a four digit year. MM is a two-digit month. DD is a two digit day. Today is 2020-05-28. YYYY should be 1≤YYYY≤9999, MM should be 1≤MM≤12, and DD should 1 to however many days are in that month that year.
today
The current day. Literally, the five characters “today”, in either case. E.g., “tOdAy” is valid.
yesterday
The day before today. Literally, the nine characters “yesterday”, in either case. E.g., “YEstERday” is valid.
tomorrow
The day after today. Literally, the eight characters “tomorrow”, in either case. E.g., “TomORRow” is valid.

Output Format                

For each input line, translate it using the given format, and write it to standard output, followed by a newline.                 

Sample Runs                

Here are sample runs, where % is my prompt.                 

% cat pearl
1941-12-07
00000000001941.00000341
% cat limits
1.1
0001-01-01
9999.365
9999-12-31
% echo ToDay | ./hw3
Wed Feb 12 2020
% echo YESterDaY | ./hw3 -f 'Day %d of the month of %B of the year %Y'
Day 11 of the month of February of the year 2020
% echo 2021.1 | ./hw3 -f 'Week-based year: %G%nConventional year: %Y'
Week-based year: 2020
Conventional year: 2021
% ./hw3 -f"A day that will live in infamy: %A %B %e %Y" -v pearl
*** Processing pearl
A day that will live in infamy: Sunday December  7 1941
A day that will live in infamy: Sunday December  7 1941
% ./hw3 -f"A day that will live in infamy: %A %B %e %Y" -v <pearl
*** Processing standard input
A day that will live in infamy: Sunday December  7 1941
A day that will live in infamy: Sunday December  7 1941
% ./hw3 -vi limits pearl
*** Processing limits
0001-01-01
0001-01-01
9999-12-31
9999-12-31
*** Processing pearl
1941-12-07
1941-12-07
% cat pearl | ./hw3 -f '%04Y %b %d %a' -v limits
*** Processing limits
0001 Jan 01 Mon
0001 Jan 01 Mon
9999 Dec 31 Fri
9999 Dec 31 Fri

Yes, that last example really is correct. Only read standard input if no filenames are given.                 

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.                 

Hints                

Tar file                

    cmake . && make

How to submit your work:                

Use web checkin, or Linux checkin:                 

    ~cs253/bin/checkin HW3 hw3.tar

How to receive negative points:                

Turn in someone else’s work.