Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <cstring>
- using namespace std;
- class om {
- char* post;
- public:
- om(){ post=0;};
- om(char*);
- om(om&);
- ~om(){delete[] post;};
- void set_post(char*);
- char* get_post();
- friend ostream& operator <<(ostream &,om&);
- friend istream& operator >>(istream &,om&);
- };
- om::om(char* post):post(new char[strlen(post)+1]){
- strcpy(this->post,post);
- };
- om::om(om&obj){
- if(this->post!=NULL) delete[] this->post;
- this->post = new char[strlen(obj.post)+1];
- strcpy(this->post,obj.post);
- };
- void om::set_post(char *post){
- if(this->post!=NULL)delete[]this->post;
- this->post=new char[strlen(post)+1];
- strcpy(this->post,post);
- };
- char* om::get_post(){
- return post;
- };
- istream& operator >>(istream& in,om& obj){
- char buff[100];
- in>>buff;
- obj.set_post(buff);
- return in;
- }
- ostream& operator <<(ostream& out,om&obj){
- out<<"Post: "<<obj.post<<endl;
- return out;
- }
- class coloborator:public om {
- float salariu;
- public:
- coloborator(){salariu=0;};
- coloborator(float);
- ~coloborator(){salariu=0;};
- coloborator& operator = (coloborator&);
- friend ostream& operator <<(ostream &,coloborator&);
- friend istream& operator >>(istream &,coloborator&);
- };
- coloborator::coloborator(float salariu):salariu(salariu){};
- coloborator& coloborator:: operator = (coloborator&obj){
- this->set_post(obj.get_post());
- this->salariu=obj.salariu;
- return *this;
- };
- istream& operator >>(istream& in,coloborator& obj){
- char buff[100];
- cout<<"Dati postul omului: "<<endl;
- in>>buff;
- obj.set_post(buff);
- cout<<"Dati salariul omului: "<<endl;
- in>>obj.salariu;
- return in;
- }
- ostream& operator <<(ostream& out,coloborator&obj){
- out<<"Post: "<<obj.get_post()<<endl;
- out<<"Salariu: "<<obj.salariu<<endl;
- return out;
- }
- int main(void){
- coloborator c,c1;
- cout<<"Dati datele despre om:"<<endl;
- cin>>c;
- cout<<"\nDati datele despre colaborator:"<<endl;
- cin>>c1;
- cout<<"Om:"<<endl;
- cout<<c;
- cout<<"\nColaborator:"<<endl;
- cout<<c1;
- cout<<"\nAtribuire"<<endl;
- c=c1;
- cout<<"Om:"<<endl;
- cout<<c;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement