#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="" 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="" operatorul="pentru" 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<