Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I need help with the second portion where the CS253 HW3: Options!(NEED HELP HERE !!!!) appears. The first portion CS253 HW1: Dates has been solved,

I need help with the second portion where the "CS253 HW3: Options!(NEED HELP HERE !!!!)" appears. The first portion CS253 HW1: Dates has been solved, codes are attached. I need this as soon as possible. Please help. CS253 HW1: Dates Description Months are confusing! Theyre all kinds of different lengths! Begone! Weeks are also confusing! Lets 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 2023.001, the last is 2023.365, and today is 2023.063. Here are some examples, both valid & invalid: Valid Invalid 476.248 2020.123A 0000476.00000248 2020 . 123 2020.1 2020.900 2023.063 2019.0 002020.33 2019.366 2020.366 1956.288 2019.22 Output Format The output format is: weekday two-digit-day-of-month month four-digit-year newline Input of 2023.063 produces output of Sat 04 Mar 2023, corresponding to today, because today is day number 63 of the year 2023. 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 #include #include int main() { std::string input; while (std::getline(std::cin, input)) { // Parse year and day from input int year = std::stoi(input.substr(0, 4)); int day = std::stoi(input.substr(5)); // Calculate time in seconds since 1970-01-01 std::tm timeinfo = {}; timeinfo.tm_year = year - 1900; // years since 1900 timeinfo.tm_mday = 1; // 1st day of month timeinfo.tm_mon = 0; // January timeinfo.tm_hour = 0; // midnight timeinfo.tm_isdst = -1; // determine daylight saving time std::time_t time = std::mktime(&timeinfo) + (day - 1) * 86400; // Convert time in seconds to broken-down time timeinfo = *std::localtime(&time); // Format output char buffer[80]; std::strftime(buffer, sizeof(buffer), "%a %d %b %Y ", &timeinfo); std::cout << buffer; } return 0; } Step 3/3 Let's go through the implementation step by step: We use a while loop to read input lines from std::cin until the end of the input is reached. We parse the year and day from the input string using std::stoi(). We create a std::tm structure timeinfo and set its fields to represent January 1st of the input year. We calculate the time in seconds since 1970-01-01 by calling std::mktime() with timeinfo and adding the number of seconds corresponding to the input day. We call std::localtime() with the calculated time to convert it to a broken-down time structure. We format the output using std::strftime() with the %a, %d, %b, and %Y format specifiers to represent the abbreviated weekday, day of the month with leading zeros, abbreviated month name, and year with century, respectively. We print the formatted output to std::cout. Note that we set the tm_isdst field of timeinfo to -1 to let the mktime() function determine whether daylight saving time is in effect or not. Also, note that we use a char buffer to store the formatted output instead of printing it directly to std::cout. This is because std::cout can be slower than writing to a buffer, especially when there are many output lines. CS253 HW3: Options!(NEED HELP HERE !!!!) 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 Saturday March 04 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 2023-03-04. -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 1year9999, and the day is either 1day365 or 1day366, depending on leap year. Today is 2023.063. YYYY-MM-DD YYYY is a four digit year. MM is a two-digit month. DD is a two digit day. Today is 2023-03-04. YYYY should be 1YYYY9999, MM should be 1MM12, 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students explore these related Databases questions