Object-oriented Programming in C++

Size: px
Start display at page:

Download "Object-oriented Programming in C++"

Transcription

1 Object-oriented Programming in C++ Object Orientation in C++ Wolfgang Eckhardt, Tobias Neckel July 1, 2014 Object Orientation in C++, July 1,

2 1 The Concept of Object Orientation Object Orientation in C++, July 1,

3 1.1 Definition of Objects What Is an Object? a car a cat a chair... a molecule a star a galaxy... anything that represents a real thing anything that represents an abstract thing anything which has some properties Object Orientation in C++, July 1,

4 How to Program Object-orientedly Change your way of thinking Change your point of view It is not just a technical question! Good designs requires considerable experience! Object Orientation in C++, July 1,

5 Classes A class is similiar to the definition of a type Specifies properties of the objects to be created 1.2 Classes vs. Objects Data to be stored once for all objects (class/static variable) Data to be stored in each object (member variables) Operations to be done with objects (member functions/methods) Represents a class of things/objects Instances / Objects An instance/object is a concrete thing of the type of a class A class specifies properties, an object has specific values for the specified properties state of an object For each class, there can be an arbitrary number of objects Each object belongs to exactly one class (exception: polymorphism, day 3) Object Orientation in C++, July 1,

6 Object: Definition Definition Oracle, The Java Tutorials State: the set of values of member variables/fields (built-in datatypes and other objects) at a specific point in time Behaviour: Member functions/methods operate on the internal state of the object, primary mechanism for object-to-object communication Object Orientation in C++, July 1,

7 Object: Example Oracle, The Java Tutorials Example: Bike State: Speed, Revolutions per Minute, Gear,.. Behaviour: Change gears, change cadence, brake,.. Object Orientation in C++, July 1,

8 Pros 1.3 Why Object Orientation? Modularity: Implementation of different objects usually written independently. Information hiding: Internal implementation remains hidden from the outside world (can be changed easily even for heavy used objects) Code reuse: Object (re-)use: you only have to understand the member-functions visible to you (interfaces in software projects and/or libraries) Inheritance (details below) Cons Performance: Wrong usage of OO-language constructs might come with a significant overhead. Code complexity: Be careful: unclever OO design problems in maintenance, extensibility, etc.) Object Orientation in C++, July 1,

9 2 Objects in C ++ Bikes as Objects Task: Model a bike in C ++ Goal: Learn the C ++ syntax on the way Design Gear Shift Bike State: current gear, #gears Behaviour: increase gear, decrease gear, get current gear State: current speed, revolutions per minute, gear shift Behaviour: change gear, brake, change cadence Object Orientation in C++, July 1,

10 2.1 Overview: Bikes as Objects Design Gear Shift Overview Bike State: current gear, #gears Behaviour: increase gear, decrease gear, get current gear State: current speed, revolutions per minute, gear shift Behaviour: change gear, brake, change cadence Next Skeleton (header file) of the bike class with member variables, member functions and access control. Object Orientation in C++, July 1,

11 Bike.h - The class Keyword 17 # ifndef BIKE_H_ 18 # define BIKE_H_ # include <cmath > 21 # include <iostream > # include " GearShift.h" class Bike { 72 }; # endif // BIKE_H_ Keyword code: class defines a class in C ++ frame for OO concepts (member variables, member functions, inheritance,... ) Object Orientation in C++, July 1,

