Programming, numerics and optimization

Size: px
Start display at page:

Download "Programming, numerics and optimization"

Transcription

1 Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski Institute of Fundamental Technological Research Room 4.32, Phone ext. 428 April 17, Current version is available at ljank. 1/51

2 Disclaimer I do realize that For those of you that know OOP, this lecture will contain nothing new. For those of you that do not know OOP, this lecture will be much too condensed. OOP would require a dedicated course. OOP is required for HW6 and HW7. If OOP/C++ is new for you, these HWs will probably demand a lot of additional work. 2/51

3 Outline 1 Object-oriented programming (OOP) 2 Objects and classes 3 Creating and destroying objects 4 Overloaded operators 5 STL vector class 6 Homework 6 3/51

4 Outline 1 Object-oriented programming (OOP) Basic idea Objects and classes Basic concepts Advantages and disadvantages 2 Objects and classes 3 Creating and destroying objects 4 Overloaded operators 5 STL vector class 6 Homework 6 4/51

5 Object-oriented programming (OOP) Structure of a typical non-object code 5/51

6 Object-oriented programming (OOP) Objects (may) bring order 6/51

7 Object-oriented programming (OOP) Object paradigm is an answer to the following deficiencies of procedural programming: Data separated from processing information. The code (and the real problem it solves) scattered into separate, unrelated data chunks and functions. 7/51

8 Objects and classes Types in C++ 1 Fundamental: bool, char, int, float, double, void, 2 Compound (built-in or user-defined): pointers, arrays, structures, classes, Classes are user-defined types, which group together: Data (internal content of an object), e.g. matrix elements Functions (often called methods) Defining operations on the data, e.g. matrix :: det() Responsible for the behavior of an object, e.g. point :: show() 8/51

9 Objects and classes Classes corresponds to types. Objects (of a given class) correspond to variables (of a given type). An object is called to be an instance of his class. The idea is to have e.g. a type (class) vector to use it like int: i n t a = 5, b = 2, c ; c = 2 a b ; cout <<c ; v e c t o r a ( 5, 4 ), b ( 1 2, 1 ), c ; c = a b ; cout <<c. norm ( ) ; Data: Functions: vector elements multiplication, addition, subtraction, showing etc. 9/51

10 Basic concepts OOP is described in a variety of ways: from ideologically negative (e.g. hard-core proponents of functional programming), to pragmatic, to ideologically positive ( an OO program is an ensemble of communicating agents ). There is no a generally-agreed set of features, an OO language should support. However, the typical features include: Encapsulation Inheritance Polymorphism Dynamic dispatch 10/51

11 Basic concepts Encapsulation Encapsulation usually refers to grouping together data with functions that operate on them E.g. an object matrix might bundle matrix entries together with methods like det(). protecting a part of the internal data of an object from external access and modifications E.g. matrix entries might be private data (accessible only indirectly). 11/51

12 Basic concepts Inheritance Classes in an OO language can form a class hierarchy. Objects of the derived class inherit their properties (data & methods) from the base class, specialize the base class. 12/51

13 Basic concepts Multiple inheritance Some of OO languages (like C++) allow multiple inheritance. With inheritance, parent classes are often abstract classes 2. 2 An abstract class is non-instantiable (each actual vehicle must be either an electric car or an electric locomotive or a diesel locomotive etc.: there is no such a thing as a pure vehicle ). 13/51

14 Basic concepts Polymorphism, dynamic dispatch The (possibly abstract) class shape might have a (virtual) member function shape.draw(). This function is inherited by the derived classes, which have to implement it according to their characteristics. Assume we have an array of pointers to different shapes. Thanks to polymorphism, they can be all treated as being of the (possibly abstract) type shape. The array can be thus defined as shape ptr[shape_no];. Thanks to dynamic dispatch, given an object of the class shape, it can be ordered to be drawn by calling the method shape.draw(). Depending on its actual type (circle? cube?), the method of the proper derived class will be executed (decided upon not during compilation, but in runtime when the type of the actual object is known). 14/51

15 Advantages and disadvantages Advantages of OOP better representation of real-world entities by grouping together data with operations (e.g. a matrix is no longer just a 2D array but a matrix), inheritance, polymorphism, etc. hidden implementation details and protection of internal data operator overloading brings order into the system model and the code (easier production and maintenance) potential for reusability Disadvantages of OOP slower code code duplications additional abstraction layer 15/51

16 Outline 1 Object-oriented programming (OOP) 2 Objects and classes Class definition Pointers to objects Internal data 3 Creating and destroying objects 4 Overloaded operators 5 STL vector class 6 Homework 6 16/51

17 Objects and classes Class definition An object consists of Interface (e.g. for a matrix class: +,,, transpose(), det(), invert (), eigenvalues () etc.) Hidden implementation (internal data structures, internal operations etc.). c l a s s classname { p r i v a t e : // p r i v a t e data members // p r i v a t e f u n c t i o n s p u b l i c : // c l a s s i n t e r f a c e // p u b l i c data members ( not recommended ) // p u b l i c f u n c t i o n s } ; 17/51

18 Objects and classes Class definition example Class definition c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : void setxy ( i n t a, i n t b ) {x=a ; y=b ; } double getlength ( void ) const ; } ; // n o t i c e the s e m i c o l o n! double v e c t o r : : getlength ( void ) const { return s q r t ( x x+y y ) ; } The const modifier ensures here that the member function does not modify the object (its data members). 18/51

19 Objects and classes Class definition example Class definition i n t main ( void ) { v e c t o r a ; // o b j e c t d e f i n i t i o n a. setxy ( 1, 1 ) ; cout <<a. getlength ( ) <<e n d l ; // cout << a. x = <<a. x <<e n d l ; ERROR! system ( pause ) ; // f o r Dev C++ u s e r s o n l y return 0 ; } 19/51

20 Objects and classes Pointers to objects As variables of any other type, objects can be created and destroyed dynamically. i n t main ( ) { v e c t o r pa ; // p o i n t e r to a v a r i a b l e // o f the type v e c t o r pa = new v e c t o r ; // c r e a t e a v e c t o r pa >setxy ( 1, 1 ) ; cout <<pa >getlength ( ) <<e n d l ; delete pa ; // d e l e t e the o b j e c t pa pa = NULL ; } return 0 ; 20/51

21 Objects and classes Internal data Internal data are specific to each object, that is each object has its own set of the internal data. vector a,b; object a x =? y =?... object b x =? y =?... a.setxy(1,1); b.setxy(5,10); x = 1 y = 1... x = 5 y = /51

22 Outline 1 Object-oriented programming (OOP) 2 Objects and classes 3 Creating and destroying objects Constructor Destructor Copy constructor 4 Overloaded operators 5 STL vector class 6 Homework 6 22/51

23 Constructor Constructor is a special function, which is automatically called when a new object is created used to initialize internal variables, assign dynamic memory for internal storage etc. cannot be called at a later time Constructor must have the same name as the class has no return type (not even void) can be overloaded If no constructor is provided, a default constructor is automatically created (no arguments, no initialization). 23/51

24 Constructor example c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a, i n t b ) ; // c o n s t r u c t o r void setxy ( i n t a, i n t b ) {x=a ; y=b ; } double getlength ( void ) const ; } ; v e c t o r : : v e c t o r ( i n t a, i n t b ) { x = a ; y = b ; } 24/51

25 Constructor example vector a; vector a (1,2); vector pa; pa = new vector; pa = new vector(1,2); delete pa; ERROR: if there is a user-defined constructor, then no default constructor is created. But here the user-defined constructor for the class vector requires arguments. right! Call the user-defined constructor. a pointer to an object of the type vector ERROR: there is no no-argument constructor. right! 25/51

26 Overloaded constructors A class can have many constructors, provided they are distinguishable by the number or types of their arguments. c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( void ) ; // d e f a u l t c o n s t r u c t o r v e c t o r ( i n t a, i n t b ) ; // c o n s t r u c t o r void setxy ( i n t a, i n t b ) {x=a ; y=b ; } double getlength ( void ) const ; } ; v e c t o r : : v e c t o r ( i n t a, i n t b ) {x = a ; y = b ; } v e c t o r : : v e c t o r ( void ) {x = 0 ; y = 0 ; } 26/51

27 Constructor with default arguments As any other function, constructor can take default arguments. c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b =0); // c o n s t r u c t o r void setxy ( i n t a, i n t b ) {x=a ; y=b ; } double getlength ( void ) const ; } ; v e c t o r : : v e c t o r ( i n t a, i n t b ) { x = a ; y = b ; } 27/51

28 Destructor Destructor is a special function, which is automatically called when an object is destroyed (at end of its scope or when deleted with delete) used to clean-up (dynamic memory used by the object, closing open files etc.) Destructor must have the same name as the class, preceded with a tilde has void arguments and no return type (not even void) cannot be overloaded 28/51

29 Destructor example c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b =0); // c o n s t r u c t o r ~ v e c t o r ( void ) ; // d e s t r u c t o r //... } ; v e c t o r : : v e c t o r ( i n t a, i n t b ) { x = new i n t ( a ) ; y = new i n t ( b ) ; } v e c t o r : : ~ v e c t o r ( void ) { d e l e t e x ; d e l e t e y ; } 29/51

30 Destructor example If an object uses dynamic memory a user-defined constructor should be provided for allocation destructor should deallocate it to avoid memory leakage if there was only the default constructor vector a; x y...?????? with the user-defined constructor vector a (1,2); x y /51

31 Destructor example If an object uses dynamic memory a user-defined constructor should be provided for allocation destructor should deallocate it to avoid memory leakage without a user-defined destructor with a user-defined destructor x y... x y /51

32 Copy constructor Copy constructor is a special constructor, which is called whenever a new object is created (copied) from an existing object. If no user-defined copy constructor is provided, a default copy constructor is provided automatically (shallow: blindly copies internal variables). When a class uses dynamic memory, it should always have a user-defined copy constructor (deep: intelligently copying data pointed to, not the pointers only). Copy constructor is defined as a usual constructor, but with a single argument: a const object of the same type passed by reference. The current object (the one being created) is created (copied) from the passed object. 31/51

33 Copy constructor example c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( const v e c t o r &v ) ; // copy c o n s t r u c t o r v e c t o r ( i n t a, i n t b ) ; // c o n s t r u c t o r //... } ; v e c t o r : : v e c t o r ( const v e c t o r &v ) { x = new i n t ( v. x ) ; // a c c e s s to p r i v a t e members y = new i n t ( ( v. y ) ) ; // i n s i d e the c l a s s o n l y } // ( even from a n o t h e r o b j e c t ) An argument to a copy constructor has to be passed by reference (passing by value would require an already defined copy constructor). However, it is passed with a modifier const (const vector &v) to protect it against modifications. 32/51

34 Copy constructor example A default (shallow) copy constructor with a class using dynamic memory copies blindly (shallowly) pointer by pointer instead of allocating additional memory. vector a (1,2); vector b = a; a x y x y... b At the end of the scope the object b is destroyed first and the dynamic memory is deallocated. When the object a is then destroyed, it tries to deallocate the memory already deallocated! a x y...?????? 33/51

35 Copy constructor example A class using dynamic memory should always have a deep, user-defined copy constructor to intelligently copy the data and allocate additional memory if necessary. 1 1 vector a (1,2); vector b = a; a x y... 2 b x y... 2 At the end of the scope each objects frees its own allocated memory. 34/51

36 Copy constructor Copy constructor (either user-defined or default) is called in three situations: when an object is 1 created from another object of the same type v e c t o r a ( 1, 1 ), b = a, c ( a ) ; 2 passed by value as an argument to a function void dosomething ( v e c t o r v ) {... } ; 3 returned by value from a function v e c t o r f (... ) { v e c t o r a ( 1, 1 ) ; //... r e t u r n a ; } 35/51

37 Outline 1 Object-oriented programming (OOP) 2 Objects and classes 3 Creating and destroying objects 4 Overloaded operators As a class member or global function Result by value and by reference Two special operators 5 STL vector class 6 Homework 6 36/51

38 Overloaded operators In mathematics, two vectors or matrices can be simply added, just as two numbers. The same functionality, for example v e c t o r a ( 1, 1 ), b ( 2, 2 ), c = a+b ; i n t s c a l a r P r o d u c t = a b ; is possible in C++ by means of overloaded operators, which are defined either as class member functions or as global functions. Most of operators can be overloaded, e.g. + / = == < > = += && << ++ &! [] () 37/51

39 Overloaded operator as a class member function c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b =0); i n t operator ( const v e c t o r &v ) const ; //... } ; i n t v e c t o r : : operator ( const v e c t o r &v ) const { return x v. x+y v. y ; } Note the direct access to the private data members. 38/51

40 Overloaded operator as a global function However, it is not always possible to add an operator as a class member function, e.g. to ostream (object cout) to instruct it about printing objects of the type vector. In such cases, an operator has to be defined as a global function and looses the direct access to private data members. c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b =0); i n t getx ( void ) const { r e t u r n x ; } i n t gety ( void ) const { r e t u r n y ; } } ; i n t operator ( const v e c t o r &v1, const v e c t o r &v2 ) { r e t u r n v1. getx ( ) v2. getx ( ) + v1. gety ( ) v2. gety ( ) ; } 39/51

