Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class Item> class Wzor{
  6. static const int size = 6;
  7. Item Tab_[size];
  8. int counter_;
  9.  
  10. public:
  11. Wzor(){
  12. counter_ = 0;
  13. };
  14.  
  15.  
  16. void addA(Item dodaj){
  17. if(counter_ <= 6){
  18. Tab_[counter_] = dodaj;
  19. counter_++;
  20. }
  21. }
  22.  
  23. void deleteA(int usun){
  24. if(counter_ >= usun){
  25. counter_--;
  26. Tab_[usun] = Tab_[counter_];
  27. }
  28. }
  29. void show(){
  30. for (int a = 0; a < counter_; a++){
  31. for(int i = 0; i < counter_ - 1; i++){
  32. if(Tab_[i] < Tab_[i + 1]){
  33. Item tmp;
  34. tmp = Tab_[i];
  35. Tab_[i] = Tab_[i + 1];
  36. Tab_[i + 1] = tmp;
  37. }
  38. }
  39. }
  40. for(int i = 0; i < counter_ ++; i++){
  41. Tab_[i].show();
  42. }
  43. }
  44.  
  45. };
  46.  
  47. class Animal{
  48. string aName_;
  49. float aWeight_;
  50. int aBirth_;
  51. string aId_;
  52.  
  53. public:
  54. Animal(string aName = "0", float aWeight = 0, int aBirth = 0, string aId = "0") : aName_(aName), aWeight_(aWeight), aBirth_(aBirth), aId_(aId){};
  55.  
  56. /* Animal show(){
  57. cout << aName_ << " " << aWeight_ << " " << aBirth_ << " " << aId_ << " ";
  58. }*/
  59.  
  60. void operator = (Animal tottenham){
  61. aName_ = tottenham.aName_;
  62. aWeight_ = tottenham.aWeight_;
  63. aBirth_ = tottenham.aBirth_;
  64. aId_ = tottenham.aId_;
  65. }
  66. bool operator < (Animal tottenham){
  67. if(aBirth_ < tottenham.aBirth_){
  68. return true;
  69. }else if(aBirth_ == tottenham.aBirth_){
  70. if(aWeight_ > tottenham.aWeight_){
  71. return true;
  72. }else{
  73. return false;
  74. }
  75. }else{
  76. return false;
  77. }
  78. }
  79. };
  80.  
  81. class Building{
  82. string bName_;
  83. float aGps_;
  84. float bGps_;
  85. float bHeight_;
  86.  
  87. public:
  88. Building(string bName = "0", float aGps = 0, float bGps = 0, float bHeight = 0) : bName_(bName), aGps_(aGps), bGps_(bGps), bHeight_(bHeight){};
  89.  
  90. /*Building show(){
  91. cout << bName_ << " " << aGps_ << " " << bGps_ << " " << bHeight_ << " ";
  92. }*/
  93.  
  94. void operator = (Building tottenham){
  95. bName_ = tottenham.bName_;
  96. aGps_ = tottenham.aGps_;
  97. bGps_ = tottenham.bGps_;
  98. bHeight_ = tottenham.bHeight_;
  99. }
  100.  
  101. bool operator < (Building tottenham)
  102. {
  103. if((aGps_ + bGps_) > (tottenham.aGps_ + tottenham.bGps_ )){
  104. return true;
  105. }
  106. else{
  107. return false;
  108. }
  109. }
  110. };
  111. int main()
  112. {
  113. string Aname[6], Aid[6];
  114. float Aweight[6];
  115. int Abirth[6];
  116.  
  117. bool liczba;
  118. for(int i = 0 ; i < 4; i++){
  119. string temp;
  120. //nazwa
  121. do{
  122. liczba = 1;
  123. cin >> temp;
  124. for(int j = 0; j < temp.size(); j++){
  125. if(static_cast<int> (temp[j]) == 32){
  126. liczba = 0;
  127. break;
  128. }
  129. }
  130. }while(liczba == 0);
  131.  
  132. Aname[i] = temp;
  133. //wiek
  134. do{
  135. bool kropka = 1;
  136. liczba = 1;
  137. cin >>temp;
  138. for(int j = 0; j < temp.size(); j++){
  139. if(static_cast<int>(temp[j]) >= 48 and static_cast<int>(temp[j]) <= 57){
  140.  
  141.  
  142. }else if(static_cast<int> (temp[j]) == 46 and kropka == 0){
  143. kropka = 1;
  144. }else{
  145. liczba = 0;
  146. break;
  147. }
  148. }
  149. }while(liczba == 0);
  150. Aweight[i] = stof(temp);
  151. //rok urodzenia
  152. do{
  153. liczba = 1;
  154. cin >>temp;
  155. for(int j = 0; j < temp.size(); j++){
  156. if(static_cast<int>(temp[j]) >= 48 and static_cast<int>(temp[j]) <= 57){
  157. }
  158. }
  159. }while(liczba == 0);
  160. Abirth[i] = stoi(temp);
  161. }
  162.  
  163.  
  164. Animal a1(Aname[0], Aweight[0], Abirth[0], Aid[0]);
  165. Animal a2(Aname[1], Aweight[1], Abirth[1], Aid[1]);
  166. Animal a3(Aname[2], Aweight[2], Abirth[2], Aid[2]);
  167. Animal a4(Aname[3], Aweight[3], Abirth[3], Aid[3]);
  168.  
  169.  
  170. Wzor<Animal> animalList;
  171. animalList.addA(a1);
  172. animalList.addA(a2);
  173. animalList.addA(a3);
  174. animalList.addA(a4);
  175.  
  176.  
  177.  
  178.  
  179. string Bname[6];
  180. float Bgps[6], Bbgps[6], Bheight[6];
  181.  
  182. for(int i = 0 ; i < 4; i++){
  183. string tmp;
  184. bool liczba;
  185. bool kropka;
  186.  
  187. do{
  188. liczba = 1;
  189. cin >> tmp;
  190. for(int j = 0; j < tmp.size(); j++){
  191. if(static_cast<int> (tmp[j]) == 32){
  192. liczba = 0;
  193. break;
  194. }
  195. }
  196. }while(liczba == 0);
  197.  
  198. Bname[i] = tmp;
  199.  
  200. do{
  201. bool kropka = 0;
  202. liczba = 1;
  203. cin >>tmp;
  204. for(int j = 0; j < tmp.size(); j++){
  205. if(static_cast<int>(tmp[j]) >= 48 and static_cast<int>(tmp[j]) <= 57){
  206.  
  207. }else if(static_cast<int> (tmp[j]) == 46 and kropka == 0){
  208. kropka = 1;
  209. }else{
  210. liczba = 0;
  211. break;
  212. }
  213. }
  214. }while(liczba == 0);
  215. Bgps[i] = stof(tmp);
  216.  
  217. do{
  218. kropka = 0;
  219. liczba = 1;
  220. cin >>tmp;
  221. for(int j = 0; j < tmp.size(); j++){
  222. if(static_cast<int>(tmp[j]) >= 48 and static_cast<int>(tmp[j]) <= 57){
  223.  
  224.  
  225. }else if(static_cast<int> (tmp[j]) == 46 and kropka == 0){
  226. kropka = 1;
  227. }else{
  228. liczba = 0;
  229. break;
  230. }
  231. }
  232. }while(liczba == 0);
  233. Bgps[i] = stof(tmp);
  234.  
  235. do{
  236. kropka = 0;
  237. liczba = 1;
  238. cin >> tmp;
  239. for(int j = 0; j < tmp.size(); j++){
  240. if(static_cast<int>(tmp[j]) >= 48 and static_cast<int>(tmp[j]) <= 57){
  241.  
  242. }else if(static_cast<int> (tmp[j]) == 46 and kropka == 0){
  243. kropka = 1;
  244. }else{
  245. liczba = 0;
  246. break;
  247. }
  248. }
  249. }while(liczba == 0);
  250. Bheight[i] = stof(tmp);
  251. }
  252.  
  253.  
  254. Building b1(Bname[0], Bgps[0], Bbgps[0], Bheight[0]);
  255. Building b2(Bname[1], Bgps[1], Bbgps[1], Bheight[1]);
  256. Building b3(Bname[2], Bgps[2], Bbgps[2], Bheight[2]);
  257. Building b4(Bname[3], Bgps[3], Bbgps[3], Bheight[3]);
  258.  
  259. Wzor<Building> buildingList;
  260. buildingList.addA(b1);
  261. buildingList.addA(b2);
  262. buildingList.addA(b3);
  263. buildingList.addA(b4);
  264.  
  265. int clear;
  266. cin >> clear;
  267. Animal.deleteA(clear);
  268.  
  269.  
  270. return 0;
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement