Bifalgorithm post · Computer science one · Nested Structures

How can a date be modeled using a nested structure?

How can a date be modeled using a nested structure? (Computer science one · Nested Structures) — "Consider adding another member variable to the Student struct…

Ideas in this flowchart

  • Modeling a student’s date of birth in the Student structure
  • Time can be modeled as a single integer representing milliseconds since the Unix epoch
  • The Unix epoch is January 1, 1970, in Coordinated Universal Time (UTC)
  • The New Horizons launch corresponds to approximately 1.137 billion milliseconds since the epoch
  • Time can also be modeled as a string
  • ISO 8601 commonly represents time with a date, time, and offset from Greenwich Mean Time
  • The New Horizons launch can be written as "2006-01-19T19:00:00+00:00"
  • For simplicity, the date will be modeled with a year, a month, and a date
  • A date is conceptually one entity, so separating its three numbers is not ideal
  • A separate structure should be defined to represent the date
Feed/

How can a date be modeled using a nested structure?

No cover

Channel

Computer science one

1 page

"Consider adding another member variable to the Student structure to model a student’s date of birth. How might we model a date? Unix systems model time as a single integer value that represents the number of milliseconds that have passed since the Unix epoch, January 1st, 1970 (also known as Coordinated Universal Time (UTC)). For example, the New Horizons space probe was launched on January 19th, 2006 at 19:00:00 UTC. This corresponds to 1,137,697,200, roughly 1.137 billion milliseconds since the epoch. Another way to model time is as a string. There are several standards for time representations, but the most common is ISO standard 8601 [22] which specifies time using a format that includes a date, time and an offset from Greenwich Mean Time (GMT). For example, the New Horizons launch date/time would be represented as \"2006-01-19T19:00:00+00:00\". To keep things simple, we’ll model our date using three numbers: a year, a month and a date. But how should we implement this? Conceptually, a date is a single entity, separating these three numbers doesn’t make much sense. This is a perfect opportunity to define another structure."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.