41 Result by value and by reference As other functions, overloaded operators can return objects by value or by reference. Assume a and b are vectors, while c is an integer: v e c t o r a ( 1, 1 ), b ( 5, 1 5 ) ; i n t k=10; Operator + (as in a+b) should return a new object of the type vector (by value) and leave the objects a and b unaltered. Operator = (as in a =k) should return the modified object a (by reference). 40/51

42 Result by value and by reference c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b=0) {x=a ; y=b } ; v e c t o r operator+(const v e c t o r &v ) const ; v e c t o r & operator+=(const v e c t o r &v ) ; } ; v e c t o r v e c t o r : : operator+(const v e c t o r &v ) const { r e t u r n v e c t o r ( x+v. x, y+v. y ) ; } // a new o b j e c t i s c r e a t e d, c o p i e d & r e t u r n e d v e c t o r & v e c t o r : : operator+=(const v e c t o r &v ) { x += v. x ; y += v. y ; r e t u r n t h i s ; } // the c u r r e n t o b j e c t ( t h i s ) i s m o d i f i e d & r e t u r n e d 41/51

43 ostream (cout) insertion operator<< c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( i n t a=0, i n t b=0) {x=a ; y=b } ; i n t getx ( void ) const { r e t u r n x ; } i n t gety ( void ) const { r e t u r n y ; } } ; ostream & operator << ( ostream &o s t r, const v e c t o r &v ) { o s t r << x = <<v. getx ( ) << y = <<v. gety ( ) <<e n d l ; r e t u r n o s t r ; } i n t main ( ) { v e c t o r a ( 1, 1 ), b ( 2, 2 ) ; cout <<a <<e n d l <<b ; r e t u r n 0 ; } 42/51

44 ostream (cout) insertion operator<< ostream & operator << ( ostream &o s t r, const v e c t o r &v ) { o s t r << x = <<v. getx ( ) << y = <<v. gety ( ) <<e n d l ; r e t u r n o s t r ; } Defined as a global function (since as a member function it should be added to the class ostream, which cannot be modified). Returns the same ostream by reference in order to enable chaining: cout <<a <<endl <<b; Both arguments are passed by reference. Only the second argument (vector) is const. 43/51

45 Assignment operator= An assignment operator = is very similar to the copy constructor. A user-defined version is necessary when the class uses dynamic memory, otherwise a default (shallow) operator= is created automatically. c l a s s v e c t o r { p r i v a t e : i n t x, y ; p u b l i c : v e c t o r ( const v e c t o r &v ) ; v e c t o r ( i n t a, i n t b ) ; v e c t o r &operator=(const v e c t o r &v ) ; } ; v e c t o r & v e c t o r : : operator=(const v e c t o r &v ) { x = v. x ; y = v. y ; r e t u r n t h i s ; } 44/51

46 Assignment operator= with the default shallow operator= vector a (1,2); vector b (3,4); b = a; a x y x y... b 3 4 with a deep user-defined operator= 1 1 vector a (1,2); vector b (3,4); b = a; a x y... 2 b x y /51

47 Outline 1 Object-oriented programming (OOP) 2 Objects and classes 3 Creating and destroying objects 4 Overloaded operators 5 STL vector class 6 Homework 6 46/51

48 STL vector class Standard (pointer-based) arrays are possible in C++ and very quick, but they have disadvantages: troublesome allocation and destruction, especially when multidimensional, troublesome resizing. Standard Templates Library (STL), now a part of the C++ Standard Library, is an object library providing generic containers (arrays, lists etc.) and algorithms for objects of any type, provided they have proper (default or user-defined) copy constructor, destructor, assignment (=) and comparison (==) operators. See or any tutorial on the web. 47/51

49 STL vector class 1D example #i n c l u d e <v e c t o r > 1D arrays v e c t o r <int > V ; // d e f i n i t i o n o f the v a r i a b l e V. r e s i z e (100, 0 ) ; // r e s i z e and i n i t i a l i z e V [ 1 0 ] = 1 0 ; V. push_back ( 3 ) ; // add 3 at the end cout <<V. s i z e ( ) ; // now 101 e l e m e n t s STL vectors are automatically destroyed in a proper way at the end of their scopes. 48/51

