CS253: Software Development with C++

Spring 2020

HW 1

CS253 HW1: Dates                

Description                

Months are confusing! They’re all kinds of different lengths! Begone! Weeks are also confusing! Let’s avoid them! All we need is a year and the day within the year!                 

For this assignment, you will write a C++ program called hw1 that will read dates in year.day format and produce equivalent output in a more conventional style.                 

Input Format                

Each input line consists of a year and day number within the year, separated by a period. The first day of this year is 2024.001, the last is 2024.366, and today is 2024.117. Here are some examples, both valid & invalid:                 

ValidInvalid
476.2482020.123A
0000476.000002482020 . 123
2020.12020.900
2024.1172019.0
002020.332019.366
2020.366 
1956.28820🐟19.22

Output Format                

The output format is:

weekday two-digit-day-of-month month four-digit-year newline

Input of 2024.117 produces output of Fri 26 Apr 2024, corresponding to today, because today is day number 117 of the year 2024.                 

Sample Run                

Here is a sample run, where % is my prompt.                 

% cmake .
… cmake output appears here …
% make
… make output appears here …
% cat in
0000476.00000248
2020.1
2019.000000000060
002020.60
2020.366
1.1
9999.365
% ./hw1 <in
Fri 04 Sep 0476
Wed 01 Jan 2020
Fri 01 Mar 2019
Sat 29 Feb 2020
Thu 31 Dec 2020
Mon 01 Jan 0001
Fri 31 Dec 9999

Hints                

You may find these functions useful. Use them if you wish.

Beware of unfortunate conventions in localtime() & mktime(), where months are 0…11 and years are 1900-based.                 

YearLeap?
2019no
2020yes
1900no
2100no
2000yes

Gregorian Calendar                

This assignment uses the current calendar system common in the USA, called the Gregorian calendar. In the Gregorian calendar, leap years (years with February 29) occur in years divisible by four, unless the year is divisible by 100 (no leap year), unless it’s divisible by 400 (leap year).                 

Use the Gregorian calendar for all dates in this assignment, even if they occur before the Gregorian calendar was devised.                 

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.                 

Tar file                

    cmake . && make

How to submit your work:                

Use web checkin, or Linux checkin:                 

    ~cs253/bin/checkin HW1 hw1.tar

How to receive negative points:                

Turn in someone else’s work.