12 Bike.h - State: Member Variables 25 class Bike { 26 // private : 27 //! current speed 28 float m_speed ; //! current rpm 31 float m_revolutions ; //! gear shift 34 GearShift m_gearshift ; 72 }; State code: Member variables define the state of an object. Member variable can be built-in or custom objects. Object Orientation in C++, July 1,

13 Relationships between Objects: Part-Of Part-Of releationship Object A is with object B in an part-of releationship, if A is part of B (A is one of the parts the machinery of B is assembled of). Example: Object gear shift can be modeled in a part-of relation to the object bike. Object Orientation in C++, July 1,

14 Object Member Variables model Part-Of Object Member Variables OO-programming: allows objects to be build of other objects not only built-in data-types allows for a modular implementation and code reuse Object Orientation in C++, July 1,

15 Bike.h - Behaviour: Member Functions 25 class Bike { 36 public : 37 /** 38 * Constructor 39 * 40 i_numberofgears # gears 41 **/ 42 Bike ( int i_numberofgears ); /** 45 * Destructor 46 **/ 47 ~ Bike (); /** 50 * Changes the gear to the closest possible gear. 51 * 52 i_gear gear to change to. 53 **/ 54 void changegear ( int i_gear ); 72 }; code: Object Orientation in C++, July 1,

16 Bike.h - Behaviour: Member Functions (2) 25 class Bike { 36 public : 56 /** 57 * Brakes the bike. 58 **/ 59 void brake (); /** 62 * Accelerates the bike. 63 * 64 i_rpm revolutions per minute. 65 **/ 66 void changecadence ( float i_rpm ); 72 }; Behaviour code: Member functions: mutator methods: change internal state of an object (often setxxx()) Object Orientation in C++, July 1,

17 Bike.h - Behaviour: Member Functions (3) 25 class Bike { 36 public : /** 69 * Prints status of our bike. 70 **/ 71 void printinformation () const ; 72 }; Behaviour code: Member functions: accessor methods give access (read-only) to the state of an object (often getxxx()) Object Orientation in C++, July 1,

18 Bike.h - Access Control 25 class Bike { 26 // private : 27 //! current speed 28 float m_speed ; 36 public : 37 /** 38 * Constructor 39 * 40 i_numberofgears # gears 41 **/ 42 Bike ( int i_numberofgears ); Accessibility Restrictive access control: helps to write clean code & uses compiler to enforce interfaces. private: Members public: Anyone Object Orientation in C++, July 1,

19 Information Hiding Users/developers have restricted access to objects/classes avoid side effects! (you don t want a user to change the gravity constant of the earth, etc.) reduce code complexity in usage (you only need to care about what you can see) reduce code complexity in development (accessor methods, e.g.: rename a member variable) Object Orientation in C++, July 1,

20 2.2 Overview: Bikes as Objects Design Gear Shift Overview Bike State: current gear, #gears Behaviour: increase gear, decrease gear, get current gear State: current speed, revolutions per minute, gear shift Behaviour: change gear, brake, change cadence Previous Skeleton (header file) of the Bike class with member variables, member functions and access control. Next Implementation (source file) of the Bike class & runner. Object Orientation in C++, July 1,

21 Bike.cpp - Constructor 17 # include " Bike.h" Bike :: Bike ( int i_numberofgears ): 20 m_speed (0), 21 m_revolutions (0), 22 m_gearshift ( i_numberofgears ) { 23 std :: cout << " bike with " << i_numberofgears 24 << " gears constructed " << std :: endl ; 25 }; Properties code: Called whenever an object is created More than one constructor (with different syntax) possible; no return type If none is specified, the compiler generates one (default constructor) Object Orientation in C++, July 1,

22 Bike.cpp - Member Initialisation List 19 Bike :: Bike ( int i_numberofgears ): 20 m_speed (0), 21 m_revolutions (0), 22 m_gearshift ( i_numberofgears ) { Properties code: Per default the default constructor is called for all members Some member types have to be initialised in the member initialisation list: references non-static const member class members w\o default constructors base class members (Performance gains possible: construction vs. assignment) Object Orientation in C++, July 1,

23 Bike.cpp - Destructor 27 Bike ::~ Bike () { 28 std :: cout << " bike destroyed :(" << std :: endl ; 29 } Properties code: Called whenever an object is destroyed Clean up of the object (could free dyn. allocated memory, e.g.) No arguments or return type If no destructor is specified, the compiler generates a default one Object Orientation in C++, July 1,

24 Bike.cpp - Member Functions 31 void Bike :: changegear ( int i_gear ) { 32 if( i_gear < m_gearshift. getcurrentgear () ) { 33 // decrease gears until best possible gear is reached 34 while ( m_gearshift. decreasegear () ) { 35 if( i_gear == m_gearshift. getcurrentgear () ) break ; 36 } 37 } 38 else if( i_gear > m_gearshift. getcurrentgear () ) { 39 // increase gearse until best possible gear is reached 40 while ( m_gearshift. increasegear () ) { 41 if( i_gear == m_gearshift. getcurrentgear () ) break ; 42 } 43 } 44 } void Bike :: brake () { 47 m_speed = std :: max ( 0.f, m_speed - 5. f ); 48 m_revolutions = m_speed * 25. f; 49 } void Bike :: changecadence ( float i_rpm ) { 52 m_revolutions = std :: max ( 0.f, i_rpm ); 53 m_speed = m_revolutions * m_gearshift. getcurrentgear () / 25. f; 54 } Object Orientation in C++, July 1,

25 Bike.cpp - Member Functions (2) 56 void Bike :: printinformation () const { 57 std :: cout << " speed : " << m_speed << std :: endl 58 << " rpms : " << m_revolutions << std :: endl 59 << " gear : " << m_gearshift. getcurrentgear () 60 << std :: endl ; 61 } Properties accessor member functions: const forbids modification of member variables (details later and in the tutorials) Object Orientation in C++, July 1,

26 2.3 Runner: Instantiating Objects 17 # include " Bike.h" int main () { 20 // construct two bikes 21 Bike l_mybike ( 20 ); 22 Bike * l_myfriendsbike = new Bike ( 15 ); 39 delete l_myfriendsbike ; 40 } code: 2 Variants: Direct instantiation via constructor call Dynamic memory allocation in C ++: via new-keyword (more typesafe and calls constructors) Hint: Always delete what you new, and free what you malloc. Don t mix new with free or malloc with delete! Object Orientation in C++, July 1,

27 17 # include " Bike.h" int main () { 20 // construct two bikes 21 Bike l_mybike ( 20 ); 22 Bike * l_myfriendsbike = new Bike ( 15 ); // print their initial status 25 l_mybike. printinformation (); 26 l_myfriendsbike -> printinformation (); // go on a bike tour with a friend 29 l_mybike. changegear ( 16 ); 30 l_mybike. changecadence ( 16.5 ); 31 l_myfriendsbike -> changegear ( 9 ); 32 l_myfriendsbike -> changecadence ( 29.8 ); // print information 35 l_mybike. printinformation (); 36 l_myfriendsbike -> printinformation (); // free dynamic memory 39 delete l_myfriendsbike ; 40 } Runner: Using bikes Object Orientation in C++, July 1,

28 2.4 Special Members up to now: member variables member functions How about variables that exist only once per class (not per object)? How about functions that do not modify objects? Object Orientation in C++, July 1,

29 19 class SimpleClass { 20 // private : 21 static int s_simplecounter ; 22 Static Members 23 public : 24 SimpleClass () { 25 s_simplecounter ++; 26 std :: cout << " ctr in constr =" << s_simplecounter << std :: endl ; 27 }; ~ SimpleClass () { 30 s_simplecounter - -; 31 std :: cout << " ctr in destr=" << s_simplecounter << std :: endl ; 32 }; 33 }; int SimpleClass :: s_simplecounter = 0; int main () { 38 SimpleClass l_simple1 ; 39 { 40 SimpleClass l_simple2 ; 41 } 42 SimpleClass l_simple3 ; 43 } Object Orientation in C++, July 1,

30 Static Members (2) 19 class SimpleClass { 20 // private : 21 static int s_simplecounter ; public : 24 SimpleClass () { 25 s_simplecounter ++; 26 std :: cout << " ctr in constr =" << s_simplecounter << std :: endl ; 27 }; ~ SimpleClass () { 30 s_simplecounter - -; 31 std :: cout << " ctr in destr=" << s_simplecounter << std :: endl ; 32 }; 33 }; int SimpleClass :: s_simplecounter = 0; code: Description A class can have static member variables, which are single locations in memory shared by all instances of the class. Object Orientation in C++, July 1,

31 19 class SimpleClass { 20 // private : 21 static int s_simplecounter ; 22 Static Member Functions 23 public : 24 static void increasecounter (){ s_simplecounter ++; }; 25 static void printcounter (){ std :: cout << s_simplecounter << std :: endl ; }; 26 }; int SimpleClass :: s_simplecounter = 1; int main () { 31 SimpleClass :: printcounter (); 32 SimpleClass :: increasecounter (); 33 SimpleClass :: printcounter (); 34 } code: Description Static member functions: accessible independently of a single instance of a class non-static members or this-pointer can t be accessed Object Orientation in C++, July 1,

32 Const Members 17 class SimpleClass { 18 // private : 19 const int m_a ; public : 22 SimpleClass ( int i_a ): m_a ( i_a ) { 23 // forbidden assignment 24 // m_a = 10; 25 }; 26 }; int main () { 29 SimpleClass l_simple ( 15 ); 30 } code: Description A class can have const member variables: can t be changed after initialization have to be set in the member initialisation list. Object Orientation in C++, July 1,

33 Const Member Functions 17 class SimpleClass { 18 // private : 19 int m_a ; public : 22 void simplefunctions () const { 23 // forbidden assignment 24 // m_a = 5; 25 } 26 }; int main () { 29 SimpleClass l_simple ; 30 l_simple. simplefunctions (); 31 } code: Description A class can have const member functions, which are not allowed to change the member variables/state of an object. Hint: The position of the const qualifier is crucial ( tutorials). Object Orientation in C++, July 1,

34 3 Inheritance Object Orientation in C++, July 1,

35 Inheritance in Real Life object Object Orientation in C++, July 1,

36 Inheritance in Real Life sunbed table chair furniture oak cypress beech daisy tulip rose Audi car VW BMW machine object comp. plant animal tree mammal reptile flower horse donkey cat Golf Polo Phaeton laptop desktop vectorc. cluster croc. snake mule Object Orientation in C++, July 1,

37 Relationships between Objects: Is-A Oracle, The Java Tutorials Is-A releationship Object A is with object B in an is-a releationship, if A behaves like B, but adds additional features (B is a blueprint for A); Example: Objects mountain bike and road bike are modeled to be in a is-a relation to the object bicycle Object Orientation in C++, July 1,

38 Is-A models Inheritance Oracle, The Java Tutorials Inheritance OO-programming allows to inherit states and behaviour from other objects; allows for abstraction/specialization in the implementation Object Orientation in C++, July 1,

39 Understanding Is-A : Rectangles Sketch Rectangles Rectangle: increasesize() Square is-a Rectangle Rectangle.increaseSize(), Square.increaseSize()? Object Orientation in C++, July 1,

40 Inheritance in OO Code Classes can inherit from a base class they are derived classes / subclasses of the base clase All classes can be specialised All classes together form a taxonomy/hierarchy of classes Methodes of the base class can be kept and used, or can be defined newly (overwriting, details see day 3) Object Orientation in C++, July 1,

41 3.2 Inheritance: Interface and Implementation Sketch Shape Shape( int i_color = 0 ); virtual ~Shape(); int getcolor() const; virtual double getsurfacearea() const; Star Rectangle Star(..); virtual ~Star(); virtual double getsurfacearea() const; Circle Rectangle( double i_width, double i_height, int i_color = 0 ); virtual ~Rectangle(); virtual double getsurfacearea() const; Circle( double i_radius ); virtual ~Circle(); virtual double getsurfacearea() const; Object Orientation in C++, July 1,

42 Star(..); virtual ~Star(); virtual double getsurfacearea() const; Shape( int i_color = 0 ); virtual ~Shape(); int getcolor() const; virtual double getsurfacearea() const; Circle( double i_radius ); virtual ~Circle(); virtual double getsurfacearea() const; Rectangle( double i_width, double i_height, int i_color = 0 ); virtual ~Rectangle(); virtual double getsurfacearea() const; Sketch Inheritance: Interface and Implementation (2) Shape Star Rectangle Circle Description Inheritance splits into: Function interfaces and function implementations Allows for three different type implementations: Implementation provided by base class Default-implementation provided base class (can be overwritten) Interface provided by base class (needs to be implemented) Object Orientation in C++, July 1,

43 3.3 Inheritance in C ++: Basic Syntax 19 class Shape { 20 // private : 21 public : 22 Shape () { 23 std :: cout << " constructed a new shape " << std :: endl ; 24 } virtual ~ Shape () {}; 27 }; class Star : public Shape {}; 30 class Circle : public Shape {}; 31 class Rectangle : public Shape {}; Concept code: Shape is the base class for the derived classes Star, Circle and Rectangle Object Orientation in C++, July 1,

44 Shape.cpp - A Bit More Complex 23 class Shape { 24 // private : 25 int m_color ; public : 28 Shape ( int i_color =0 ): 29 m_color ( i_color ) {}; 30 virtual ~ Shape () {}; int getcolor () const { return m_color ; }; 39 }; code: code: Object Orientation in C++, July 1,

45 Inheritance - Implementing a Child Class 41 class Circle : public Shape { 42 // private : 43 double m_radius ; public : 46 Circle ( double i_radius ): 47 Shape (), m_radius ( i_radius ) { 48 std :: cout << " constructed a circle, radius : " 49 << m_radius << std :: endl ; 50 }; 51 virtual ~ Circle () {}; 57 }; code: code: Accessibility Circle inherits from Shape note class definition Note: call of base class constructor in initialisation list Object Orientation in C++, July 1,

46 41 class Circle : public Shape { 42 // private : 43 double m_radius ; public : 46 Circle ( double i_radius ): 47 Shape (), m_radius ( i_radius ) { 48 std :: cout << " constructed a circle, radius : " 49 << m_radius << std :: endl ; 50 }; 51 virtual ~ Circle () {}; 57 }; Inheritance - Access Control code: code: Accessibility Restrictive access control helps to write clean code and uses the compiler to enforce your interfaces. private: Members protected: Members of the class & of derived classes public: Anyone Object Orientation in C++, July 1,

47 4 Backup some stuff that may be interesting but is not covered in the lecture Object Orientation in C++, July 1,

48 4.1 Switching Off the Lifecycle Management 1 double * p ; 2 3 p = new double ; / / now, p p o i n t s to an e x i s t i n g new v a r i a b l e 4 5 * p = 20; 6 7 d e l e t e p ; / / now v a r i a b l e i s freed, but p s t i l l p o i n t s 8 / / to t h i s v a r i a b l e * p = 30; The value 20 in the memory is an anonymous variable as it doesn t have a name we can reach it only through a pointer. Object Orientation in C++, July 1,

49 Two Memory Leaks 1 double * p ; 2 3 f o r ( i n t i =0; i <20; i ++) { 4 p = new double ; 5 } 6 7 d e l e t e p ; 1 f o r ( i n t i =0; i <20; i ++) { 2 double * p = new double ; 3 } The upper operation creates 20 doubles on the heap, but it destroys only one double in the end. Consequently, the remaining 19 doubles are lost for the future program execution. Let s sketch the memory layout! The second one destroys the pointer but not the space where the pointer is pointing to. This is why many applications crash after Wolfgangseveral Eckhardt, Tobias hours Neckel: of Object-oriented execution. Programming in C++ Object Orientation in C++, July 1,

50 Understanding is-a : Birds Birds Bird: fly() Penguin is-a bird Bird.fly(), Penguin.fly()? What happenend? Problem of our intuotion/language, birds fly means in general birds have the ability to fly Correct model, if our project contains no non-flying bird and will not contain non-flying birds in future Birds (2) Bird FlyingBird is-a Bird: fly() NonFlyingBird is-a Bird Penguin is-as a NonFlyingBird FlyingBird.fly() NonFlyingBird.fly(), Peguin.fly() Object Orientation in C++, July 1,

51 4.2 Modellierung mit UML Flussdiagramme Nur geeignet für kleine Algorithmen Keine Darstellung von Klassenhierarchien Keine Darstellung von Datenabhängigkeiten... UML: Unified Modeling Language visuelle Modellierungssprache Sprache unterstützt unterschiedliche Diagrammtypen Software wird über diese Diagramme/Modelle spezifiziert Kann als Basis für die Dokumentation dienen Automatische Code-Generierung möglich Auch für sonstige betriebliche Abläufe geeignet Object Orientation in C++, July 1,

52 Strukturdiagramme Klassendiagramm Objektdiagramm Kompositionsstrukturdiagramm Komponentendiagramm Verteilungsdiagramm Paketdiagramm Profildiagramm Verhaltensdiagramme Aktivitätsdiagramm Anwendungsfalldiagramm (Use-Cases) Interaktionsübersichtsdiagramm Kommunikationsdiagramm Sequenzdiagramm Zeitverlaufsdiagramm Zustandsdiagramm Object Orientation in C++, July 1,

53 Klassendiagramm Einzelne Klasse Klasse dargestellt durch Rechteck Horizontale Unterteilung in drei Bereiche Oberster Bereich: Klassenname Mittlerer Bereich: Attribute/Variablen Unterer Bereich: Methoden Klassenname + public_vars private_vars + public_methods private_methods Object Orientation in C++, July 1,

54 Syntax der Klassenbeschreibung Name von Klasse/Variablen/Methoden frei wählbar +: public Variable/Methode (optional) -: private Variable/Methode (optional) Für Variablen kann der Typ angegeben werden (nach :) Für Methoden kann der Rückgabewert angegeben werden (nach :) Object Orientation in C++, July 1,

55 Vererbung Darstellung durch Pfeil mit geschlossener Spitze ist ein - Beziehung Pfeil von spezialisierter Klasse zur Vaterklasse Fahrzeug Auto Motorrad Object Orientation in C++, July 1,

56 Assoziation Semantischer Zusammenhang zwischen Klassen Beschreibung der Assoziation neben dem Pfeil Vorlesung liest hört Dozent Student Object Orientation in C++, July 1,

57 Aggregation und Komposition Aggregation (leere Raute): hat ein Komposition (volle Raute): enthält ein Angabe der Anzahl möglich Fahrzeug 1 5 Besitzer Türen Object Orientation in C++, July 1,

Challenges of This Course. Object-oriented Programming in C++ Outline of Day 1. What Will be Covered in This Course. Outline of Day 2 & 3

Challenges of This Course. Object-oriented Programming in C++ Outline of Day 1. What Will be Covered in This Course. Outline of Day 2 & 3 Challenges of This Course Object-oriented Programming in C++ Working with C and C++ Wolfgang Eckhardt, Tobias Neckel June 30, 2014 Heterogeneity of the audience (different level of programming experience,

More information

Part V. Object-oriented Programming. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Part V. Object-oriented Programming. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26, Part V Object-oriented Programming Compact Course @ Max-Planck, February 16-26, 2015 65 What Is an Object? Compact Course @ Max-Planck, February 16-26, 2015 66 What Is an Object? a car a cat a chair...

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

10. Object-oriented Programming. 7. Juli 2011

10. Object-oriented Programming. 7. Juli 2011 7. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Object Case Study Brain Teaser Copy Constructor & Operators Object-oriented Programming, i.e.

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017

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

8. Object-oriented Programming. June 15, 2010

8. Object-oriented Programming. June 15, 2010 June 15, 2010 Introduction to C/C++, Tobias Weinzierl page 1 of 41 Outline Recapitulation Copy Constructor & Operators Object-oriented Programming Dynamic and Static Polymorphism The Keyword Static The

More information

Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay

Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay Classes - 2 Data Processing Course, I. Hrivnacova, IPN Orsay OOP, Classes Reminder Requirements for a Class Class Development Constructor Access Control Modifiers Getters, Setters Keyword this const Member

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005 Lecture 8 Classes and Objects Part 2 MIT AITI June 15th, 2005 1 What is an object? A building (Strathmore university) A desk A laptop A car Data packets through the internet 2 What is an object? Objects

More information

1.00 Lecture 14. Exercise: Plants

1.00 Lecture 14. Exercise: Plants 1.00 Lecture 14 Inheritance, part 2 Reading for next time: Big Java: sections 9.1-9.4 Exercise: Plants Create a base class Plant Plant: Private data genus, species, isannual Write the constructor Create

More information

#include <iostream> #include <cstdlib>

#include <iostream> #include <cstdlib> Classes and Objects Classes The structure data type can be used in both C and C++ Usually a structure is used to store just data, however it can also be used to store functions that can work on the data.

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

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

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 you review all previous exams and make sure you fully understand

More information

Object-oriented Programming in C++

Object-oriented Programming in C++ Object-oriented Programming in C++ Working with C and C++ Wolfgang Eckhardt, Tobias Neckel March 23, 2015 Working with C and C++, March 23, 2015 1 Challenges of This Course Heterogeneity of the audience

More information

Introduction to Classes

Introduction to Classes Introduction to Classes Procedural and Object-Oriented Programming Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented

More information

G52CPP C++ Programming Lecture 9

G52CPP C++ Programming Lecture 9 G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And

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

C++ Programming Lecture 8 Software Engineering Group

C++ Programming Lecture 8 Software Engineering Group C++ Programming Lecture 8 Software Engineering Group Philipp D. Schubert VKrit This time for real (hopefully) Date: 15.12.2017 Time: 15:45 h Your opinion is important! Please use the free text comments

More information

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck C++ Crash Kurs Polymorphism Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ Polymorphism Major abstractions of C++ Data abstraction

More information

EMBEDDED SYSTEMS PROGRAMMING OO Basics

EMBEDDED SYSTEMS PROGRAMMING OO Basics EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:

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

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

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming Chapter 13: Introduction to Classes 1 13.1 Procedural and Object-Oriented Programming 2 Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a

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

Computer Programming Inheritance 10 th Lecture

Computer Programming Inheritance 10 th Lecture Computer Programming Inheritance 10 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 Eom, Hyeonsang All Rights Reserved 순서 Inheritance

More information

ECE 3574: Dynamic Polymorphism using Inheritance

ECE 3574: Dynamic Polymorphism using Inheritance 1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:

More information

Principles of Object Oriented Programming. Lecture 4

Principles of Object Oriented Programming. Lecture 4 Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance

More information

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

Comp151. Inheritance: Initialization & Substitution Principle

Comp151. Inheritance: Initialization & Substitution Principle Comp151 Inheritance: Initialization & Substitution Principle Initializing Base Class Objects If class C is derived from class B which is in turn derived from class A, then C will contain data members of

More information

CLASSES AND OBJECTS IN JAVA

CLASSES AND OBJECTS IN JAVA Lesson 8 CLASSES AND OBJECTS IN JAVA (1) Which of the following defines attributes and methods? (a) Class (b) Object (c) Function (d) Variable (2) Which of the following keyword is used to declare Class

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. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.

More information

CSCI 123 Introduction to Programming Concepts in C++

CSCI 123 Introduction to Programming Concepts in C++ CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe Brad Rippe More Classes and Dynamic Arrays Overview 11.4 Classes and Dynamic Arrays Constructors, Destructors, Copy Constructors Separation

More information

CS 11 C++ track: lecture 1

CS 11 C++ track: lecture 1 CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account http://www.cs.caltech.edu/cgi-bin/ sysadmin/account_request.cgi Need to know UNIX (Linux) www.its.caltech.edu/its/facilities/labsclusters/

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

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 you review all previous exams and make sure you fully understand

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

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

G52CPP C++ Programming Lecture 13

G52CPP C++ Programming Lecture 13 G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

G52CPP C++ Programming Lecture 7. Dr Jason Atkin G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A

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

6. Pointers, Structs, and Arrays. 1. Juli 2011

6. Pointers, Structs, and Arrays. 1. Juli 2011 1. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 50 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung

More information

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

6. Pointers, Structs, and Arrays. March 14 & 15, 2011 March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

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

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 10 October 1, 2018 CPSC 427, Lecture 10, October 1, 2018 1/20 Brackets Example (continued from lecture 8) Stack class Brackets class Main

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

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

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Object Oriented Programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 23, 2010 G. Lipari (Scuola Superiore

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

2.1 Introduction UML Preliminaries Class diagrams Modelling delegation... 4

2.1 Introduction UML Preliminaries Class diagrams Modelling delegation... 4 Department of Computer Science COS121 Lecture Notes Chapter 2- Memento design pattern Copyright c 2015 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 2.1 Introduction.................................

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

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Implementing an ADT with a Class

Implementing an ADT with a Class Implementing an ADT with a Class the header file contains the class definition the source code file normally contains the class s method definitions when using Visual C++ 2012, the source code and the

More information

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Classes & Objects DDU Design Constructors Member Functions & Data Friends and member functions Const modifier Destructors Object -- an encapsulation of data

More information

G52CPP C++ Programming Lecture 10. Dr Jason Atkin

G52CPP C++ Programming Lecture 10. Dr Jason Atkin G52CPP C++ Programming Lecture 10 Dr Jason Atkin 1 Last lecture Constructors Default constructor needs no parameters Default parameters Inline functions Like safe macros in some ways Function definitions

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

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

Object-oriented Programming in C++

Object-oriented Programming in C++ Object-oriented Programming in C++ Working with C and C++ Wolfgang Eckhardt, Tobias Neckel June 30, 2014 Working with C and C++, June 30, 2014 1 Challenges of This Course Heterogeneity of the audience

More information

CS11 Introduction to C++ Fall Lecture 7

CS11 Introduction to C++ Fall Lecture 7 CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,

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

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

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

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

PROGRAMMING IN C++ COURSE CONTENT

PROGRAMMING IN C++ COURSE CONTENT PROGRAMMING IN C++ 1 COURSE CONTENT UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 2 1.1 Procedure oriented Programming 1.2 Object oriented programming paradigm 1.3 Basic concepts of Object Oriented

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

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

OO Techniques & UML Class Diagrams

OO Techniques & UML Class Diagrams OO Techniques & UML Class Diagrams SE3A04 Tutorial Jason Jaskolka Department of Computing and Software Faculty of Engineering McMaster University Hamilton, Ontario, Canada jaskolj@mcmaster.ca October 17,

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1 C How to Program, 6/e 1 Structures : Aggregate data types are built using elements of other types struct Time { int hour; int minute; Members of the same structure must have unique names. Two different

More information

Creating an object Instance variables

Creating an object Instance variables Introduction to Objects: Semantics and Syntax Defining i an object Creating an object Instance variables Instance methods What is OOP? Object-oriented programming (constructing software using objects)

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

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

CS

CS CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and

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

a data type is Types

a data type is Types Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

Lecture 13: more class, C++ memory management

Lecture 13: more class, C++ memory management CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 13:

More information

Lecture 14: more class, C++ streams

Lecture 14: more class, C++ streams CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 14:

More information

A brief introduction to C++

A brief introduction to C++ A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne

More information

Introduction to Computation and Problem Solving

Introduction to Computation and Problem Solving Class 13: Inheritance and Interfaces Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward 2 More on Abstract Classes Classes can be very general at the top of

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Programming in C# Inheritance and Polymorphism

Programming in C# Inheritance and Polymorphism Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data

More information

Distributed Real-Time Control Systems. Lecture 14 Intro to C++ Part III

Distributed Real-Time Control Systems. Lecture 14 Intro to C++ Part III Distributed Real-Time Control Systems Lecture 14 Intro to C++ Part III 1 Class Hierarchies The human brain is very efficient in finding common properties to different entities and classify them according

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract

More information

Chapter 2: Java OOP I

Chapter 2: Java OOP I Chapter 2: Java OOP I Yang Wang wyang AT njnet.edu.cn Outline OO Concepts Class and Objects Package Field Method Construct and Initialization Access Control OO Concepts Object Oriented Methods Object An

More information

Object Oriented Programming: Inheritance Polymorphism

Object Oriented Programming: Inheritance Polymorphism Object Oriented Programming: Inheritance Polymorphism Shahram Rahatlou Computing Methods in Physics http://www.roma1.infn.it/people/rahatlou/cmp/ Anno Accademico 2018/19 Today s Lecture Introduction to

More information

Lecture 5: Inheritance

Lecture 5: Inheritance McGill University Computer Science Department COMP 322 : Introduction to C++ Winter 2009 Lecture 5: Inheritance Sami Zhioua March 11 th, 2009 1 Inheritance Inheritance is a form of software reusability

More information

COP 3530 Discussion Session #2 Ferhat Ay

COP 3530 Discussion Session #2 Ferhat Ay COP 3530 Discussion Session #2 Ferhat Ay COP3530-Ferhat Ay-Discussion Ses.#2 1/18/2011 1 Few things about me My name is difficult! Fer-hat, Fur-hot, Far-had, Frad, Fred, Frank, or just say F. I m a PhD

More information