Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.

Slides:



Advertisements
Similar presentations
Object-Oriented PHP (1)
Advertisements

1 CS 201 Introduction to c++ (1) Debzani Deb. 2 History of C++ Extension of C (C++ for better C) Early 1980s: Bjarne Stroustrup (Bell Laboratories) Provides.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 16: Classes and Data Abstraction Outline 16.1Introduction.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Chapter 12: Adding Functionality to Your Classes.
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.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Introduction to C++ Systems Programming. Systems Programming: Introduction to C++ 2 Systems Programming: 2 Introduction to C++  Syntax differences between.
Object Oriented Programming Elhanan Borenstein copyrights © Elhanan Borenstein.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Learners Support Publications Classes and Objects.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 25P. 1Winter Quarter C++: I/O and Classes Lecture 25.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
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
Learners Support Publications Object Oriented Programming.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Object Oriented Programming
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
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.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object-Oriented Programming (OOP) and C++
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++
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Chapter 15 - C++ As A "Better C"
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Abstract Data Types Programmer-created data types that specify
Introduction to C++ Systems Programming.
OOP What is problem? Solution? OOP
Review: Two Programming Paradigms
About the Presentations
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
(5 - 1) Object-Oriented Programming (OOP) and C++
Object Oriented Analysis and Design
Corresponds with Chapter 7
OOP vs Structured Programming
Classes and Objects.
(5 - 1) Object-Oriented Programming (OOP) and C++
Principles of object – oriented programming UNIT-1 Chapter-1.
C++ Object Oriented 1.
Presentation transcript:

Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope and accessing members - access functions and utility functions. Unit - V

History of C++ –Extension of C –Early 1980s: Bjarne Stroustrup (Bell Laboratories) –Originally named “C with Classes”. –Provides capabilities for object-oriented programming Objects: reusable software components –Model items in real world Object-oriented programs –Easy to understand, correct and modify –Hybrid language C-like style Object-oriented style Both

Object Oriented Programming OOP is a programming style that is focused on objects Important Features of OOP –Abstraction –Encapsulation –Inheritance –Polymorphism

Abstraction Showing only the essential features and hiding the unnecessary features The access modifiers in C++ or any OOP language, provides abstraction Functions also provide abstraction If a variable is declared as private, then other classes cannot access it The function name that is used in function call hides the implementation details from user. It shows only the outline of functionality that the function provides.

Encapsulation The process of bringing together the data and method of an object is called as encapsulation The data and method are given in the class definition Classes provides us with this feature - Encapsulation

Inheritance Feature that enables the characteristics or properties of a parent to reach its child C++ supports inheritance A class can inherit one or more classes Inherited class is called as parent class or super class or base class Class that inherits a parent class is called as child class or sub class or derived class

Polymorphism Poly – Many Morph – Form Polymorphism is the characteristic that enables an entity to co exist in more than one form C++ supports function overloading and operator overloading to implement polymorphism

Structured Vs OOP StructuredOOP Focuses on ProcessFocuses on Object Follows Top Down Approach Follows Bottom Up Approach

Top Down approach –A Single module will be split into several smaller modules –General to Specific Bottom Up approach –Lot of small modules will be grouped to form a single large module –Specific to General If the requirements are clear at the first instance we can go for Top down approach In circumstances where the requirements may keep on adding, we go for Bottom up approach

MAIN PROGRAM FUNCTION 3FUNCTION 2 GLOBAL DATA FUNCTION 5FUNCTION 4 FUNCTION 1 Using function Function & program is divided into modules Every module has its own data and function which can be called by other modules. Structured Programming

OBJECT ORIENTED PROGRAMMING Object 1 Object 2 Data Function Data Function Object 3 Data Function Objects have both data and methods Objects of the same class have the same data elements and methods Objects send and receive messages to invoke actions

I/O in C++ Since C++ is a superset of C, all of the C I/O functions such as printf and scanf which are found in the stdio.h header file, are still valid in C++. C++ provides an alternative with the new stream input/output features by including “iostream.h”. Several new I/O objects available when you include the iostream header file. Two important ones are: –cin// Used for keyboard input –cout// Used for screen output Both cin and cout can be combined with other member functions for a wide variety of special I/O capabilities in program applications.

Since cin and cout are C++ objects, they are somewhat "intelligent": –They do not require the usual format strings and conversion specifications. –They do automatically know what data types are involved. –They do not need the address operator, &. –They do require the use of the stream extraction ( >> ) and insertion ( << ) operators. The next slide shows an example of the use of cin and cout.

11/30/ Classes in C++ Class is defined as: A collection of related variables and functions into a single structure A user-defined complex data type with its own operations Object: Instances of the class are called objects. The variables and functions in the definition of the class are called members. Syntax to create a Class: class class-name { private data and functions access-specifier: data and functions access-specifier: data and functions //... access-specifier: data and functions } object-list; The object-list is optional. If present, it declares objects of the class.

11/30/ access-specifier is one of these three C++ keywords: public private (default) Protected - private data can be accessed only by other members of the class. - public data can be accessed by other parts of the program - protected needed only when inheritance is involved. - access-specifier can be changed in any order, default is private. Class Scope Class data members and member functions belong to that class's scope. Within a class's scope, class members are references by name. Outside a class's scope, class members are referenced through one of the handles on an object. Use dot (.) notation for object and references. Use arrow (->) for pointer to the object E.g., c.x, cpt -> x

Implementation of a Class Class declaration contains:  Declarations of data members  Prototypes (declarations) of function members Definitions of function members are not usually placed in class declaration Definitions placed outside the class declaration must tell compiler where the corresponding declaration/prototype is : Use the scope operator :: which has the form ClassName::ItemName

1. Member functions: "Inside" an object, so don't pass object to them as a parameter. (They receive the object to be operated on implicitly, rather than explicitly via a parameter.) Non-member functions: "Outside" an object, so to operate on an object, they must receive it via a parameter. 2. Public items must be qualified when referred to outside the class declaration: ClassName::ItemName Public constants are usually declared static so they are global class properties that can be accessed by all objects of that class type rather than each object having its own copy. 3.Simple member functions: Usually specified as inline functions. This suggests to compiler to replace a function call with actual code of the function with parameters replaced by arguments — saves overhead of function call.

Access Functions and Utility Functions Utility functions –private functions that support the operation of public functions –Not intended to be used directly by clients Access functions –public functions that read/display data or check conditions –For a data structure, it could call the isEmpty function

Assignment Distinguish between a `struct' and a `class' in C++? 2.How does a class accomplish data hiding? Explain with an example. 3.Explain the benefits of object oriented programming over procedure oriented programming 4.What are the access privileges in C++? What is the default access level? 5.What do you mean by Encapsulation and explain in detail. 6.What is the difference between “C structure” and “C++ structure”. 7.Explain about the C++ classes in detail and design a class for playing cards? 8.Discuss in detail about utility functions and access functions.