#include #include #include using namespace std; class animal_de_companie//Clasa de baza { private: char* nume; char* regn; char* ordin; int nr_ani; int *nr_rase; int vechime_specie; public: virtual void culoare()//functia virtuala { cout<<"culoarea animalului este nedefinita\n"<nume = new char[strlen(n) + 1]; strcpy(nume, n); this->regn = new char[strlen(r) + 1]; strcpy(regn, r); this->ordin = new char[strlen(o) + 1]; strcpy(ordin, o); this->nr_ani=n_a; /*this->nr_rase = new int[40]; this->nr_rase=v;*/ this->nr_rase=new int[12]; for(int i=0;i<12;i++) this->nr_rase[i]=nr_rase[i]; this->vechime_specie=v_s; cout<<"S-a apelat constructorul cu parametri"<nume = new char[strlen(a.nume) + 1]; strcpy(nume, a.nume); this->regn = new char[strlen(a.regn) + 1]; strcpy(regn, a.regn); this->ordin = new char[strlen(a.ordin) + 1];
strcpy(ordin, a.ordin); this->nr_ani=a.nr_ani; /*this->nr_rase = new int[40]; this->nr_rase=a.nr_rase;*/ this->nr_rase=new int[12]; for(int i=0;i<12;i++) this->nr_rase[i]=a.nr_rase[i]; this->vechime_specie=a.vechime_specie; cout<<"S-a apelat constructorul de copiere"<nume; delete[] this->regn; delete[] this->ordin; delete[] this->nr_rase; cout<regn; delete[] this->ordin; delete[] this->nr_rase; this->nume=new char [strlen(s.nume)+1]; strcpy(nume,s.nume); this->regn = new char[strlen(s.regn) + 1]; strcpy(regn, s.regn); this->ordin = new char[strlen(s.ordin) + 1]; strcpy(ordin, s.ordin); this->nr_ani=s.nr_ani; /*this->nr_rase = new int[40]; this->nr_rase=s.nr_rase;*/ this->nr_rase=new int[12]; for(int i=0;i<12;i++) this->nr_rase[i]=s.nr_rase[i]; this->vechime_specie=s.vechime_specie; cout<<"S-a apelat operatorul ="<nume = new char[strlen(n) + 1]; strcpy(nume, n); } char* getregn()
// Supraincarcare operator
{ return regn; } void setregn(char* r) { if(regn!=NULL) { delete[] regn; } this->regn = new char[strlen(r) + 1]; strcpy(regn, r); } char* getordin() { return ordin; } void setordin(char* o) { if(ordin!=NULL) { delete[] ordin; } this->ordin = new char[strlen(o) + 1]; strcpy(ordin, o); } int getnr_ani() { return nr_ani; } void setnr_ani(float n_a) { nr_ani =n_a; } int getvechime_specie() { return vechime_specie; } void setvechime_specie(float v_s) { vechime_specie =v_s; } void setnr_rase(int*p) {nr_rase=new int[10]; nr_rase=p; } int* getnr_rase() { return nr_rase; }
friend istream& operator>>(istream&, animal_de_companie& a);
friend ifstream& operator>>(ifstream&, animal_de_companie& a); friend ofstream& operator<<(ofstream&, animal_de_companie& a); friend friend friend friend friend
istream& operator>>(istream&, animal_de_companie& a); ostream& operator<<(ostream&, animal_de_companie a); int operator+(animal_de_companie&, int); int operator-(animal_de_companie&, int); const animal_de_companie& operator++(animal_de_companie&);
friend class pisica; friend class mamifer; }; //operator + int operator+(animal_de_companie& s, int x) { return s.nr_ani + x; cout<<"s-a apelat operatorul +"<>(istream& intrare, animal_de_companie& a) { cout<<"Nume: "; char n[40]; intrare.getline(n, 40); a.setnume(n); cout<<"regn: "; char r[40]; intrare.getline(r, 40); a.setregn(r);
cout<<"ordin: "; char o[40]; intrare.getline(o, 40); a.setordin(o); return intrare; } ifstream& operator>>(ifstream& f, animal_de_companie& a) { f.open("afisare.bin", ios::in|ios::_Nocreate); if(f) { char n[10]; f>>n; a.setnume(n); char r[10]; f>>r; a.setregn(r); char o[10]; f>>o; a.setordin(o); int n_a; f>>n_a; a.setnr_ani(n_a); int v_s; f>>v_s; a.setvechime_specie(v_s); cout<<"s-a apelat citirea din fisier"<
{ public: virtual void spune_ceva() { cout<<"ham,Ham"<nume_proprietar=new char [strlen(n_p)+1]; strcpy (nume_proprietar, n_p); cout<<"s-a apelat constructorul cu parametrii pentru clasa derivata"<nume_proprietar = new char[strlen(p.nume_proprietar) + 1]; strcpy(nume_proprietar,p.nume_proprietar); cout<<"S-a apelat constructorul de copiere pentru clasa derivata"<nume_proprietar; cout<regn; delete[] this->ordin; delete[] this->nume_proprietar; delete[] this->nr_rase; this->nume_proprietar = new char[strlen(g.nume_proprietar) + 1]; strcpy(nume_proprietar,g.nume_proprietar); cout<<"s-a apelat operatorul = pentru clasa derivata"; return (* this); cout<<"Operator ="<
void set_nume_proprietar(char* n_p) { if(nume_proprietar!=NULL) { delete[] nume_proprietar; } this->nume_proprietar = new char[strlen(n_p) + 1]; strcpy(nume_proprietar, n_p); }
}; void main() { animal_de_companie c; int e[1]={19}; animal_de_companie b ("caine","animalia","carnivora",25,e,1500); ofstream x; x<>h; animal_de_companie j ("iguana","as","s",18,e,1900); animal_de_companie d=b; animal_de_companie f; f=b; pisica(); pisica a ("mata","animalia","carnivora",10,e,1000,"ion"); cout<