Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 159 – HW #06

Due: Monday, November 13 at 11:00pm (time local to West Lafayette, IN). 10 Points Possible.

Problem: You will now take your Homework #5 solution and make it time zone-aware. The unix timestamp typically represents time with respect to Coordinated Universal Time, or UTC – the time of day at the prime meridian,

longitude. A time zone is then defined as an offset in terms of hours (or sometimes minutes) with respect to UTC for   local timekeeping purposes. For example, Purdue is located in the United States Eastern Time Zone, which is UTC–4 ("UTC minus four") during daylight saving time from March to November. If it is 12 PM in UTC, then it is 8 AM in   UTC–4.

Your program will accept a single long long unix timestamp and up to ten int UTC hour offsets and display the

resulting dates and times. The number of hours spanned between the earliest and latest time zone will also be displayed.

Example Execution #1:

Enter unix timestamp -> 1699923600

Enter offset, or -100 to finish -> 0

Enter offset, or -100 to finish -> -4

Enter offset, or -100 to finish -> -5

Enter offset, or -100 to finish -> -100

UTC +0: 2023-11-14 01:00:00 AM

UTC -4: 2023-11-13 09:00:00 PM

UTC -5: 2023-11-13 08:00:00 PM

Hours spanned: 6

Explanation: Your program no longer

needs to handle "noon" nor "midnight"

specially. Additionally, hours, minutes,

and seconds will always be displayed, and the month name is no longer included.

Hint: Use the + flag for the printf

placeholder that will display the UTC

offset itself. This will force a plus sign to be displayed for positive numbers and

zero in addition to the typical minus sign for negative numbers. See p. 58 in the Forouzan & Gilberg textbook for details.

Example Execution #2:

Enter unix timestamp -> -100

Error! Timestamp must be >= 0.

Enter unix timestamp -> 629547420

Enter offset, or -100 to finish -> -13

Error! Offset must be between -12 and 14 inclusive.

Enter offset, or -100 to finish -> 15

Error! Offset must be between -12 and 14 inclusive.

Enter offset, or -100 to finish -> -5

Enter offset, or -100 to finish -> -100

UTC -5: 1989-12-13 05:17:00 AM

Hours spanned: 1

Explanation: Input validation

requirements are demonstrated here. The earliest possible UTC offset is UTC+14,  and the latest possible UTC offset is

UTC–12.

Hint: An offset of -100 must be handled specially, as this value is provided by the user to indicate that they have finished

entering fewer than ten offsets.

Academic Integrity Reminder: Please review the policies of the course as they relate to academic integrity.

.    The assignment you submit should be your own original work.

.    Seek assistance from only course staff.

.    Collaboration is never permitted on individual homework assignments.

.    Protect your work from being openly accessible on the Internet.

Example Execution #3: The user need not enter -100 to finish input if they have already entered ten offsets.

Enter unix timestamp -> 2208988800

Enter offset, or -100 to finish -> -10

Enter offset, or -100 to finish -> -8

Enter offset, or -100 to finish -> -7

Enter offset, or -100 to finish -> -6

Enter offset, or -100 to finish -> -5

Enter offset, or -100 to finish -> -4

Enter offset, or -100 to finish -> -3

Enter offset, or -100 to finish -> -1

Enter offset, or -100 to finish -> 0

Enter offset, or -100 to finish -> 1

UTC-10:        2039-12-31 02:00:00 PM

UTC -8:        2039-12-31 04:00:00 PM

UTC -7:        2039-12-31 05:00:00 PM

UTC -6:        2039-12-31 06:00:00 PM

UTC -5:        2039-12-31 07:00:00 PM

UTC -4:        2039-12-31 08:00:00 PM

UTC -3:        2039-12-31 09:00:00 PM

UTC -1:        2039-12-31 11:00:00 PM

UTC +0:        2040-01-01 12:00:00 AM

UTC +1:        2040-01-01 01:00:00 AM

Hours spanned: 12

Example Execution #4:

Enter unix timestamp -> 68245261

Enter offset, or -100 to finish -> 2

Enter offset, or -100 to finish -> 3

Enter offset, or -100 to finish -> -100

UTC +2:        1972-02-29 11:01:01 PM

UTC +3:        1972-03-01 12:01:01 AM

Hours spanned: 2

Example Execution #5:

Enter unix timestamp -> 1000000000

Enter offset, or -100 to finish -> 0

Enter offset, or -100 to finish -> -40

Error! Offset must be between -12 and 14

Enter offset, or -100 to finish -> -4

Enter offset, or -100 to finish -> -100

UTC +0:        2001-09-09 01:46:40 AM

UTC -4:        2001-09-08 09:46:40 PM

Hours spanned: 5

Example Execution #6:

Enter unix timestamp -> 978281999

Enter offset, or -100 to finish -> 12

Enter offset, or -100 to finish -> 11

Enter offset, or -100 to finish -> 10

Enter offset, or -100 to finish -> 9

Enter offset, or -100 to finish -> 8

Enter offset, or -100 to finish -> 7

Enter offset, or -100 to finish -> 6

Enter offset, or -100 to finish -> 5

Enter offset, or -100 to finish -> 4

Enter offset, or -100 to finish -> -100

UTC+12:        2001-01-01 04:59:59 AM

UTC+11:        2001-01-01 03:59:59 AM

UTC+10:        2001-01-01 02:59:59 AM

UTC +9:        2001-01-01 01:59:59 AM

UTC +8:        2001-01-01 12:59:59 AM

UTC +7:        2000-12-31 11:59:59 PM

UTC +6:        2000-12-31 10:59:59 PM

UTC +5:        2000-12-31 09:59:59 PM

UTC +4:        2000-12-31 08:59:59 PM

Hours spanned: 9

Example Execution #7:

Enter unix timestamp -> 4107555000

Enter offset, or -100 to finish -> -12

Enter offset, or -100 to finish -> 14

Enter offset, or -100 to finish -> -100

UTC-12:        2100-02-28 03:30:00 PM

UTC+14:        2100-03-01 05:30:00 PM

Hours spanned: 27

Hint: If the offset adjustment is made before converting each resulting timestamp into the corresponding date and time, then rollovers   into the previous or next day, month, and

year will occur naturally based on your

existing code. Handling rollovers after the    conversion into the date and time is possible but would be considerably more complex.

Hint: A single array is necessary to solve this problem.

All course programming and documentation standards are in effect for this and each

assignment this semester. Please review this document!

Additional Requirements:

1.   Add the homework assignment header file to the top of your program. A description of your program will need to be included in the assignment header. This particular header can be added to your file by entering  :hhw while in  command mode in vi.

2. Each of the example executions provided for your reference represents a single execution of the program.

Your program must accept input and produce output exactly as demonstrated in the example executions.

Do not add any “bonus” features not demonstrated in the example executions.

3. Revisit course standards as it relates what makes for good use of user-defined functions, what is acceptable to retain in the main function, and when passing parameters by address is appropriate. In many cases user- defined function use should result in a main function that only declares variables and makes function calls.

4.   Course standards prohibit the use of programming concepts beyond the material found in the first EIGHT chapters of the book, notes, and lectures.

◦   The use of any technique of dynamic memory allocation or strings would violate the requirements of this assignment and would result in no credit being awarded for your effort.

5.   A program MUST compile, be submitted through Vocareum as demonstrated during the lab #0 exercise, and be successfully submitted prior to the posted due date to be considered for credit. The C-file you submit must be    named exactly:  hw06.c, no variation is permitted.

Course Programming and Documentation Standards Reminders:

•    It is common to make use of a symbolic/defined constant when the size of the array is known prior to the start of a program.  The course standards expect all arrays to be of a fixed size.  Variable-size arrays, even those

demonstrated in chapter 8 of the text, would violate course standards.

Code found inside the body of relevant selection constructs must be indented two additional spaces.

Make use of { and  } with all relevant selection constructs.

See page 258 of your C programming text regarding the proper indentation for a switch construct.

Use the course function header (vi shortcut  :hfx while in command mode) for every user-defined function in

your program.

List and comment all parameters to a function, one per line, in the course function header.

All function declarations will appear in the global declaration section of your program.

The user-defined function definitions will appear in your program after the main function.

Indent all code found within the main function and each user-defined function exactly two spaces.

Place a single space between all operators and operands.

Comment all variables to the right of each declaration. Declare only one variable per line.

Maximize your use of symbolic/defined constants and minimize your use of literal constants.

Notice that several programs (see program 2-9 on pages 74-75) in the programming text use a single line

comment to indicate the start of the local declaration and executable statement sections of the main function.

At no point during the semester should these two sections ever overlap.

When you submit... only the final successful submission is kept for grading. All other submissions are over-written and cannot be recovered. You may make multiple submissions but only the last attempt is retained and graded.

Assignment deadlines... are firm and the electronic submission will disable promptly as advertised. We can only grade what you are able successfully submit via Vocareum prior to the assignment deadline.