Computer Programming

J Mwaura

Mode of Course Delivery

  1. Lectures
  2. Online tutorials
  3. Practical(s)
  4. Assignment(s)
  5. Presentation(s)

Course Outline

  1. Comparative study of structured & object-oriented programming techniques;
  2. abstraction, objects, classes,
  3. inheritance, polymorphism,
  4. abstract vs. concrete classes,
  5. constructors and destructors
  6. Programming in an object oriented programming language such as C++, Java
  7. Applications to engineering problems

Why C++ Programming?

Computer Programming

J Mwaura

C

  • This is great if you need to code a device driver, not great if you need to create a web application
  • GIS project written in C; GDAL

C++

  • Majority software are written in C++ - Portable
  • It's preferable to most companies to develop applications
  • GIS softwares written in C++; GRASS GIS, QGIS (+python)
  • Most GPS receivers firmware are written in C++
  • C++ is a certainly good language to know

Summary: Programming Languages used in GIS

GIS scripting and applications (Python, R)

Data processing, analysis, and modeling (Python, R)

Web mapping (JavaScript, Python)

Geospatial databases (SQL, NoSQL)

Map Servers (Java, C#, .NET, C++)

GIS heavy-weight development (Java, C/C++, C#)

Mobile development (Android, iOS, JavaScript)

Geospatial libraries (JavaScript, Python, Java, R, C/C++)

Principle of C++ OOP

The 3 cornerstones of Object Oriented Programming (OOP);

  • Encapsulation,
  • Inheritance and,
  • Polymorphism

Lecture 1: Arrays

Computer Programming

J Mwaura

Arrays

An array is a compound type that defines a sequence of data items of the same type

Array Attributes

  • Type
    1. The type of all data items in an array must be the same; the array type is the type of the elements
    2. For example, we can have an int array, a double array, a char array, and a Circle array
  • Capacity
    1. This is the maximum number of elements an array can hold
    2. This attribute is either a literal or a constant value that cannot be changed after the array is declared
    3. For constant & literal, use uppercase

Attributes of arrays

  • Size
    1. Array size defines the number of valid elements at each moment
Attributes of arrays

Array Declaration

Array declaration/definition gives an array a name, sets the type of the elements, sets the capacity of the array, and allocates memory locations for the array

arrays arrays arrays

Memory Allocation

The array elements are referenced using zero indexing

The index starts from [0] and goes to [CAPACITY - 1]

arrays

Accessing Array Elements

Two-Dimensional Arrays

A two-dimensional array defines a structured data type in which two indices are used to define the location of elements in rows and columns

The 1st index defines the row; the 2nd index defines the column

int scores [5][3] = {{82,65,72},{73,70,80},{91,76,40},{72,72,68},{65,90,80}};

2d

Bitbucket: Arrays


Home: Arrays

Three-Dimensional Arrays

C++ supports three dimension arrays

But, arrays with more than three dimensions are rare

3d

End of Lecture 1

Computer Programming

That's it!

Queries about this Lesson, please send them to: jmwaura.uni@gmail.com

*References*

  • C++ Programming - An Object-Oriented Approach, 2019 Behrouz, Richard et.al
  • Accelerated C++ - Practical Programming by Example, 2000 Andrew, Barbara et.al
Courtesy of
Computer Programming