ECE 264 Object-Oriented Software Development

Slides:



Advertisements
Similar presentations
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
ECE 264 Object-Oriented Software Development
 2006 Pearson Education, Inc. All rights reserved Operator Overloading.
Operator Overloading in C++ Systems Programming. Systems Programming: Operator Overloading 22   Fundamentals of Operator Overloading   Restrictions.
Lecture 9 Concepts of Programming Languages
12/08/08MET CS Fall Polymorphism 10. Polymorphism Goal: Goal: Create methods that can be invoked with all object types, base as well as.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
Review of C++ Programming Part II Sheng-Fang Huang.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
OOP Languages: Java vs C++
Chapter 12: Adding Functionality to Your Classes.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Copy Control Joe Meehean. More Class Responsibilities When making a new type (i.e., class) we must specify what happens when it is: Copied Assigned Destroyed.
Inheritance in C++ CS-1030 Dr. Mark L. Hornick.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Exam 3 Preview.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Object-Based Programming Mostly Review. Objects Review what is object? class? member variables? member functions? public members? private members? friend.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 31: Operator overloading examples, inheritance intro.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 29: Operator overloading.
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.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 18: More on inheritance and Polymorphism.
Introduction to Classes in C++ Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 16: Destructors, Copy Constructors and Exam 2 Review.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Abstract Classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 13: Exam 1 Preview.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 17: Operator overloading and inheritance intro.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Pointer to an Object Can define a pointer to an object:
Learning Objectives Pointers as dada members
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
Andy Wang Object Oriented Programming in C++ COP 3330
Constructor & Destructor
Inheritance Often, software encapsulates multiple concepts for which some attributes/behaviors overlap E.g. A computer (role-playing) game has: Monsters:
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
CISC/CMPE320 - Prof. McLeod
Instructor: Dr. Michael Geiger Spring 2017 Lecture 12: Exam 1 Preview
Instructor: Dr. Michael Geiger Spring 2019 Lecture 23: Exam 2 Preview
Presentation transcript:

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 37: Exam 3 Preview

Lecture outline Announcements/Reminders General exam information Lab 10 submission due by tomorrow Project demos due December 7 (Friday) Entire group members must attend Presentation order: Group 1-Group 4 Project documentation (user’s guide, tech report) due December 10 General exam information Q & A Friday? Exam review: what we’ve covered since the last exam (not an exhaustive list!) Destructors Copy constructors Operator overloading Inheritance Basics of base/derived classes Use of constructors Virtual functions Pure virtual functions & abstract classes 4/27/2017 ECE 264: Lecture 37

General exam information 8.5” x 11” double-sided sheet of notes allowed; paper based materials allowed Exam date/time: Monday, 12/10, 9:00-9:50 am Exam will be written to (hopefully) take one hour Exam will be held in room: S&E 212 Very similar format to Exams 1 & 2: 3 questions, most of which have multiple parts Question 1: Multiple choice (more ?s, fewer points per ?) Question 2: Understanding code (i.e., given some code, what’s output?) Question 3: Writing short code sequences Sample Questions and solutions will be uploaded Tuesday 4/27/2017 ECE 264: Lecture 37

Review: Destructors class-name::~class-name() { } Destructors called when object destroyed; used for “object cleanup” At end of function When delete is used to deallocate object Often empty, unless object contains dynamically allocated data Destructor is responsible for deleting that data Syntax: class-name::~class-name() { } 4/27/2017 ECE 264: Lecture 16

Review: Copy constructors Called when new object created from existing object Example: Point p2 = p1; Default is shallow copy Need deep copy if object contains Array(s) Dynamically allocated data Must still copy all data members Syntax: class_name::class_name(const class_name &<param_name>) Example: tenInts::tenInts(const tenInts &t){ for (int i=0; i < 10; i++) arr[i] = t.arr[i]; } 4/27/2017 ECE 264: Lecture 37

Review: Operator overloading Allows use of built-in operators with user-defined types Definitions for overloaded operators included in class definition Example (from Point class) double operator –(const Point& rhs); Syntax: Keyword operator is used, followed by the actual operator “Argument” is an object reference of the same type const declarations are optional but often preferred Syntax exceptions: friend functions Has access to class data, but not technically part of class Used if LHS of operation is not of same type as class Example: stream operators (e.g. cin >> h1;) Both sides (of binary operator) must be specified as “arguments” 4/27/2017 ECE 264: Lecture 37

Review: Inheritance Create new class (derived class) from existing class (base class) Base class has functionality shared by derived class Can add functions to derived class Can customize base class functionality Can have inheritance hierarchy Syntax example using Rectangle/Square In Square.h, declare class as: class Square : public Rectangle Default constructor for a base class is called automatically in the derived class constructor Ex: Square() calls Rectangle() Will actually traverse inheritance hierarchy, starting at lowest class If derived class needs the parameterized constructor of base class, must explicitly invoke it in initialization list Ex: Square::Square(const Point &p, double s) : Rectangle(s, s, p.getX(), p.getY()) Access visibility: for data/functions to be visible to base & derived class(es), but not clients, declare as protected 4/27/2017 ECE 264: Lecture 37

Review: Polymorphism/virtual functions Polymorphism: Code/operations behave differently in different contexts One example: operator overloading Inheritance-based polymorphism in form of virtual functions Virtual functions allow us to write generic code that works for (hopefully) many specific cases Using pointers to objects allows dynamic binding Base class pointer can be used for derived class object ptr->function() will call version for appropriate class Also useful when Passing function arguments by reference Calling member function inside another member function (implicitly using this pointer) Remember, a class with virtual functions should have a virtual destructor 4/27/2017 ECE 264: Lecture 37

Review: Abstract classes Abstract classes give ability to specify generic class At least some base class functionality is too general to implement  use pure virtual function Having pure virtual function(s) makes class abstract Cannot instantiate object of abstract class type Pure virtual function syntax (in .h file): virtual <return_type> <fname>(<args>) = 0; Derived classes must overload pure virtual functions Failure to do so makes derived class abstract! 4/27/2017 ECE 264: Lecture 37