#include using namespace std; class ToyShop { private: const int id; char name[70]; unsigned int number_toys_type; float* prices; int number_sold_toys; public: //Constr with param ToyShop(int ID, char nume[70], int numar_vandute) :id(ID) { if (strlen(nume) < 70) { strcpy(name, nume); number_toys_type = 0; prices = NULL; number_sold_toys = numar_vandute; } else { throw exception(); } } void afisareToy() { cout << "ID: " << id << " Name: " << name << " No of toys type: " << number_toys_type; } //Copy constr ToyShop(ToyShop& a) :id(a.id) { strcpy(name, a.name); number_toys_type = a.number_toys_type; prices = NULL; number_sold_toys = a.number_sold_toys; } //Destructor ~ToyShop() { if (prices != NULL) delete prices; } //Operator = ToyShop operator=(const ToyShop& a) { if (prices != NULL) { delete prices; } strcpy(name, a.name); number_toys_type = a.number_toys_type; number_sold_toys = a.number_sold_toys; prices = new float[a.number_toys_type]; for (int i = 0; i < number_toys_type; i++) { prices[i] = a.prices[i]; } return *this; } //Getteri / Settari //const int id; //char name[70]; //unsigned int number_toys_type; //float* prices; //int number_sold_toys; // STATIC STRING ! //char* getName(char nume[70]) { // name = nume; // return this->name; //} char* getName() { return this->name; } void setName(char x[70]) { if (strlen(x) > 3) strcpy(name, x); else throw exception(); } int getID() { return this->id; } // NU FACE PENTRU UNSIGNED INT SET SI GET //unsigned int getNOtype() { // return this->number_toys_type; //} //void setNOtype(unsigned int x) { // return number_toys_type = x; //} ////GET + SET? //unsigned int getNoToysType(unsigned int c) { // number_toys_type = c; // return number_toys_type; //} //! FLOAT* GET //float* getPrices(float* pret) { // prices = new float[this->pret]; // for (int i = 0; i < pret; i++) // prices[i] = pret[i]; //} float* getPrices() { return this->prices; } void setPrices(float* new_price, int n) { if (prices != NULL) delete prices; else { prices = new float[n]; for (int i = 0; i < n; i++) { prices[i] = new_price[i]; } number_toys_type = n; } } int getNoSold(int no) { number_sold_toys = no; return number_sold_toys; } friend istream& operator >> (istream&, ToyShop& a); friend ostream& operator << (ostream&, ToyShop a); }; //Getteri / Settari //const int id; //char name[70]; //unsigned int number_toys_type; //float* prices; //int number_sold_toys; istream& operator >> (istream& intrare, ToyShop& a) { cout << "Name: " << endl; intrare >> a.name; cout << "No of types: " << endl; intrare >> a.number_toys_type; cout << "No sold toys " << endl; intrare >> a.number_sold_toys; a.prices = new float[a.number_toys_type]; for (int i = 0; i < a.number_toys_type; i++) { intrare >> a.prices[i]; cout << " " << endl; } return intrare; } ostream& operator <<(ostream& iesire, ToyShop a) { iesire << "Name: " << a.name; iesire << "No of types: " << a.number_toys_type; iesire << "No sold toys " << a.number_sold_toys; for (int i = 0; i < a.number_toys_type; i++) cout << a.prices[i] << " " << endl; return iesire; } void main() { ToyShop shop1(1, "Noriel", 2450); shop1.afisareToy(); ToyShop shop2(2,"Marcel",312); cout << shop2; cin >> shop2; cout << shop2; }