Principles of Object-Oriented Software Development The language C++

Slides:



Advertisements
Similar presentations
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
C++ Classes & Data Abstraction
C++ Basics Variables, Identifiers, Assignments, Input/Output.
CPA: C++ Polymorphism Copyright © 2007 Mohamed Iqbal Pallipurath Overview of C++ Polymorphism Two main kinds of types in C++: native and user-defined –User-defined.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Principles of Object-Oriented Software Development The language Eiffel.
Principles of Object-Oriented Software Development The language Java.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
C++ Training Datascope Lawrence D’Antonio Lecture 1 Quiz 1.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Lecture 9 Concepts of Programming Languages
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
C++ Yeting Ge.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 12: Adding Functionality to Your Classes.
C++ C++ Overview (I) What is Object Orientated Programming? Approach: Break problem into subgroups of related parts that take into account code and data;
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
OOP, Virtual Functions and Inheritance
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
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.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
1 Abstract Data Types & Object Orientation Abstract Data Types (ADT) Concepts –Data Abstraction –ADT in PLs –Encapsulation Object Orientation –Principal.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object-Oriented Programming Chapter Chapter
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
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.
ISBN Object-Oriented Programming Chapter Chapter
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Overview of C++ Polymorphism
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Classes: Defining Your Own Data Types Basic principles in OOP Define a new data type as a class and use objects of a class Member Functions –Constructors.
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Introduction to Computers Computer Generations
Classes and Inheritance
Abstract Data Types and Encapsulation Concepts
C++, OBJECT ORIENTED PROGRAMMING
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Orientated Programming
Reserved Words.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Overview of C++ Polymorphism
CS410 – Software Engineering Lecture #5: C++ Basics III
Lecture 10 Concepts of Programming Languages
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Principles of Object-Oriented Software Development The language C++

Introduction Terminology Expressions Control Objects Inheritance Techniques Summary

C++ -- is much more than a better C 1972 C Kernigan and Ritchi (Unix) 1983 C++ (Simula 1967) 1985 ANSI/ISO C 1996 ANSI/ISO C++ Design principles -- the benefits of efficiency superset of C -- supporting OOP static typing -- with user-defined exceptions explicit -- no default virtual functions extensible -- libraries in C and C++

Keywords: inline, new, delete, private, protected, public C++ overview Language features: constructors -- to create and initialize destructors -- to reclaim resources virtual functions -- dynamic binding (multiple) inheritance -- for refinement type conversions -- to express relations between types private, protected, public -- for access protection friends -- to allow for efficient access

Some basic terminology name -- denotes an object, a function, set of functions, enumerator, type, class member, template, a value or a label introduced by a declaration, used within a scope, and has a type which determines its use. object -- region of storage a named object has a storage class that determines its lifetime, and the meaning of the values found in an object is determined by the type of the expression used to access it C++ -- terminology (2)

Type expressions basic types -- int, char, float,... array -- int ar[SIZE] function -- void f(int) pointer -- int*, char*, void (*f)(int) reference -- int&, char*& class, union, struct -- user-defined

operators -- +, -,.., <, <=,.., ==, !=,.., &&, || indexing -- o[ e ] application -- o(...) access -- o.m(...) dereference -- p->m(...) in/decrement -- o++, o-- conditional -- b?e:e2 Assignment var = expression modifying -- +=. -=,... C++ -- expressions (2)

Control conditional -- if (b) S1; else S2; selection -- switch(n) { case : n1: S1; break;... default:... } iteration -- while (b) S looping -- for( int i = 1; i <= MAX; i + + ) S jumps -- return, break, continue, goto

ADT in C style struct ctr { int n; } void ctr_init(ctr& c) { c.n = 0; } void ctr_add(ctr& c, int i = 1) { c.n = c.n + i; } int ctr_val(ctr& c) { return c.n; } Usage ctr c; ctr_init(c); ctr_add(c,1); cout << ctr_val(c); ctr* p = new ctr; ctr_init(*p); ctr_add(*p);

ADT in C++ class ctr { public: ctr() { n = 0; } constructor ~ctr() { cout << "bye"; }; destructor void add( int i = 1) { n = n + i; } int val( ) { return n; } private: int n; }; Usage ctr c; c.add(1); cout << c.val(); ctr* p = new ctr(); c->add(1); cout val();

Inheritance class A { ancestor public: A() { n = 0; } void add( int i ) { n = n + i; } virtual int val() { return n; } protected: private would deny access to D int n; }; class D : public A { descendant public: D() : A() { } int val() { return n \% 2; } };

Techniques templates -- template class C {... } overloading -- void read(int); voi read(float) friends -- to bypass protection type conversions -- by class constructors or type operators type coercion -- by explicit casts (is dangerous) smart pointers -- by overloading de-reference

class ctr { C++ techniques public: ctr(int i = 0) { n = i; } ctr(const char* s = "0") { n = itoa(s); } void operator++() { n = n + 1; } int operator()() { return n; } operator char*() { return atoi(n); } private: int n; }; Usage ctr c; c++; cout << (char*) c << " is " << c();

The language C++ design principles -- efficiency terminology -- object, type syntax -- object, reference, pointer objects -- abstract data types inheritance -- virtual functions techniques -- operators, templates, overloading