Answered step by step
Verified Expert Solution
Link Copied!

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

  1. Open a new Dev-C++ project
  2. At the top of the program, include the ctime library.
  3. 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...)
  1. 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) ;

  1. Establish a tm structure and reference with a pointer. Assign to the current time:
 tm *local = localtime(&now) ;

  1. 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 

  1. Print the current time in the following formats:
 17:30 5:30pm / 12:00am 

  1. 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 = ?? ; 

  1. 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 ; 

  1. 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.
  2. Subtract the number of seconds in a week from the time_t variable created just above.
  3. 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

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions