Programming in C++ Ryan Kafuman 07/06/09. Programming in C++ ● Classes and Object Oriented Design ● Error Handling ● Function Overloading ● Operator Overloading.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Object-Oriented PHP (1)
Advanced Object-Oriented Programming Features
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
C++ fundamentals.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
OOP with PHP Roman Bednarik
C++ Review Classes and Object Oriented Programming Parasol Lab, Texas A&M University.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
1 Life Cycle of Software Specification Design –Risk Analysis –Verification Coding Testing –Refining –Production Maintenance.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Object Oriented Software Development
CS212: Object Oriented Analysis and Design Lecture 17: Virtual Functions.
Learners Support Publications Object Oriented Programming.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 15 Inheritance.
Introduction to Object-Oriented Programming Lesson 2.
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Procedural programming Procedural programming is where you specify the steps required. You do this by making the program in steps. Procedural programming.
Java Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
Object Oriented Programming Some Interesting Genes.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Andy Wang Object Oriented Programming in C++ COP 3330
OOP: Encapsulation &Abstraction
Classes (Part 1) Lecture 3
Java Yingcai Xiao.
Inheritance and Polymorphism
The Object-Oriented Thought Process Chapter 1
CS212: Object Oriented Analysis and Design
Review: Two Programming Paradigms
About the Presentations
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Generics, Lambdas, Reflections
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Concepts
Designing for Inheritance
OOP’S Concepts in C#.Net
Lecture 9 Concepts of Programming Languages
Object-Oriented Programming
Learning Objectives Classes Constructors Principles of OOP
Andy Wang Object Oriented Programming in C++ COP 3330
Object Oriented Practices
Chapter 7 Classes & Objects.
Introduction to Data Structure
Chapter 7 Classes & Objects.
Object-Oriented PHP (1)
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
C++ Object Oriented 1.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Programming in C++ Ryan Kafuman 07/06/09

Programming in C++ ● Classes and Object Oriented Design ● Error Handling ● Function Overloading ● Operator Overloading ● RTTI and C++ style casting ● Namespaces ● Templates

Object Oriented Design: What is an object? An object is an encapsulation of data and functionality. Each object can be thought of as a black box machine once it is implemented. Constructors create the object, and methods allow manipulation of the object.

Object Oriented design: Interfaces Knowing exactly what kinds of manipulations and outputs a type of object supports allows the definition of a set of functions that provide that functionality. This leads to modularization: to add a new impmementation of a particular object, simply requires implementing the interface.

Object Oriented Design: Classes Objects belong to classes Object classes define the properties of objects belonging to that class Classes are like structs See examples 1 and 2: Interfacing with Polygons

Object Oriented Design: Classes contd. Example1 initialized the object in main Example2 used a constructor Theintrinsic data is still globally accessable in both cases. When designing an interface, you do not want to access data outside the class: encapsulation see example3

Class Inheritance Unlike structs, classes can derive from other classes and inherit their properties The class inheriting is called the “derived class”, and the class it inherits from is the “base class” See example4

Polymorphism and Multiple Inheritance Classes can derive from more than one class Derived classes can be treated like base classes Polymorphic classes can be addressed as the base class, however function calls can be to functions implemented in the derived class. This uses RTTI, and induces latency, but allows a level of abstraction that C does not offer. See example5

Error Handling in C++ C++ offers two new ways of handling two different kinds of errors Assert: If a thing should never happen in a proper implementation, you can assert it. Exceptions can allert the program to other types of run-time errors.

Asserts Used for things that should never happen Simply assert it is so: assert(x>0); assert(ptr!=NULL); etc. #define NDEBUG removes all asserts.

Exceptions Exceptions handle run-time errors that can occur during normal operation Some functions return error codes. Sometimes functions cannot return error codes.

Exceptions Contd. try {... throw(some exception);... } catch(exception e) {... } See example6: Hermitian Matrices

Operator Overloading Use familiar operators (+, -, *, /, etc.) to interact with user defined types. Leads to straightforward, easy to read code. Implements like a regular function see example7: Sums and scalar multiplication of vectors

Function Overloading No more having to remember many names of different versions of the same function. Functions given the same name, but with different argument lists can coexist. Leads to simpler looking code, with simpler naming conventions. See example8: Measuring Distances

More Advanced Topics Namespaces allow global namespace to kept clean and can also allow some modularization. Templates allow an even higher level of abstraction

The End Thank You.