Person (name, address)-> base class
Employee (name, address, salary)-> derived class
Student (name, address, course) -> derived class
[Note: - Employee and Student are derived classes
that are derived features from the base class Person]
#include<iostream.h>
#include<string.h>
class person
{
protected: char name[10],address[10];
public: person()
{
strcpy(name,"");
strcpy(address,"");
}
person(char *n,char *a)
{
strcpy(name,n);
strcpy(address,a);
}
void show()
{
cout<<"\n Name="<<name<<" address="<<address;
}
};
class employee: public person
{
private: int sal;
public: employee()
{
}
employee(char *n,char *a,int s)
{
strcpy(name,n);
strcpy(address,a);
sal=s;
}
void show()
{
cout<<"\n Name="<<name<<" address="<<address<<" sal="<<sal;
}
};
class student: public person
{
private: char course[10];
public: student()
{
strcpy(name,"");
strcpy(address,"");
strcpy(course,"");
}
student(char *n,char *a,char *c)
{
strcpy(name,n);
strcpy(address,a);
strcpy(course,c);
}
void show()
{
cout<<"\n Name="<<name<<" address="<<address<<" course="<<course;
}
};
void main()
{
char a[10],b[10],d;
char a1[10],b1[10],c1[10];
cout<<"Name=";
cin>>a;
cout<<"Address=";
cin>>b;
cout<<"salary=";
cin>>d;
employee e1(a,b,d);
e1.show();
cout<<"\nName=";
cin>>a1;
cout<<"Address=";
cin>>b1;
cout<<"course=";
cin>>c1;
student s1(a1,b1,c1);
s1.show();
}
No comments:
Post a Comment