Inherited constructor and distructor
code:
#include<iostream>
using namespace std;
class information{
protected:
string name;
int id;
string address;
double salary;
public:
information(){
cout<<"Information default constractor called."<<endl;
name="Not entered.";
id=-1;
address="Not found.";
salary=0.0;
}information(string name,int id,string address,double salary){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
}
~information(){
cout<<"Name : "<<name<<endl;
cout<<"Id Number : "<<id<<endl;
cout<<"Address : "<<address<<endl;
cout<<"Salary : "<<salary<<endl;
}
void set_informaton(string name,int id,string address,double salary){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
}
};
class teacher:public information{
private:
string school_name;
string degree;
public:
teacher():information(){
cout<<"Teacher default constractor called."<<endl;
school_name="Not initialized.";
degree="Not Found";
}
teacher(string name,int id,string address,double salary,string school_name,string degree){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
this->school_name=school_name;
this->degree=degree;
}
void set_teacher(string name,int id,string address,double salary,string school_name,string degree){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
this->school_name=school_name;
this->degree=degree;
}
~teacher(){
cout<<"School Name : "<<school_name<<endl;
cout<<"Degree : "<<degree<<endl;
}
};
class police: public information{
private:
string post;
string posting;
public:
police():information(){
cout<<"Police default constractor called."<<endl;
post="Not entered.";
posting="Not found.";
}police(string name,int id,string address,double salary,string post,string posting){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
this->post=post;
this->posting=posting;
}
~police(){
cout<<"Post : "<<post<<endl;
cout<<"Posting : "<<posting<<endl;
}
void set_police(string name,int id,string address,double salary,string post,string posting){
this->name=name;
this->id=id;
this->address=address;
this->salary=salary;
this->post=post;
this->posting=posting;
}
};
int main()
{
teacher to;
police po;
teacher t1o("Subir saha",10113,"Jhinaidho",70000.583,"Pabna University of science and technology","Bsc Engineer from BUET");
police p1o("Samim arefin",190101,"Rajshahi",30000.74,"SI","Pabna sadar");
return 0;
}
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন