Docsity

Chapter 4 Compound Data Types, Lecture notes of Programming Paradigms

Toggle sidebar
bg1
Chapter 4
Compound Data Types
4.1 Arrays
➢ a structured datatype is composed of several data items in which each data item
a simple data type
One Dimensional
→ Array is a group of similar datatypes with a fixed number of
components.
→ One-dimensional array - collection of similar datatypes in list
form
• Each element has a unique number starting from zero (0)
and ending at n – 1, where n is the fixed size of the array.
• Declaration and initialization of the array
• Accessing values on the array
• If the size of the array would increase
Two Dimensional Array
→ stored data is manipulated using table from
→ intend to perform matrix manipulation, the elements are stored on
row and column coordinates.
• Declaring and initializing a two dimensional array
pf3
pf4
pf5

Partial preview of the text

Download Chapter 4 Compound Data Types and more Lecture notes Programming Paradigms in PDF only on Docsity!

Chapter 4

Compound Data Types

4.1 Arrays

➢ a structured datatype is composed of several data items in which each data item a simple data type One Dimensional → Array is a group of similar datatypes with a fixed number of components. → One-dimensional array - collection of similar datatypes in list form

  • Each element has a unique number starting from zero (0) and ending at n – 1, where n is the fixed size of the array.
  • Declaration and initialization of the array
  • Accessing values on the array
  • If the size of the array would increase Two Dimensional Array → stored data is manipulated using table from → intend to perform matrix manipulation, the elements are stored on row and column coordinates.
  • Declaring and initializing a two dimensional array
  • Accessing the values on a two-dimensional array Passing arrays to functions
  • passing a one-dimensional array
  • Two dimensional arrays Array Manipulations (Searching and Sorting) → perform the searching process by comparing the search item on each individual element on the array
  • Implements a sequential search and would determine if the search item exist or not exist on the list

4.2.Strings

C-style String → header → Strings - an array of characters enclosed in double quotation marks. → C-strings are null (i.e. \0) terminated, so the null character must only appear on the last position of the string → Basic function include, copying, comparing and determining the length. → Favorable way of inputting data to a character array String Class Type → #include → provides a convenient way of processing character array

  • Declare a string object
  • To access elements, modify contents, and compare strings Vector Class Type https://www.cplusplus.com/reference/vector/vector/ → include → the flexibility over arrays since it can grow and shrink in size during runtime
  • Declaring a vector object
  • Basic operations such insertion, deletion and getting the value