TonyVk

Untitled

May 31st, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. #include "Volonter.h"
  2.  
  3. void Zivotinja::DodajZivotinju()
  4. {
  5. cout << "1 - Pas" << endl;
  6. cout << "2 - Macka" << endl;
  7. cout << "Izaberite zivotinju:";
  8. int nZiv = 0;
  9. cin >> nZiv;
  10. while (nZiv < 1 || nZiv > 2)
  11. {
  12. cout << "Izaberite zivotinju:";
  13. cin >> nZiv;
  14. }
  15. cout << "Unesite sifru zivotinje:";
  16. string sSifra;
  17. cin >> sSifra;
  18. cout << "Unesite ime zivotinje:";
  19. string sIme;
  20. cin >> sIme;
  21. cout << "Unesite vrstu zivotinje:";
  22. cin.clear();
  23. cin.ignore(INT_MAX, '\n');
  24. string sVrsta;
  25. getline(cin, sVrsta);
  26. cout << "Unesite dob zivotinje u mjesecima:";
  27. int nDob;
  28. cin >> nDob;
  29. cout << "1 - Cipirana" << endl;
  30. cout << "2 - Nije cipirana" << endl;
  31. cout << "Izaberite status cipiranja:";
  32. int nCip;
  33. cin >> nCip;
  34. while (nCip < 1 || nCip > 2)
  35. {
  36. cout << "Izaberite status cipiranja:";
  37. cin >> nCip;
  38. }
  39. cout << "1 - Zdrava" << endl;
  40. cout << "2 - Bolesna" << endl;
  41. cout << "3 - Mrtva" << endl;
  42. cout << "Izaberite zdravstveno stanje:";
  43. int nZdrav;
  44. cin >> nZdrav;
  45. while (nZdrav < 1 || nZdrav > 3)
  46. {
  47. cout << "Izaberite zdravstveno stanje:";
  48. cin >> nZdrav;
  49. }
  50. vector<Volonter> vVolonteri;
  51. vector<Volonter>::iterator iPos;
  52. XMLDocument oXmlDocument;
  53. oXmlDocument.LoadFile("volonteri.xml");
  54. XMLElement *pRoot = oXmlDocument.FirstChildElement("volonteri");
  55. XMLElement *pChild;
  56. vVolonteri.clear();
  57. for (pChild = pRoot->FirstChildElement("volonter"); pChild != NULL; pChild = pChild->NextSiblingElement())
  58. {
  59. string sIme = pChild->Attribute("ime");
  60. string sPrezime = pChild->Attribute("prezime");
  61. string sBroj = pChild->Attribute("broj");
  62. string sKorisIme = pChild->Attribute("korisnicko_ime");
  63. string sLozinka = pChild->Attribute("lozinka");
  64. vVolonteri.push_back(Volonter(sBroj, sKorisIme, sLozinka, sIme, sPrezime));
  65. }
  66. for (iPos = vVolonteri.begin(); iPos != vVolonteri.end(); ++iPos)
  67. {
  68. cout << (iPos)->DajBroj() << " " << (iPos)->ime << " " << (iPos)->prezime << endl;
  69. }
  70. cout << "Izaberite sifru volontera:";
  71. int nVolonter;
  72. cin >> nVolonter;
  73. string sVolonter = to_string(nVolonter);
  74. int nPomocna = 0;
  75. for (iPos = vVolonteri.begin(); iPos != vVolonteri.end(); ++iPos)
  76. {
  77. if ((iPos)->DajBroj() == sVolonter)
  78. {
  79. nPomocna = 1;
  80. break;
  81. }
  82. }
  83. while (nPomocna == 0)
  84. {
  85. for (iPos = vVolonteri.begin(); iPos != vVolonteri.end(); ++iPos)
  86. {
  87. cout << (iPos)->DajBroj() << " " << (iPos)->ime << " " << (iPos)->prezime << endl;
  88. }
  89. cout << "Izaberite sifru volontera:";
  90. cin >> nVolonter;
  91. sVolonter = to_string(nVolonter);
  92. for (iPos = vVolonteri.begin(); iPos != vVolonteri.end(); ++iPos)
  93. {
  94. if ((iPos)->DajBroj() == sVolonter)
  95. {
  96. nPomocna = 1;
  97. break;
  98. }
  99. }
  100. }
  101. cout << "Unesite datum prijave u skloniste(1.1.2019.):";
  102. string sDatum;
  103. cin >> sDatum;
  104. XMLDocument xmlDoc;
  105. xmlDoc.LoadFile(XML_Zivotinje.c_str());
  106. if (nZiv == 1)
  107. {
  108. XMLElement *pRoota = xmlDoc.FirstChildElement("zivotinje");
  109. XMLElement *pRoota2 = pRoota->FirstChildElement("psi");
  110. XMLElement *pElementa = xmlDoc.NewElement("pas");
  111. pElementa->SetAttribute("sifra", sSifra.c_str());
  112. pElementa->SetAttribute("ime", sIme.c_str());
  113. pElementa->SetAttribute("vrsta", sVrsta.c_str());
  114. pElementa->SetAttribute("dob_u_mjesecima", nDob);
  115. if (nCip == 1)
  116. {
  117. pElementa->SetAttribute("informacije_o_cipiranju", "Cipirana");
  118. }
  119. else
  120. {
  121. pElementa->SetAttribute("informacije_o_cipiranju", "Nije cipirana");
  122. }
  123. if (nZdrav == 1)
  124. {
  125. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Zdrava");
  126. }
  127. else if (nZdrav == 2)
  128. {
  129. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Bolesna");
  130. }
  131. else
  132. {
  133. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Mrtva");
  134. }
  135. pElementa->SetAttribute("sifra_volontera", nVolonter);
  136. pElementa->SetAttribute("datum_prve_pojave", sDatum.c_str());
  137.  
  138. pRoota2->InsertEndChild(pElementa);
  139. }
  140. else
  141. {
  142. XMLElement *pRoota = xmlDoc.FirstChildElement("zivotinje");
  143. XMLElement *pRoota2 = pRoota->FirstChildElement("macke");
  144. XMLElement *pElementa = xmlDoc.NewElement("macka");
  145. pElementa->SetAttribute("sifra", sSifra.c_str());
  146. pElementa->SetAttribute("ime", sIme.c_str());
  147. pElementa->SetAttribute("vrsta", sVrsta.c_str());
  148. pElementa->SetAttribute("dob_u_mjesecima", nDob);
  149. if (nCip == 1)
  150. {
  151. pElementa->SetAttribute("informacije_o_cipiranju", "Cipirana");
  152. }
  153. else
  154. {
  155. pElementa->SetAttribute("informacije_o_cipiranju", "Nije cipirana");
  156. }
  157. if (nZdrav == 1)
  158. {
  159. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Zdrava");
  160. }
  161. else if (nZdrav == 2)
  162. {
  163. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Bolesna");
  164. }
  165. else
  166. {
  167. pElementa->SetAttribute("informacije_o_zdravstvenom_stanju", "Mrtva");
  168. }
  169. pElementa->SetAttribute("sifra_volontera", nVolonter);
  170. pElementa->SetAttribute("datum_prve_pojave", sDatum.c_str());
  171.  
  172. pRoota2->InsertEndChild(pElementa);
  173. }
  174. xmlDoc.SaveFile(XML_Zivotinje.c_str());
  175. cout << "Uspjesno dodana zivotinja!" << endl;
  176. Izbornik();
  177. }
Advertisement
Add Comment
Please, Sign In to add comment