









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 15
This page cannot be seen from the preview
Don't miss anything!










►
►
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 : 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();
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;
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;
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””; }; }
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;
_shape[ i ].draw();
*(_shape + (i * sizeof(Shape))).draw();
docsity.com