50 STL vector class 2D example #i n c l u d e <v e c t o r > 2D arrays v e c t o r <v e c t o r <int > > V2d ; // note the space! V2d. r e s i z e ( ) ; // 100 rows f o r ( i n t i =0; i <V2d. s i z e ( ) ; ++i ) V2d [ i ]. r e s i z e ( ) ; // each row has 100 e l e m e n t s V2d [ 1 0 ] [ 1 0 ] = 10; STL vectors are automatically destroyed in a proper way at the end of their scopes. 49/51

51 Outline 1 Object-oriented programming (OOP) 2 Objects and classes 3 Creating and destroying objects 4 Overloaded operators 5 STL vector class 6 Homework 6 50/51

52 Homework 6 (20 points) Matrix class Available at ljank. the answer and the source code (all three files) to ljank@ippt.pan.pl. 51/51

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

CS304 Object Oriented Programming

CS304 Object Oriented Programming 1 CS304 Object Oriented Programming 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes?

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-2: Programming basics II Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428 March

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Abstract Data Types (ADT) and C++ Classes

Abstract Data Types (ADT) and C++ Classes Abstract Data Types (ADT) and C++ Classes 1-15-2013 Abstract Data Types (ADT) & UML C++ Class definition & implementation constructors, accessors & modifiers overloading operators friend functions HW#1

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

An Introduction to C++

An Introduction to C++ An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 14: Object Oriented Programming in C++ (fpokorny@kth.se) Overview Overview Lecture 14: Object Oriented Programming in C++ Wrap Up Introduction to Object Oriented Paradigm Classes More on Classes

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 14: Object Oriented Programming in C++ (ramviyas@kth.se) Overview Overview Lecture 14: Object Oriented Programming in C++ Classes (cont d) More on Classes and Members Group presentations Last time

More information

And Even More and More C++ Fundamentals of Computer Science

And Even More and More C++ Fundamentals of Computer Science And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members

More information

Intermediate Programming & Design (C++) Classes in C++

Intermediate Programming & Design (C++) Classes in C++ Classes in C++ A class is a data type similar to a C structure. It includes various local data (called data members) together with constructors, destructors and member functions. All of them are called

More information

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a. Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype

More information

Written by John Bell for CS 342, Spring 2018

Written by John Bell for CS 342, Spring 2018 Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Review: C++ Basic Concepts. Dr. Yingwu Zhu Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to

More information

CS 162, Lecture 25: Exam II Review. 30 May 2018

CS 162, Lecture 25: Exam II Review. 30 May 2018 CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield C++ Programming Classes Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Presentation Outline Differences between C and C++ Object

More information

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance? INHERITANCE - Part 1 OOP Major Capabilities Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors encapsulation

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

INHERITANCE - Part 1. CSC 330 OO Software Design 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1 INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 15: Inheritance and Polymorphism, STL (pronobis@kth.se) Overview Overview Lecture 15: Inheritance and Polymorphism, STL Wrap Up Additional Bits about Classes Overloading Inheritance Polymorphism

More information

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2016) ramana@cs.columbia.edu Lecture-2 Overview of C C++ Functions Structures Pointers Design, difference with C Concepts of Object oriented Programming Concept

More information

CS32 - Week 1. Umut Oztok. June 24, Umut Oztok CS32 - Week 1

CS32 - Week 1. Umut Oztok. June 24, Umut Oztok CS32 - Week 1 CS32 - Week 1 Umut Oztok June 24, 2016 Administration Email:umut@ucla.edu Office hours: R 09:30am-12:30pm (BH 4663) Constructor Special member function to initialize an instance of a class. Called whenever

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer May 13, 2013 OOPP / C++ Lecture 7... 1/27 Construction and Destruction Allocation and Deallocation Move Semantics Template Classes Example:

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods.

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods. Classes: Methods, Constructors, Destructors and Assignment For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar Classes: Member functions // classes

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

CS250 Final Review Questions

CS250 Final Review Questions CS250 Final Review Questions The following is a list of review questions that you can use to study for the final. I would first make sure that you review all previous exams and make sure you fully understand

More information

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

More information

Assignment of Structs

Assignment of Structs Deep Copy 1 Assignment of Structs 2 Slides 1. Table of Contents 2. Assignment of Structs 3. Dynamic Content 4. Shallow Copying 5. Assignment Operator 6. Deep Assignment Copy 7. Assignment Problems 8. Assignment

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

