Concept
How can a date be modeled using a nested structure?
ComputerScienceOne / Nested Structures
"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."
Related Ideas
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How are structure instances declared and initialized?ComputerScienceOne · Declaration & Initialization
- How do you access members of a statically declared structure?ComputerScienceOne · Selection Operators
- How are structures defined and named in C?ComputerScienceOne · Alternative Declarations
- How do you access members through a pointer to a structure?ComputerScienceOne · Selection Operators
- What problems arise when modeling students with separate variables and arrays?ComputerScienceOne · Encapsulation & Objects
- How does composition model objects made up of other objects?ComputerScienceOne · Composition
- What is composition in object-oriented class design?ComputerScienceOne · Common Methods