-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreading.cpp
128 lines (121 loc) · 3.44 KB
/
reading.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <fstream>
#include "cat.h"
#include "dog.h"
#include "fish.h"
#include <set>
#include <map>
std::vector<Animal *> anims;//объявляю глобальными, чтобы было видо во всех task
std::vector<Person> owners;
std::string ToLower(std::string &s)
{
for (int i = 0; i < s.size(); ++i)
{
s[i] = tolower(s[i]);
}
return s;
}
void reading(){
std::ifstream file("input.txt");
if (!file.is_open())
{
std::cerr << "File is not open!";
exit(1);
}
if (file.peek() == EOF)
{
std::cerr << "The file is empty!";
exit(1);
}
std::string owner_name = "";
std::string str_OwnerAge = "";
std::string animal_type = "";
std::string breed = "";
std::string animal_name = "";
std::string animal_age = "";
int ownerAge;
int animalAge;
while (!file.eof())
{
getline(file, owner_name, ',');
getline(file, str_OwnerAge, ';');
getline(file, animal_type, ',');
getline(file, breed, ';');
getline(file, animal_name, ';');
getline(file, animal_age);
ownerAge = stoi(str_OwnerAge);
animalAge = stoi(animal_age);
if (breed == ",,")
{
breed = "None";
}
if(animal_name == ",,"){
animal_name = "None";
}
if (animal_type == "cat")
{
anims.push_back(new Cat(animal_name, animalAge, breed));
Person pr(owner_name, ownerAge, anims[anims.size() - 1]);
bool isFind = 0;
for (auto &ps : owners)
{
if (ps.GetOwnerName() == owner_name && ps.GetOwnerAge() == ownerAge)
{
ps.Push_Animal(anims[anims.size() - 1]);
isFind = 1;
break;
}
}
if (!isFind)
{
owners.push_back(pr);
}
}
if (animal_type == "dog")
{
anims.push_back(new Dog(animal_name, animalAge, breed));
Person pr(owner_name, ownerAge, anims[anims.size() - 1]);
bool isFind = 0;
for (auto &ps : owners)
{
if (ps.GetOwnerName() == owner_name && ps.GetOwnerAge() == ownerAge)
{
ps.Push_Animal(anims[anims.size() - 1]);
isFind = 1;
break;
}
}
if (!isFind)
{
owners.push_back(pr);
}
}
if (animal_type == "fish")
{
anims.push_back(new Fish(animal_name, animalAge, breed));
Person pr(owner_name, ownerAge, anims[anims.size() - 1]);
bool isFind = 0;
for (auto &ps : owners)
{
if (ps.GetOwnerName() == owner_name && ps.GetOwnerAge() == ownerAge)
{
ps.Push_Animal(anims[anims.size() - 1]);
isFind = 1;
break;
}
}
if (!isFind)
{
owners.push_back(pr);
}
}
std::string owner_name = "";
std::string str_OwnerAge = "";
std::string animal_type = "";
std::string breed = "";
std::string animal_name = "";
std::string animal_age = "";
int ownerAge = 0;
int animalAge = 0;
}
}