Continued from last class

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Operator overloading redefine the operations of operators
Functions Prototypes, parameter passing, return values, activation frams.
1 Data Structures - CSCI 102 CS102 C++ Operator Overloading Prof Tejada.
1 CSC241: Object Oriented Programming Lecture No 21.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. S. Kozaitis Summer Summary of Topics Related to Classes Class definition Defining member.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
Chapter 19 - Inheritance Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Chapter 20- Virtual Functions and Polymorphism Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Synthetic OO Design Concepts & Reuse Lecture 1: Program fragments and abstract classes CSE335 Spring 2008 E. Kraemer adapted from K. Stirewalt.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20- Virtual Functions and Polymorphism Outline 20.1Introduction 20.2Type Fields and switch Statements.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 - Inheritance Outline 19.1Introduction 19.2Inheritance: Base Classes and Derived Classes 19.3Protected.
Slide 1 Polymorphism: Part I. Slide 2 Summary: Derived Class * ‘is-a’ relationship n Different from ‘has-a’ or ‘uses-a’, or … by class-in-class * Public.
Multiple-Subscripted Array
1 Lecture Note 9_Polymorphism Outline Relationships Among Objects in an Inheritance Hierarchy Invoking Base-Class Functions from Derived-Class object Virtual.
Abstract Classes An abstract class is a base class that will never have an object instantiated from it. –Abstract classes are used only for inheritance,
CS342 Data Structure Review of C++: Overriding base- class functions.
1 Abstract Class There are some situations in which it is useful to define base classes that are never instantiated. Such classes are called abstract classes.
Interfaces Need arising from software engineering –Disparate groups of programmers need to agree to a “contract” that spells out how their software interacts.
 Review structures  Program to demonstrate a structure containing a pointer.
1 Object-Oriented Programming Using C++ CLASS 11 Honors.
Polymorphism Dr. Leon Jololian. Dr.Jololian2 class Person { private: string name; int age; public: Person(string na, int ag); Person(string na); string.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
CMSC 2021 Polymorphism. CMSC 2022 Static vs. Dynamic Binding Binding The determination of which method in the class hierarchy is to be used for a particular.
Outline 1 Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 20 - C++ Virtual Functions and Polymorphism.
1 Chapter 5 - Object-Oriented Programming 1 What is inheritance? Object-oriented systems allow classes to be defined in terms of other classes. Classes.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Inheritance Outline 9.1Introduction 9.2Inheritance: Base Classes and Derived Classes 9.3.
Slide 1 Polymorphism: Part I. Slide 2 Summary: Derived Class * ‘is-a’ relationship n Different from ‘has-a’ or ‘uses-a’, or … by class-in-class * Public.
1 Data Structures CSCI 132, Spring 2014 Lecture 6 Applications using Stacks.
Instructor - C. BoyleFall Semester
C++ Lecture 5 Monday, 18 July Chapter 7 Classes, continued l const objects and const member functions l Composition: objects as members of classes.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Class 15 - Overhead 1Object Oriented Programming Using C #include class telephone { public: telephone(char *number, int volume); int dial(char *outgoing_number);
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 – Inheritance – Part 1 Outline 19.1Introduction 19.2Inheritance: Base Classes and Derived Classes.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Polymorphism Outline 20.5Polymorphism 20.6Case Study: A Payroll System Using Polymorphism.
1 Data Structures CSCI 132, Spring 2016 Notes 6 Applications using Stacks.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
 Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
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* Review Jason Stredwick.
Chapter 19 - C++ Inheritance
Chapter 10 - Object-Oriented Programming: Polymorphism
Lab6_II Object-Oriented Programming: Polymorphism
null, true, and false are also reserved.
Chapter 10 - Object-Oriented Programming: Polymorphism
Introduction to Programming
Starting Out with C++: From Control Structures through Objects
Chapter 20- Virtual Functions and Polymorphism
Default Arguments.
Dynamic Memory A whole heap of fun….
Chapter 19 - Inheritance Outline 19.1 Introduction
Chapter 20 - C++ Virtual Functions and Polymorphism
Object-Oriented Programming: Polymorphism
Polymorphism: Part I.
Chapter 19 - Inheritance Outline 19.1 Introduction
Capitolo 10- Virtual Functions and Polymorphism
C++ Pointers and Strings
Virtual Functions Example
Function Overloading.
Object-Oriented Programming: Polymorphism
IS 0020 Program Design and Software Tools
The Stack.
Presentation transcript:

Continued from last class class Boss : public Employee { public: Boss( const char *, const char *, double = 0.0 ); void setWeeklySalary( double ); virtual double earnings() const; virtual void print() const; private: double weeklySalary; }; Boss :: Boss( const char *first, const char *last, double s ) : Employee( first, last ) { setWeeklySalary( s ); } void Boss :: setWeeklySalary( double s ) { weeklySalary = s>0 ? s : 0;

double Boss :: earnings() const { return weeklySalary; } void Boss :: print() const { cout << “\n Boss: “; Employee :: print(); class HourlyWorker : public Employee { public: HourlyWorker( const char *, const char *, double = 0.0, double = 0.0 ); void setWage( double ); void setHours( double ); virtual double earnings() const; virtual void print() const; private: double wage; double hours; };

HourlyWorker :: HourlyWorker( const char *first, const char *last, double w, double h ) : Employee( first, last ) { setWage( w ); setHours( h ); } void HourlyWorker :: setWage( double w ) { wage = w>0 ? w : 0; void HourlyWorker :: setHours( double h ) { hours = h>=0 && h<168 ? h : 0; double HourlyWorker :: earnings() const { if( hours<=40 ) return wage*hours; else return 40*wage+(hours-40)*wage*1.5;

void HourlyWorker :: print() const { cout << “\n Hourly worker: “; Employee :: print(); } void virtualViaPointer( const Employee *baseClassPtr ) { baseClassPtr->print(); cout << “ earned $” << baseClassPtr->earnings(); void virtualViaReference( const Employee &baseClassRef ) { baseClassRef.print(); cout << “ earned $” << baseClassRef.earnings();

int main() { Boss b( “John”, “Smith”, 800.00 ); b.print(); cout << “ earned $” << b.earnings(); virtualViaPointer( &b ); virtualViaReference( b ); HourlyWorker h( “Karen”, “Price”, 13.75, 40 ); h.print(); cout << “ earned $” << h.earnings(); virtualViaPointer( &h ); virtualViaReference( h ); cout << endl; return 0; }