Data Structure and Algorithm: CIT231 Lecture 4: ADT and Introduction to Object Oriented Programming (OOP) DeSiaMore www.desiamore.com/ifm DeSiaMorewww.desiamore.com/ifm1.

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

PROGRAMMING LANGUAGE (JAVA) UNIT 42 BY ROBERT BUTTERFIELD TELEPHONE Data Structures and Algorithms.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Introduction to Programming Lecture 39. Copy Constructor.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
C++ Classes & Data Abstraction
Visual Basic: An Object Oriented Approach 2 – Designing Software Systems.
1 Objects and ClassesStefan Kluth 1.6Objects and Classes 1.6What is an Object? 1.7Objects and Classes 1.8Object Interface, Class Inheritance, Polymorphism.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
1 Lecture 29 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Lecture 9 Concepts of Programming Languages
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
C++ fundamentals.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Introduction to Object-oriented programming and software development Lecture 1.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Object Oriented Programming (OOPs) Class Object Data Hiding Abstraction Encapsulation Polymorphism Inheritance Difference between Procedural and OOPs programming.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 5 – Dynamic Data Structure Par1: Abstract Data Type DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
C++ Lecture 4 Tuesday, 15 July Struct & Classes l Structure in C++ l Classes and data abstraction l Class scope l Constructors and destructors l.
Salman Marvasti Sharif University of Technology Winter 2015.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
ISBN Chapter 12 Support for Object-Oriented Programming.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.1 Fundamental Concepts.
Programming Logic and Design Seventh Edition
Class and Objects UNIT II.
Andy Wang Object Oriented Programming in C++ COP 3330
About the Presentations
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object-Oriented Programming Using C++
Object-oriented programming principles
Lecture 9 Concepts of Programming Languages
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented Programming
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Introduction to Data Structure
Object-Oriented Programming Using C++
Object-Oriented Programming
CECS 130 Final Exam Review Session
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Data Structure and Algorithm: CIT231 Lecture 4: ADT and Introduction to Object Oriented Programming (OOP) DeSiaMore DeSiaMorewww.desiamore.com/ifm1

Introduction to Object Oriented Programming In this lecture you will learn the general concepts of Object Oriented Programming (OOP). Inheritance Encapsulation Polymorphism Object Oriented Programming is very powerful and important programming paradigm. DeSiaMorewww.desiamore.com/ifm2

Introduction to Object Oriented Programming Most of the nowadays sophisticated application software have been developed in Objected Oriented languages and mostly in C++. E.g. Word processors, spreadsheets, and graphics applications. Also some Operating Systems are written in OO languages. DeSiaMorewww.desiamore.com/ifm3

Fundamental terms and Principles of the OOP Attribute – The data for a class that maintains the current state of an object. The state of an object is determined by the current contents of all the attributes. Object – An object is a something that exists and is identifiable. An object exhibits behaviour and maintains state. Example of objects are telephones, automobiles, buildings, animals, etc. DeSiaMorewww.desiamore.com/ifm4

Fundamental terms and Principles of the OOP Class – Class is a synonymous with type. A class specifies a traits (data) and behaviour that an object can exhibit. A class itself does not exists. It is only a description of an object. A blueprint is analogous to a class and building itself is the object. A class can be considered a template for the creation of objects. DeSiaMorewww.desiamore.com/ifm5

Fundamental terms and Principles of the OOP Inheritance – This is the relationship of classes. There is an explicit is-a relationship between classes. For example an automobile is-a vehicle, a zebra is-a mammal, a flower is-a plant, and so on. Interface – The visible functionality of a class. Is the contract an object makes with users of an object. Users manipulate an object through its interface. DeSiaMorewww.desiamore.com/ifm6

Fundamental terms and Principles of the OOP - Interface of a class is the part the clients see. An interface is considered a contract the class has with its client. - For example an automobile has an interface (contract) with its driver. An automobile’s interface includes a steering wheel, brake pedals, speedometer, and a clutch. - This interface provides functionality to the driver without the need to know the inner workings of the automobile. DeSiaMorewww.desiamore.com/ifm7

Fundamental terms and Principles of the OOP Implementation – The internal functionality and attributes of a class. A class’s implementation is hidden from users of the class. Encapsulation – Encompasses the interfaces and abstraction of a class. Abstraction – The generalisation of a class that distinguish it from other classes DeSiaMorewww.desiamore.com/ifm8

Fundamental terms and Principles of the OOP Understanding inheritance is a good starting point of learning object orientation. The concept of inheritance can be understood in analog to your family tree. The procedure to describe your family tree is the same to describe class inheritance in C++. DeSiaMorewww.desiamore.com/ifm9

