Andy Wang Object Oriented Programming in C++ COP 3330

Slides:



Advertisements
Similar presentations
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Advertisements

Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
Approfondimento Classi - Esempi1 // Argomento: Oggetti membri di altre classi // Declaration of the Date class. // Member functions defined in date1.cpp.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Starting Out with C++, 3 rd Edition 1 Chapter 15 – Inheritance, Polymorphism, and Virtual Functions.
1 Abstract Data Type (ADT) a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how)
1 Class Constructors a class constructor is a member function whose purpose is to initialize the private data members of a class object the name of a constructor.
Classi - Esempi1 // SalesPerson class definition // Member functions defined in salesp.cpp #ifndef SALESP_H #define SALESP_H class SalesPerson { public:
1 The UNIX date command myclock.cpp example The C/C++ time() and ctime() functions myclock2.cpp example Inline function definitions Inline class member.
ITEC 320 C++ Examples.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
1 Object-Oriented Programming Using C++ CLASS 5. 2 Object Composition Object composition occurs when a class contains an instance of another class. Creates.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 10 1.
Inheritance One of the most powerful features of C++
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 6 1.
11 Introduction to Object Oriented Programming (Continued) Cats.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 11: Class diagrams; class relationships.
Object Oriented Programming COP3330 / CGS5409.  Multiple Inheritance  Template Classes and Functions.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
February 28, 2005 Introduction to Classes. Object Oriented Programming An object is a software bundle of related variables and methods. Software objects.
11 Introduction to Object Oriented Programming (Continued) Cats.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Introduction to Programming
Chapter 12 Classes and Abstraction
Andy Wang Object Oriented Programming in C++ COP 3330
#define #include<iostream> using namespace std; #define GO
Template Classes and Functions
Command Line Arguments
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Sorting Algorithms.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Chapter Structured Types, Data Abstraction and Classes
Arrays Part-1 Armen Keshishian.
CMPE Data Structures and Algorithms in C++ February 22 Class Meeting
Andy Wang Object Oriented Programming in C++ COP 3330
Introduction to Structured Data Types and Classes
תכנות מכוון עצמים ו- C++ יחידה 03 מחלקות: תכונות, שיטות, הרשאות, const
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Random Number Generation
Andy Wang Object Oriented Programming in C++ COP 3330
Andy Wang Object Oriented Programming in C++ COP 3330
Creation and Use of Namespaces
Screen output // Definition and use of variables
Templaets It is a new concept which enables us to define “generic class “ and “generic function” to provide the “ generic programming” We are familiar.
Introduction to Programming
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
Code::Block vs Visual C++
CSC 270 – Survey of Programming Languages
How Dynamic Memory Works with Memory Diagram
How Classes Work with Memory Diagram
C++ Compilation Model C++ is a compiled language
Introduction of Programming
Mr. Dave Clausen La Cañada High School
Function Overloading.
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Recitation Course 0520 Speaker: Liu Yu-Jiun.
Separate Compilation.
Inline Functions.
Pointers and dynamic objects
Pointers & Functions.
CMSC 341 C++ and OOP.
Andy Wang Object Oriented Programming in C++ COP 3330
Object-Oriented Programming (OOP) Lecture No. 23
How Dynamic Memory Works with Memory Diagram
How Classes Work with Memory Diagram
Presentation transcript:

Andy Wang Object Oriented Programming in C++ COP 3330 Multiple Inheritance Andy Wang Object Oriented Programming in C++ COP 3330

Multiple Inheritance C++ supports multiple inheritance A class can inherit properties from more than one base class (multiple parent classes) Not all object-oriented languages support multiple inheritance (e.g., Java)

Inline functions: code inserted at each invocation point date.h #ifndef _DATE_H #define _DATE_H class Date { protected: int day, month, year; public: Date() { day = month = 1; year = 1900; } Date(int d, int m, int y) { day = d; month = m; year = y; } int getDay() const { return day; } int getMonth() const { return month; } int getYear() const { return year; } }; #endif Inline functions: code inserted at each invocation point

time.h #ifndef _TIME_H #define _TIME_H class Time { protected: int hour, min, sec; public: Time() { hour = min = sec = 0; } Time(int h, int m, int s) { hour = h; min = m; sec = s; } int getHour() const { return hour; } int getMin() const { return min; } int getSec() const { return sec; } }; #endif

datetime.h #ifndef _DATETIME_H #define _DATETIME_H const int DT_SIZE = 20; class DateTime : public Date, public Time { protected: char dateTimeString[DT_SIZE]; public: DateTime(); DateTime(int, int, int, int, int, int); const char *getDateTime() const { return dateTimeString; } }; #endif

datetime.cpp #include <cstring> #include <cstdlib> #include “DateTime.h” const int TEMP_SIZE = 10; DateTime::DateTime() : Date(), Time() { strcpy(dateTimeString, “1/1/1900 0:0:0”); }

datetime.cpp DateTime::DateTime(int dy, int mon, int yr, int hr, int mt, int sc) : Date(dy, mon, yr), Time(hr, mt, sc) { char temp[TEMP_SIZE]; strcpy(dateTimeString, itoa(getMonth(), temp, TEMP_SIZE); strcat(dateTimeString, “/”); strcpy(dateTimeString, itoa(getDay(), temp, TEMP_SIZE); strcpy(dateTimeString, itoa(getYear(), temp, TEMP_SIZE); strcat(dateTimeString, “ ”);

datetime.cpp strcpy(dateTimeString, itoa(getHour(), temp, TEMP_SIZE); strcat(dateTimeString, “:”); strcpy(dateTimeString, itoa(getMin(), temp, TEMP_SIZE); strcpy(dateTimeString, itoa(getSec(), temp, TEMP_SIZE); }

main.cpp #include <iostream> #include “DateTime.h” using namespace std; int main() { DateTime emptyDay; cout << emptyDay.getDateTime() << endl; DateTime pastDay(2, 4, 60, 5, 32, 27); cout << pastDay.getDateTime() << endl; return 0; }