-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperFunctions.cpp
143 lines (128 loc) · 5.19 KB
/
HelperFunctions.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include"HelperFunctions.h"
bool HelperFunctions::isLetter(char x)//Ïðîâåðÿâà äàëè ñèìâîëúò å ìàëêà ëàòèíñêà áóêâà.
{
return x >= 'a' && x <= 'z';
}
bool HelperFunctions::isCorrectName(std::string name)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåíî èìåòî íà äèíîçàâúðà.
{
//1 èìå, çàïî÷âàùî ñ ãëàâíà ëàòèíñêà áóêâà, ïîñëåäâàíà îò ìàëêè ëàòèíñêè áóêâè.
bool flag = true;
if (name[0] >= 'A' && name[0] <= 'Z')
{
for (size_t i = 1; i < name.size(); i++)
{
if (isLetter(name[i])) flag = true;
else { flag = false; break; }
}
return flag;
}
else return false;
}
bool HelperFunctions::isCorrectGender(std::string gender)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí ïîëà.
{
return (gender.compare("male") == 0 || gender.compare("female") == 0);
}
bool HelperFunctions::isCorrectEra(std::string era)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåíà åðàòà.
{
return (era.compare("Triassic") == 0 || era.compare("Cretaceous") == 0 || era.compare("Jura") == 0);
}
bool HelperFunctions::isCorrectOrder(std::string order)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí ðàçðåäúò íà äèíîçàâúðà.
{
return (order.compare("herbivorous") == 0 || order.compare("carnivorous") == 0 ||
order.compare("flying") == 0 || order.compare("aqueous") == 0);
}
bool HelperFunctions::isCorrectSpecies(std::string species)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí âèäúò íà äèíîçàâúðà.
{
return (species.compare("Plesiosaur") == 0 || species.compare("Brontosaurus") == 0
|| species.compare("Tyrannosaur") == 0 || species.compare("Pterosaur") ==0);
}
bool HelperFunctions::isCorrectFood(std::string food)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåíà õðàíàòà íà äèíîçàâúðà.
{
return (food.compare("grass") == 0 || food.compare("meat") == 0 || food.compare("fish") == 0);
}
bool HelperFunctions::isCorrectAnimal(const Dinosaur& other)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí äèíàçàâúðà.
{
return isCorrectName(other.getName()) && isCorrectGender(other.getGender()) && isCorrectEra(other.getEra())
&& isCorrectOrder(other.getOrder()) && isCorrectSpecies(other.getSpecies()) && isCorrectFood(other.getFood());
}
bool HelperFunctions::isCorrectSize(std::string size)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí ðàçìåðúò íà êëåòêàòà.
{
return (size.compare("small") == 0 || size.compare("medium") == 0 || size.compare("large") == 0);
}
bool HelperFunctions::isCorrectClimate(std::string climate)//Ïðîâåðÿâà äàëè êîðåêòíî å âúâåäåí êëèìàòúò íà êëåòêàòà.
{
return (climate.compare("dry") == 0 || climate.compare("air") == 0
|| climate.compare("water") == 0);
}
bool HelperFunctions::isCorrectCageEmployee(const Cage& other)
{
/*Ïðîâåðÿâà äàëè å êîðåêòíî ñúîòíîøåíèåòî æèâîòíè â êëåòêàòà è áðîé íà ñëóæèòåëèòå â êëåòêàòà êàòî ñå èìà ïðåäâèä, ÷å
çà 1 æèâîòíî ñà íåîáõîäèìè 2 ÷îâåêà, çà 2æ. - 4÷., çà 3æ. - 5÷., çà 4æ. - 6÷. è òàêà äî 10æ. - 12÷.*/
if (other.getAnimals().size() == 0)
{
return other.getCountEmp() == 0;
}
else if (other.getAnimals().size() == 1)
{
return other.getCountEmp() == 2;
}
else if (other.getAnimals().size() >= 2 && other.getAnimals().size() <= 10)
{
return (other.getCountEmp() == other.getAnimals().size() + 2);
}
else return false;
}
bool HelperFunctions::isCorrectCageAnimal(const Cage& other, std::vector<Dinosaur>animals)
{
/*Ïðîâåðÿâà äàëè å êîðåêòíî ñúîòíîøåíèåòî ðàçìåð íà êëåòêàòà è áðîé íà æèâîòíèòå â êëåòêàòà êàòî ñå èìà ïðåäâèä, ÷å
â ìàëêà êëåòêà ìîæå äà èìà íàé-ìíîãî åäíî æèâîòíî, â ñðåäíà - íàé-ìíîãî òðè, à â ãîëÿìà - íàé-ìíîãî 10.*/
if (other.getSize() == "small")
{
return (animals.size() == 0);
}
else if (other.getSize() == "medium")
{
return(animals.size() >= 0 && animals.size() < 3);
}
else if (other.getSize() == "large")
{
return(animals.size() >= 0 && animals.size() < 10);
}
else return false;
}
bool HelperFunctions::isCorrectClimateAnimal(const std::string& climate, const Dinosaur& animal)
{
/*Ïðîâåðÿâà äàëè å êîðåêòíî ñúîòíîøåíèåòî êëèìàò íà êëåòêàòà è âèä íà æèâîòíèòå â êëåòêàòà êàòî ñå èìà ïðåäâèä, ÷å
àêî êëèìàòúò å ñóõîçåìåí, òî â òàçè êëåòêà ìîãàò äà æèâåÿò 2 âèäà - Áðîíòîçàâúð è Òèðàíîçàâúð,
àêî êëèìàòúò å âúçäóøåí, òî â òàçè êëåòêà ìîæå äà æèâåå ñàìî Ïòèöåçàâúð,
àêî êëèìÿòúò å âîäåí, òî â òàçè êëåòêà ìîæå äà æèâåå ñàìî Ïëåçèîçàâúð.*/
if (climate == "dry")
{
return (animal.getSpecies() == "Brontosaurus" || animal.getSpecies() == "Tyrannosaur");
}
else if (climate == "air")
{
return (animal.getSpecies() == "Pterosaur");
}
else if (climate == "water")
{
return (animal.getSpecies() == "Plesiosaur");
}
else return false;
}
bool HelperFunctions::isCorrectData(size_t number, std::vector<size_t>helper)
{
/*Ïðîâåðÿâà ïî äàäåíî ÷èñëî, äàëè òîâà ÷èñëî ñå ñðåùà â ìàñèâà îò ÷èñëà.
Èçïîëçâà ñå â "main.cpp", çà èçáèðàíå íà êîðåêòíà êëåòêà îò ìíîæåñòâî îò êëåòêè.*/
bool flag = false;
for (size_t i = 0; i < helper.size(); i++)
{
if (helper[i] == (number - 1)) flag = true;//number å íîìåðúò íà êëåòêàòà, (number-1) å ïîçèöèÿòà â ìàñèâà.
}
return flag;
}
bool HelperFunctions::isCorrectQuantityInWarehouse(const Warehouse& other)
{
//Ïðîâåðÿâà äàëè å êîðåêòíî êîëè÷åñòâîòî õðàíà â ñêëàäà.
return (other.getQuantityGrass() >= 0 && other.getQuantityMeat() >= 0 && other.getQuantityFish() >= 0);
}