-
Notifications
You must be signed in to change notification settings - Fork 0
/
reading2.cpp
106 lines (98 loc) · 3 KB
/
reading2.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
#include"FactMethod.cpp"
int main(){
std::vector<Animal*> anims;
std::vector<Person> owners;
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 animal_breed = "";
std::string animalAgeStr = "";
std::string animal_name = "";
int ownerAge;
int animalAge;
std::string check = "";
while (!file.eof())
{
std::getline(file,check);
std::istringstream istr(check);
istr>>owner_name>>str_OwnerAge>>animal_type>>animal_name>>animalAgeStr>>animal_breed;
ownerAge = stoi(str_OwnerAge);
animalAge = stoi(animalAgeStr);
if (animal_type == "cat")
{
anims.push_back(Animal::createAnimal(Cat_ID,animal_name,animalAge,animal_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(Animal::createAnimal(Dog_ID,animal_name,animalAge,animal_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(Animal::createAnimal(Fish_ID,animal_name,animalAge,animal_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 = "";
int ownerAge = 0;
int animalAge = 0;
}
for(int i=0; i<owners.size(); i++){
std::cout<<owners[i];
}
}