Chapter 4 Compound Data Types, Lecture notes of Programming Paradigms

The concepts of arrays and vectors in C++. It starts with the definition of a one-dimensional array and its declaration, initialization, and accessing values. Then, it explains two-dimensional arrays and how to declare and initialize them. The document also covers passing arrays to functions and array manipulations such as searching and sorting. Finally, it introduces the vector class type, which is more flexible than arrays since it can grow and shrink in size during runtime. how to declare a vector object and perform basic operations such as insertion, deletion, and getting the value.

Typology: Lecture notes

2020/2021

Available from 04/02/2022

gwen-hermo
gwen-hermo 🇵🇭

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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