Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- class Animal
- {
- protected:
- string name;
- int number;
- int level;
- public:
- Animal() :name(""), number(0), level(0) {};
- Animal(string n, int m, int l) :name(n), number(m), level(l) {};
- Animal(const Animal&a) :name(a.name), number(a.number), level(a.level) {};
- string get_name()
- {
- return name;
- }
- int get_number()
- {
- return number;
- }
- int get_level()
- {
- return level;
- }
- virtual void input_f(ifstream&file)
- {
- file >> name;
- file >> number;
- file >> level;
- }
- };
- const static int Size = 3;
- class Zoo
- {
- protected:
- string sity;
- string zoo;
- Animal * arr;
- public:
- Zoo() :sity(""), zoo(""), arr(new Animal[2]){};
- Zoo(string s, string z, Animal*a) : sity(s), zoo(z), arr(a) {};
- Zoo(const Zoo&z) :sity(z.sity), zoo(z.zoo), arr(z.arr) {};
- string get_sity()
- {
- return sity;
- }
- string get_zoo()
- {
- return zoo;
- }
- int get_dangerous_level(int i)
- {
- return arr[i].get_level();
- }
- string get_animal(int i)
- {
- return arr[i].get_name();
- }
- int get_number_of_animal(int i)
- {
- return arr[i].get_number();
- }
- virtual void input_z(ifstream & file)
- {
- file >> sity;
- file >> zoo;
- string z_name;
- int z_number, z_level;
- for (int i = 0; i < Size; i++)
- {
- file >> z_name;
- file >> z_number;
- file >> z_level;
- Animal a(z_name, z_number, z_level);
- arr[i] = a;
- }
- }
- void sort()
- {
- for (int i = 0; i < Size - 1; i++)
- for (int j = i + 1; j < Size; j++)
- {
- if (arr[i].get_name() > arr[j].get_name())
- {
- swap(arr[i], arr[j]);
- }
- }
- }
- };
- void print2(Zoo *zoo, int size_of_zoo)
- {
- //for (int i = 0; i < size_of_zoo; i++)
- //{
- // zoo[i].sort();
- //}
- ofstream file("rez.txt", ios_base::out);
- for (int i = 0; i < size_of_zoo; i++)
- {
- file << zoo[i].get_sity() << endl;
- file << zoo[i].get_zoo() << endl;
- for (int j = 0; j < Size; j++)
- {
- file << zoo[i].get_animal(j) << endl;
- // file << zoo[i].get_number_of_animal(j) << endl;
- }
- }
- file << "animal in danger" << endl;
- for (int i = 0; i < size_of_zoo; i++)
- {
- for (int j = 0; j < Size; j++)
- {
- if (zoo[i].get_dangerous_level(j) > 50)
- {
- file << zoo[i].get_animal(j);
- }
- }
- }
- }
- void print3(Zoo *zoo, int size_of_zoo)
- {
- //for (int i = 0; i < size_of_zoo; i++)
- //{
- // zoo[i].sort();
- //}
- for (int i = 0; i < size_of_zoo; i++)
- {
- cout << zoo[i].get_sity() << endl;
- cout << zoo[i].get_zoo() << endl;
- for (int j = 0; j < Size; j++)
- {
- cout << zoo[i].get_animal(j) << endl;
- //cout << zoo[i].get_number_of_animal(j) << endl;
- }
- }
- cout << "animal in danger" << endl;
- for (int i = 0; i < size_of_zoo; i++)
- {
- for (int j = 0; j < Size; j++)
- {
- if (zoo[i].get_dangerous_level(j) > 50)
- {
- cout << zoo[i].get_animal(j);
- }
- }
- }
- }
- int main()
- {
- ifstream file("zoo.txt",ios_base::in);
- if (!file.is_open())
- {
- cout << "cant open file" << endl;
- }
- if (!file.eof())
- {
- int size;
- file >> size;
- Zoo * arr = new Zoo[size];
- int i = 0;
- int x;
- while(i<size)
- {
- file >> x;
- if(x==0)
- {
- arr[i].input_z(file);
- i++;
- }
- }
- print3(arr, size);
- print2(arr, size);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement