Program Overriding Member Functions


#include <iostream.h>
#include <string.h>
/*----------------------Class Interfaces-------------------------*/
class employee
{
        char name[10];
        int empno;
    public :
        void set(int, char*);
        void display_heading();
        void display();
};
class manager : public employee
{
        int no_of_projects;
    public:
        void set(int, char*, int);    // functions overriding the
        void display_heading();        // base class definitions

        void display_projects();
};
/*----------------------Class Implementations---------------------*/
// member function definitions for 'employee'
void employee::set(int c, char* s)
{
    empno = c;
    strcpy(name, s);
}
void employee::display_heading()
{
    cout << "Employee Information : \n";
}
void employee::display()
{
    cout << "Employee No. : " << empno << "\n";
    cout << "Name         : " << name << "\n";
}
// member function definitions for 'manager'
void manager::set(int c, char* s, int p)
{
    no_of_projects = p;
    employee::set(c, s);// base class function explicitly invoked
}
void manager::display_heading()
{
    cout << "Manager Details : \n";
}
void manager::display_projects()
{
    cout << "No of Projects currently handling : ";
    cout << no_of_projects << "\n";
}
/*----------------------Class definitions ends here---------------*/
void main(void)
{
    manager peter;

    peter.set(1000, "Peter", 4);
    peter.display_heading();
    peter.display();
    peter.display_projects();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|