Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <time.h>
- #include <string>
- using namespace std;
- class tree {
- public:
- int size,x,y;
- tree() {
- size = 10 + rand() % 50;
- x = 10 + rand() % 500;
- y = 10 + rand() % 500;
- //printf("tree size = %d",size);
- }
- ~tree() {
- printf("tree delete");
- }
- virtual void prt() {};
- virtual void set_xy() {};
- };
- class oak : public tree {
- public:
- string name;
- oak():tree() {
- name = "oak";
- }
- void prt() {
- cout << "tree size = " << size << " meter name = " << name <<endl;
- }
- void set_xy(int x, int y) {
- this->x = x;
- this->y = y;
- }
- };
- class birch : public tree {
- public:
- string name;
- birch() :tree() {
- name = "birch";
- }
- void prt() {
- cout << "tree size = " << size << " meter name = " << name << endl;
- }
- void set_xy(int x, int y) {
- this->x = x;
- this->y = y;
- }
- };
- class maple : public tree {
- public:
- string name;
- maple() :tree() {
- name = "maple";
- }
- void prt() {
- cout << "tree size = " << size << " meter name = " << name << endl;
- }
- void set_xy(int x, int y) {
- this->x = x;
- this->y = y;
- }
- };
- class MyStorage {
- private:
- int _size;
- tree **obj,**obj2;
- public:
- MyStorage(int size) {
- _size = size;
- obj = new tree*[_size];
- }
- int getCount() {
- return _size;
- }
- tree &getObject(int index) {
- return *obj[index];
- }
- void setObject(int index, tree *tr) {
- obj[index] = tr;
- }
- void add(int index, tree* tr) {
- _size++;
- obj2 = new tree * [_size];
- obj2[index] = tr;
- for (int i = 0; i < index; i++)
- obj2[i] = obj[i];
- for (int i = index+1; i < _size; i++)
- obj2[i] = obj[i-1];
- delete(obj);
- obj = new tree * [_size];
- for (int i = 0; i < _size; i++)
- obj[i] = obj2[i];
- }
- void del(int index, tree* tr) {
- }
- };
- int main()
- {
- srand(time(NULL));
- //MyStorage storage(12);
- //cout << storage.getcount() << endl;
- //scanf("%d", &a);
- //cout << storage.getValue(a) << endl;
- /*storage.setValue(3, new oak());
- storage.getValue(3).prt();
- /*oak* a = new oak();
- a.*/
- // ٌîçنàهى ًُàيèëèùه
- MyStorage storage(10);
- // نîلàâëےهى â يهمî îلْهêٍû
- for (int i = 0; i < storage.getCount(); i++)
- storage.setObject(i, new maple());
- // îلًàùàهىٌے ïîî÷هًهنيî êî âٌهى
- for (int i = 0; i < storage.getCount(); i++)
- storage.getObject(i).prt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement