C Programming for Engineers Data Structure & Object Oriented - - PowerPoint PPT Presentation

c programming for engineers data structure object
SMART_READER_LITE
LIVE PREVIEW

C Programming for Engineers Data Structure & Object Oriented - - PowerPoint PPT Presentation

C Programming for Engineers Data Structure & Object Oriented Programming ICEN 200 Spring 2018 Prof. Dola Saha 1 Data Structures Weve studied fixed-size data structures such as single- subscripted arrays, double-subscripted


slide-1
SLIDE 1

1

C Programming for Engineers Data Structure & Object Oriented Programming

ICEN 200– Spring 2018

  • Prof. Dola Saha
slide-2
SLIDE 2

2

Data Structures

Ø We’ve studied fixed-size data structures such as single-

subscripted arrays, double-subscripted arrays and structs.

Ø This topic introduces dynamic data structures with sizes

that grow and shrink at execution time.

§ Linked lists are collections of data items “lined up in a row”—insertions and deletions are made anywhere in a linked list. § Stacks are important in compilers and operating systems—insertions and deletions are made only at one end of a stack—its top. § Queues represent waiting lines; insertions are made only at the back (also referred to as the tail) of a queue and deletions are made only from the front (also referred to as the head) of a queue. § Binary trees facilitate high-speed searching and sorting of data, efficient elimination of duplicate data items, representing file system directories and compiling expressions into machine language.

slide-3
SLIDE 3

3

Linked List

Ø Linked lists are collections of data items “lined up in a row”—

insertions and deletions are made anywhere in a linked list.

Ø Linear Linked List Ø Doubly linked list Ø Circular linked list

slide-4
SLIDE 4

4

Stacks

Ø Stacks are important in compilers and operating systems—

insertions and deletions are made only at one end of a stack—its top.

Ø Stack is referred to as LIFO (last-in-first-out). Ø PUSH Ø POP

slide-5
SLIDE 5

5

Stack – PUSH & POP

5 . 2 . 3 …

topPtr

. 5 . 2 . 3 …

topPtr

. 8 .

PUSH

5 . 2 . 3 …

topPtr

.

POP

slide-6
SLIDE 6

6

Queues

Ø

Queues represent waiting lines; insertions are made only at the back (also referred to as the tail) of a queue and deletions are made only from the front (also referred to as the head) of a queue.

Ø

Used in networking when packets are queued to move from one layer to another.

Ø

Enqueue

Ø

Dequeue

slide-7
SLIDE 7

7

Trees

Ø

A tree is a nonlinear, two-dimensional data structure with special properties.

Ø

Tree nodes contain two or more links.

Ø

Binary trees facilitate high-speed searching and sorting of data, efficient elimination of duplicate data items, representing file system directories and compiling expressions into machine language.

slide-8
SLIDE 8

8

Self Referencing Structures

Ø A self-referential structure contains a pointer member

that points to a structure of the same structure type.

Ø Example:

  • struct node {

int data; struct node *nextPtr; };

defines a type, struct node.

Ø A structure of type struct node has two members—

integer member data and pointer member nextPtr.

slide-9
SLIDE 9

9

Linked List graphical representation

slide-10
SLIDE 10

10

Insert a node in order in a list

slide-11
SLIDE 11

11

Insert a node – C code

slide-12
SLIDE 12

12

Delete a node from list

slide-13
SLIDE 13

13

Delete a node – C code

slide-14
SLIDE 14

14

Evolution of computers

Ø Early computers were far less complex than today’s

computers

Ø Modern computers are smaller, but more complex

slide-15
SLIDE 15

15

Objects

Ø Computer scientists have introduced the notion of

  • bjects and object-oriented programming to help

manage the growing complexity of modern computers.

Ø Object is anything that can be represented by data in

computer’s memory

slide-16
SLIDE 16

16

Properties

Ø The data that represent the

  • bject are organized into a

set of properties.

Ø The values stored in an

  • bject’s properties at any
  • ne time form the state of

an object.

Name: PA 3794 Owner: US Airlines Location: 39 52′ 06″ N 75 13′ 52″ W Heading: 271° Altitude: 19 m AirSpeed: 0 Make: Boeing Model: 737 Weight: 32,820 kg

slide-17
SLIDE 17

17

Methods

Ø In object-oriented programming, the programs that

manipulate the properties of an object are the

  • bject’s methods.

Ø We can think of an object as a collection of properties

and the methods that are used to manipulate those properties.

slide-18
SLIDE 18

18

Class

Ø A class is a group of objects with the same properties

and the same methods. Class <CAR>

Object <7_series_BMW> Object <Ford_Mustang> Object <VW_Beetle>

slide-19
SLIDE 19

19

Instance

Ø Each copy of an object from a

particular class is called an instance of the object.

Ø The act of creating a new instance of

an object is called instantiation.

Ø Two different instances of the same

class will have the same properties, but different values stored in those properties.

slide-20
SLIDE 20

20

Terminology

The same terminology is used in most object-oriented programming languages.

Object Instance Property Method Instantiation Class State

slide-21
SLIDE 21

21

First OOP in C++

slide-22
SLIDE 22

22

Access Specifier: Public & Private

Ø Keyword public or private is an access specifier. Ø Access specifiers are always followed by a colon (:) Ø Public: Ø Accessible to public—that is, it can be called by other

functions in the program (such as main), and by member functions / methods of other classes (if there are any). Ø Private:

Ø Accessible only to member functions / methods of the

class for which they are declared.

slide-23
SLIDE 23

23

Passing value

slide-24
SLIDE 24

24

Example object with properties & methods (1)

slide-25
SLIDE 25

25

Example object with properties & methods (2)

slide-26
SLIDE 26

26

Example object with properties & methods (3)

slide-27
SLIDE 27

27

Constructor and Destructor

Ø A constructor is a special function that gets called

automatically when the object of a class is created.

Ø A destructor is a special function that gets called

automatically when an object is deleted.

slide-28
SLIDE 28

28

Constructor Example

slide-29
SLIDE 29

29

Constructor Example

slide-30
SLIDE 30

30

Constructor Example

slide-31
SLIDE 31

31

Separate Function definition & declaration

slide-32
SLIDE 32

32

Separate Function definition & declaration

slide-33
SLIDE 33

33

Separate Function definition & declaration