Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. class om {
  7.    char* post;
  8.  
  9.    public:
  10.    om(){ post=0;};
  11.    om(char*);
  12.    om(om&);
  13.    ~om(){delete[] post;};
  14.    void set_post(char*);
  15.    char* get_post();
  16.    friend ostream& operator <<(ostream &,om&);
  17.    friend istream& operator >>(istream &,om&);
  18. };
  19.  
  20. om::om(char* post):post(new char[strlen(post)+1]){
  21.     strcpy(this->post,post);
  22. };
  23.  
  24. om::om(om&obj){
  25.    if(this->post!=NULL) delete[] this->post;
  26.    this->post = new char[strlen(obj.post)+1];
  27.    strcpy(this->post,obj.post);
  28. };
  29.  
  30.  
  31. void om::set_post(char *post){
  32.      if(this->post!=NULL)delete[]this->post;
  33.      this->post=new char[strlen(post)+1];
  34.      strcpy(this->post,post);
  35. };
  36.  
  37. char* om::get_post(){
  38.     return post;
  39. };
  40.  
  41.  
  42. istream& operator >>(istream& in,om& obj){
  43.  
  44.     char buff[100];
  45.     in>>buff;
  46.     obj.set_post(buff);
  47.     return in;
  48. }
  49.  
  50. ostream& operator <<(ostream& out,om&obj){
  51.  
  52. out<<"Post: "<<obj.post<<endl;
  53. return out;
  54.  
  55. }
  56.  
  57. class coloborator:public om {
  58.    float salariu;
  59.  
  60.    public:
  61.    coloborator(){salariu=0;};
  62.    coloborator(float);
  63.    ~coloborator(){salariu=0;};
  64.    coloborator& operator = (coloborator&);
  65.    friend ostream& operator <<(ostream &,coloborator&);
  66.    friend istream& operator >>(istream &,coloborator&);
  67. };
  68.  
  69. coloborator::coloborator(float salariu):salariu(salariu){};
  70.  
  71. coloborator& coloborator:: operator = (coloborator&obj){
  72.  
  73.  
  74.       this->set_post(obj.get_post());
  75.       this->salariu=obj.salariu;
  76.       return *this;
  77. };
  78.  
  79. istream& operator >>(istream& in,coloborator& obj){
  80.  
  81.     char buff[100];
  82.     cout<<"Dati postul omului: "<<endl;
  83.     in>>buff;
  84.     obj.set_post(buff);
  85.     cout<<"Dati salariul omului: "<<endl;
  86.     in>>obj.salariu;
  87.     return in;
  88. }
  89.  
  90. ostream& operator <<(ostream& out,coloborator&obj){
  91.  
  92. out<<"Post: "<<obj.get_post()<<endl;
  93. out<<"Salariu: "<<obj.salariu<<endl;
  94. return out;
  95. }
  96.  
  97. int main(void){
  98.  
  99.     coloborator c,c1;
  100.     cout<<"Dati datele despre om:"<<endl;
  101.     cin>>c;
  102.     cout<<"\nDati datele despre colaborator:"<<endl;
  103.     cin>>c1;
  104.     cout<<"Om:"<<endl;
  105.     cout<<c;
  106.     cout<<"\nColaborator:"<<endl;
  107.     cout<<c1;
  108.     cout<<"\nAtribuire"<<endl;
  109.     c=c1;
  110.     cout<<"Om:"<<endl;
  111.     cout<<c;
  112.  
  113.   system("pause");
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement