#include <iostream.h>
#include <string.h>
/*----------------------Class Interfaces-------------------------*/
class employee // base class
{
char name[10];
int empno;
public :
void set(int, char*);
void display();
};
class manager : public employee // Level - 1
{
int no_of_projects;
public:
void set(int, char*, int); // overriding functions
void display();
};
class area_manager : public manager // Level - 2
{
char location[10];
public:
void set(int, char*, int, char*);// overriding functions
void display();
};
/*----------------------Class Implementations---------------------*/
// member function definitions for 'employee'
void employee::set(int c, char* s)
{
empno = c;
strcpy(name, s);
}
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)
{
employee::set(c, s);
no_of_projects = p;
}
void manager::display()
{
employee::display();
cout << "No of Projects currently handling : ";
cout << no_of_projects << "\n";
}
// member function definitions for 'area_manager'
void area_manager::set(int c, char* s, int p, char* l)
{
manager::set(c, s, p);
strcpy(location, l);
}
void area_manager::display()
{
manager::display();
cout << "Location : ";
cout << location << "\n";
}
/*----------------------Class definitions ends here---------------*/
void main(void)
{
area_manager A;
A.set(1001, "Stavan", 5, "New York");
A.display();
}
0 comments:
Post a Comment