Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab you will manipulate a time variable and corresponding structure, print today's date and time in various formats, and determine how to adjust
In this lab you will manipulate a time variable and corresponding structure, print today's date and time in various formats, and determine how to adjust the internal form of other dates.
Project Detail
- Open a new Dev-C++ project
- At the top of the program, include the ctime library.
- In main, create string arrays for:
- weeks of the day (Sunday=0, Monday=1, Tuesday=2...)
- months of the year (January=0, February=1, March=2...)
- Create a time_t variable and set to the current time (don't forget to include ctime at the top of your program).
time_t now = time(NULL) ;
- Establish a tm structure and reference with a pointer. Assign to the current time:
tm *local = localtime(&now) ;
- Using the values in the structure, print today's date using the following formats:
1/1/20 (m/d/yy) January 1, 2020 1-Jan-2020
- Print the current time in the following formats:
17:30 5:30pm / 12:00am
- Create a tm structure for your birthday and time, assigning all variables appropriately:
tm birthday ; birthday.tm_year = ??? - 1900 ; birthday.tm_mon = ?? ; birthday.tm_mday = ?? ; birthday.tm_hour = ?? ; birthday.tm_min = ?? ; birthday.tm_sec = ?? ; birthday.tm_isdst = ?? ;
- Determine how many seconds after epoch you were born, then use the ctime function to print the date and time, and finally determine how old you are in seconds. (You can use any other big moment in your life, such as receiving your high school diploma, proposing to your significant other, driving your first car, opening your first paycheck, or a significant moment in history.)
time_t time_of_birthday = mktime(&birthday) ; cout << ctime(&time_of_birthday) << endl << "I was born " << time_of_birthday << " seconds after epoch!" << endl ;
- Determine the number of seconds that occur in one week. (Multiply the number of days in a week by the number of hours in a day, by the number of minutes in an hour, by the number of seconds in a minute). Use the computer to calculate this number.
- Subtract the number of seconds in a week from the time_t variable created just above.
- Print the date and time occurring exactly one week before the big moment in your life using the ctime function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started