Fundamental terms and Principles of the OOP Inheritance is known as an is-a relationship. Example a toyota is-a vehicle, a snake is-a reptile, and a flower is-a plant. To begin applying inheritance, you must decide a base class that must reside within your application. It provides basic, default functionality to users of the class. DeSiaMorewww.desiamore.com/ifm10

Access Specifier of the class The class in C++ contains three important access specifiers which provide conditions to access to the data members and functions (methods) of the class. These are Public Private Protected DeSiaMorewww.desiamore.com/ifm11

Access Specifier of the class Public – A class member with public visibility is accessible outside of the class. Private – A class member with private visibility can only be accessible by member functions of the class. Protected – A class member with protected visibility is accessible by member functions of the class and its descendents. DeSiaMorewww.desiamore.com/ifm12

MATRIX Operation with the use of Class #include Const int MAX = 3; Class Matrix { Private: Int mat[MAX][MAX]; Public: Matrix(); void create (); void display (); }; DeSiaMorewww.desiamore.com/ifm13

Initialise Matrix() Matrix::Matrix() { for(int i=0; i<MAX; i++) { for (int j=0; j<MAX; j++) mat[i][j]=0; } DeSiaMorewww.desiamore.com/ifm14

Create matrix() //Create matrix mat Void Matrix::create() { int n; for (int i=0; i<MAX; i++) { for (int j = 0; j<MAX; j++) { cout<<“Enter the element: ”; cin>>n; mat[i][j] = n; } DeSiaMorewww.desiamore.com/ifm15

Display matrix() //displays the contents of the matrix Void Matrix::display(); { for (int i=0; i<MAX; i++) { for (int j=0; j<MAX; j++) cout<<mat[i][j]<<“ ”; cout<<endl; } DeSiaMorewww.desiamore.com/ifm16

Create the object of Matrix in the Main program void main() { matrix mat1; cout<<"\nEnter the elements of the array: \n"; mat1.create(); cout<<"Your array is:\n"; mat1.display(); } DeSiaMorewww.desiamore.com/ifm17

Pointers A pointer is a variable which stores the address of another variable. There are two important operators when working with pointers in C++: the address of (&) operator the value of (*) operator How much storage space does a pointer consume? Use sizeof(ptr) without the '*‘ operator to determine the memory utilised on your system DeSiaMorewww.desiamore.com/ifm18

Pointers Irrespective of datatype or whether the pointer points to a single variable or array, as a general rule, pointers must use the same amount of memory space. The & operator gives us the address of a variable and * gives us the value of a variable at a specified address. Example:- DeSiaMorewww.desiamore.com/ifm19

Example of the use of * and & #include int main() { int i = 10; cout << "The value of variable i is " << i << "\n"; cout << "The memory address of i is " << &i << "\n"; /* Prints the memory address in hexadecimal format */ cout << "The value of variable i using * operator is "<< *(&i) <<"\n"; /* The * operator gives the value when provided with a memory address. Note that the dsta type is inferred from the variable name. */ system("PAUSE"); return 0; } DeSiaMorewww.desiamore.com/ifm20

Pointer Example #include int main() { int i = 10; int *x = &i; int *y; /* x stores the address of variable i. Pointer assignment could also be done as */ y = &i; cout <<"The pointer x is stored at the mempory address "<< &x << "\n"; cout <<"The pointer x stores the memory address of i: " << y << "\n"; /* Contrast the difference between the memory address of the pointer and the memory address it stores. */ cout<< "The value of i accessed through pointer x is " << *x << "\n"; /* Now we manipulate the value of i using pointer x; */ *x = *x + 1; // increment i by 1 cout<< "i (through pointer) = " << *x << " which equals i (direct access) " << i << "\n"; /* A pointer does not create a copy of the variable it points to. */ cout<<"The memory allocated to the pointer x is " << sizeof(x) << " bytes. "; system("pause"); return 0; } DeSiaMorewww.desiamore.com/ifm21

Array as Pointers In C++ array starts at position 0. The elements of the array occupy adjacent locations in memory. C++ treats the name of the array as if it was the pointer to the first element. If v is an array, *v is the same thing as v[0], *(v+1) is the same thing as v[1] as diagram below shows: DeSiaMorewww.desiamore.com/ifm22

Array as Pointers Pointer use for an array DeSiaMorewww.desiamore.com/ifm23

Exercise Using matrix arrays, write a program to create two matrices and then create methods of adding and subtracting those matrices. DeSiaMorewww.desiamore.com/ifm24

Next Topic String ADT and array of characters DeSiaMorewww.desiamore.com/ifm25