Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
C++ Classes & Data Abstraction
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
Learners Support Publications Classes and Objects.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
Introduction to Object-Oriented Programming Lesson 2.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Lecture 19: Introduction to Classes Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
CITA 342 Section 1 Object Oriented Programming (OOP)
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Matthew Small Introduction to Object-Oriented Programming.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
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.
CSIS 123A Lecture 1 Intro To Classes Glenn Stevenson CSIS 113A MSJC.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Creating Your Own Classes
Classes (Part 1) Lecture 3
Classes C++ representation of an object
Object-Oriented Programming: Classes and Objects
Objects as a programming concept
Chapter 7: Introduction to Classes and Objects
Abstract Data Types Programmer-created data types that specify
Review: Two Programming Paradigms
Table of Contents Class Objects.
Classes & Objects.
Chapter 5 Classes.
Lecture 9 Concepts of Programming Languages
CS212: Object Oriented Analysis and Design
Introduction to Classes
Chapter 9 Objects and Classes
Classes and Objects.
Defining Classes and Methods
Submitted By : Veenu Saini Lecturer (IT)
Classes C++ representation of an object
Lecture 8 Object Oriented Programming (OOP)
Classes and Objects Systems Programming.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Computer Programming II Lecture 5

Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming and object-oriented programming (OOP). - Procedural programming : In a procedural program data is typically stored in a collection of variables and there is a set of functions that perform operations on the data. The data and the functions are separate entities. - Object-oriented programming : is centered around objects that encapsulate both data and the functions that operate on them.

Object Oriented Programming (OOP) There are a few principle concepts that form the foundation of object-oriented programming : 1- Abstraction : - An abstraction is a general model of something. It is a definition that includes only the general characteristics of an object without the details that characterize specific instances of the object. - An abstract data type (ADT) is a data type that specifies the values the data type can hold and the operations that can be done on them without the details of how the data type is implemented.

Object Oriented Programming (OOP) 2- Class: A class is a programmer-defined data type that describes what an object of the class will look like when it is created. It consists of a set of variables and a set of functions. 3- Objects: Objects are instances of a class. They are created with a definition statement after the class has been declared. 4- Encapsulation : Encapsulation is placing the data and the functions that work on that data in the same place.

Object Oriented Programming (OOP) 5- Inheritance: - Inheritance allows to create classes which retain characteristics of the base class. - Inheritance involves a base class and a derived class. The base class is the general class and the derived class is the specialized class. The derived class is based on, or derived from, the base class. 6- Polymorphism: In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.

Classes and objects : - In C++, the class is the construct primarily used to create objects. - A class is a programmer-defined data type that describes what an object of the class will look like when it is created. It consists of a set of variables and a set of functions.

Classes and objects : Declaration: Classes are generally declared using the keyword class, with the following format: class class_name { access_specifier_1: member1; access_specifier_2: member2;... } object_names;

Classes and objects : - Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers. - An access specifier is one of the following three keywords: private, public or protected.

Classes and objects : - These specifiers modify the access rights that the members following them acquire: private members of a class are accessible only from within other members of the same class or from their friends. protected members are accessible from members of their same class and from their friends, but also from members of their derived classes. Finally, public members are accessible from anywhere where the object is visible.

Classes and objects : Example: class Crectangle { private: int x, y; public: void set_values (int a, int b); int area ( ); } rect;

Classes and objects : Accessing an Object’s Members: - Public members of a class object are accessed with the dot operator (.). - After the previous declarations of CRectangle and rect, we can refer within the body of the program to any of the public members of the object rect as if they were normal functions or normal variables, just by putting the object's name followed by a dot (.) operator and then the name of the member. For example : rect.set_values (3,4); myarea = rect.area();

This program is used to calculate the area of rectangle.

Classes and objects : Types of Member Functions: - Accessor, get, getter function: uses but does not modify a member variable. - A function that uses the value of a class variable but does not change it, is known as an accessor. - Mutator, set, setter function: modifies a member variable. - A function that stores a value in a member variable or changes its value, is known as a mutator.

Classes and objects : Defining Member Functions: - Member functions are part of a class declaration. Class member functions can be defined either inside or outside the class declaration. - When a class function is defined within the class declaration, it is called an inline function. Inline functions provide a convenient way to contain function information within a class declaration, but they can only be used when a function body is very short, usually a single line.

Classes and objects : - When a function body is longer, a prototype for the function should appear in the class declaration, instead of the function definition itself. The function definition is then placed outside the class declaration. - In the function definition, precede function name with class name and scope resolution operator ( :: ) - The ( : : ) symbol is called the scope resolution operator. It is needed to indicate that these are class member functions and to tell the compiler which class they belong to.

Classes and objects :

Write a C++ program to create a class called rectangle which used to calculate the area of rectangle. Note : Length and width are inserted by user. Area = Length * width.