CompTIA Tech+ (FC0-U71)Software Development ConceptsMedium

A developer is writing a program to manage a list of tasks. Each task has a name (e.g., 'Buy groceries'), a due date (e.g., '2024-12-31'), and a completion status (e.g., 'false' for incomplete). To organize this data efficiently, the developer wants to create a single custom data type that can hold all these related pieces of information for each task. Which programming construct is best suited for this purpose?

  1. APrimitive Data Type
  2. BFunction
  3. CObject / Struct
  4. DArray
Show answer & explanation

Correct answer: C. Object / Struct

An Object (or Struct in some languages) is a composite data type that allows you to group related data of different types under a single name. This is ideal for representing an entity like a 'Task' with distinct properties such as 'name' (string), 'due date' (date/string), and 'completion status' (boolean).

Why the other options are wrong

  • A. A Primitive Data Type (like integer, string, boolean) holds a single value, not a collection of related values for an entity.
  • B. A Function is a block of code that performs an action, not a structure for grouping related data.
  • D. An Array typically stores a collection of items of the same data type, not different types for a single entity.

Object / Struct (Composite Data Type)

An object (or struct in languages like C/C++) is a composite data type that groups together related data items, potentially of different types, under a single name, representing a single entity.

  • Allows combining multiple data types into one logical unit.
  • Provides a way to model real-world entities.
  • In OOP, objects also include methods (behaviors).

Memory trick: An Object/Struct is like a personalized folder for all an item's details.

More Software Development Concepts questions