INHERITANCE - Part 1. CSC 330 OO Software Design 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1 INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer September 26, 2016 OOPP / C++ Lecture 4... 1/33 Global vs. Class Static Parameters Move Semantics OOPP / C++ Lecture 4... 2/33 Global Functions

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Introduction to Programming using C++

Introduction to Programming using C++ Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer October 10, 2016 OOPP / C++ Lecture 7... 1/15 Construction and Destruction Kinds of Constructors Move Semantics OOPP / C++ Lecture 7... 2/15

More information

Increases Program Structure which results in greater reliability. Polymorphism

Increases Program Structure which results in greater reliability. Polymorphism UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

More Tutorial on C++:

More Tutorial on C++: More Tutorial on C++: OBJECT POINTERS Accessing members of an object by using the dot operator. class D { int j; void set_j(int n); int mul(); ; D ob; ob.set_j(4); cout

More information

CS105 C++ Lecture 7. More on Classes, Inheritance

CS105 C++ Lecture 7. More on Classes, Inheritance CS105 C++ Lecture 7 More on Classes, Inheritance " Operator Overloading Global vs Member Functions Difference: member functions already have this as an argument implicitly, global has to take another parameter.

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

POLYMORPHISM. Phone : (02668) , URL :

POLYMORPHISM. Phone : (02668) , URL : POLYMORPHISM POLYMORPHISM Polymorphism is the property of the same object to behave differently in different context given the same message Compile Time and Runtime Polymorphism Compile time - Function

More information

pointers & references

pointers & references pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using

More information

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

C++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science Written examination Homologation C++ and Computer Organization (2DMW00) Part I: C++ - on Tuesday, November 1st 2016, 9:00h-12:00h.

More information

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE1303. B.Tech. Year - II

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE1303. B.Tech. Year - II Subject Code: 01CE1303 Subject Name: Object Oriented Design and Programming B.Tech. Year - II Objective: The objectives of the course are to have students identify and practice the object-oriented programming

More information

eingebetteter Systeme

eingebetteter Systeme Praktikum: Entwicklung interaktiver eingebetteter Systeme C++-Tutorial (falk@cs.fau.de) 1 Agenda Classes Pointers and References Functions and Methods Function and Operator Overloading Template Classes

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Programming Languages: OO Paradigm, Polymorhism and Class Members

Programming Languages: OO Paradigm, Polymorhism and Class Members Programming Languages: OO Paradigm, Polymorhism and Class Members Onur Tolga Şehitoğlu Computer Engineering,METU 1 May 2009 Outline 1 2 Abstract Classes Inheritance inclusion polymorphism Binding is still

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Next week s homework. Classes: Member functions. Member functions: Methods. Objects : Reminder. Objects : Reminder 3/6/2017

Next week s homework. Classes: Member functions. Member functions: Methods. Objects : Reminder. Objects : Reminder 3/6/2017 Next week s homework Classes: Methods, Constructors, Destructors and Assignment Read Chapter 7 Your next quiz will be on Chapter 7 of the textbook For : COP 3330. Object oriented Programming (Using C++)

More information

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates Lecture-4 Inheritance review. Polymorphism Virtual functions Abstract classes Passing arguments to functions by Value, pointers, refrence const member functions const arguments to a function Function overloading

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP THROUGH C++(R16) int *x; float *f; char *c; What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,

More information

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI 621213 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Sub code: CS2203 SEM: III Sub Name: Object Oriented Programming Year: II UNIT-I PART-A 1. What is

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1 CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects

More information

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo Chapter 10 Pointers and Dynamic Arrays 1 Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic Classes, Pointers, Dynamic Arrays The this

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

OBJECT ORIENTED PROGRAMMING USING C++

OBJECT ORIENTED PROGRAMMING USING C++ OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

CS24 Week 3 Lecture 1

CS24 Week 3 Lecture 1 CS24 Week 3 Lecture 1 Kyle Dewey Overview Some minor C++ points ADT Review Object-oriented Programming C++ Classes Constructors Destructors More minor Points (if time) Key Minor Points const Motivation

More information

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example CS 311 Data Structures and Algorithms Lecture Slides Friday, September 11, 2009 continued Glenn G. Chappell

More information

Programming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor

Programming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor Programming C++ Lecture 3 Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Inheritance S Software reuse inherit a class s data and behaviors and enhance with new capabilities.

More information