Class Employee-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Class, Employee, Statment, Problem, Report, Shape, Array, Polymorphism, Return, Main

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object
Object-
-Oriented Programming
Oriented Programming
(OOP)
(OOP)
Lecture No. 30
Lecture No. 30
Polymorphism
Polymorphism
Case Study
Case Study
A Simple Payroll Application
A Simple Payroll Application
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Class Employee-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object

Object

Oriented Programming

Oriented Programming

(OOP)

(OOP)

Lecture No. 30

Lecture No. 30

Problem Statement

Problem Statement

Develop a simple payroll application. There

Develop a simple payroll application. There

are three kinds of employees in the system:

are three kinds of employees in the system:

salaried employee, hourly employee, and

salaried employee, hourly employee, and

commissioned employee. The system takes commissioned employee. The system takes

as input an array containing employee as input an array containing employee

objects, calculates salary polymorphically,

objects, calculates salary polymorphically,

and generates report.

and generates report.

Class SalariedEmp

Class SalariedEmp

class SalariedEmp : public Employee class SalariedEmp : public Employee

private: private:

double salary;

double salary;

public: public:

SalariedEmp(String&,double,double);

SalariedEmp(String&,double,double);

virtual double calcSalary();

virtual double calcSalary();

Class HourlyEmp

Class HourlyEmp

class HourlyEmp : public Employee {class HourlyEmp : public Employee {

private:

private:

int hours; int hours;

double hourlyRate;

double hourlyRate;

public:public:

HourlyEmp(string&,double,int,double); HourlyEmp(string&,double,int,double);

virtual double calcSalary();

virtual double calcSalary();

Class CommEmp

Class CommEmp

CommEmp::CommEmp( String& n, CommEmp::CommEmp( String& n,

double tr, double s, double cr ) double tr, double s, double cr )

: Employee( n, tr ) {

: Employee( n, tr ) {

sales = s;

sales = s;

commRate = cr;

commRate = cr;

A Sample Payroll

A Sample Payroll

int main() {

int main() {

Employee* emp[10]; Employee* emp[10];

emp[0] = new SalariedEmp( emp[0] = new SalariedEmp( ““AamirAamir””,,

emp[1] = new HourlyEmp( emp[1] = new HourlyEmp( ““FaakhirFaakhir””,,

emp[2] = new CommEmp(

emp[2] = new CommEmp( “

Fuaad

Fuaad ”

generatePayroll( emp, 10 );

generatePayroll( emp, 10 );

return 0;

return 0;

Shape Hierarchy Revisited

Shape Hierarchy Revisited

Shape

Line Circle Triangle

draw

calcArea

draw

calcArea

draw

calcArea

draw

calcArea

Shape Hierarchy

Shape Hierarchy

class Line : public Shape { class Line : public Shape {

public: public:

Line(Point p1, Point p2);

Line(Point p1, Point p2);

void draw(){ cout << void draw(){ cout << ““LineLine\nn””; }; }

Polymorphism & Arrays

Polymorphism & Arrays

int main() {

int main() {

Point p1(10, 10), p2(20, 20), Point p1(10, 10), p2(20, 20), ……

Line _line[ 10 ];

Line _line[ 10 ];

_line[ 0 ] = Line( p1, p2 ); _line[ 0 ] = Line( p1, p2 );

_line[ 1 ] = Line( p3, p4 );

_line[ 1 ] = Line( p3, p4 );

drawShapes( _line, 10 );

drawShapes( _line, 10 );

return 0; return 0;

Because

Because

Line Array

Shape Array

_shape[ i ].draw();

*(_shape + (i * sizeof(Shape))).draw();

docsity.com