Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #pragma once
  2.  
  3. class walidator
  4. {
  5. public:
  6. virtual bool waliduj() = 0;
  7. };
  8.  
  9. class telefonkom : public walidator
  10. {
  11. private:
  12. std::string numer;
  13. public:
  14. bool waliduj()
  15. {
  16. const char* wzorcowy = "\\+?\\d{1,3}(-| )?\\d{3}(-| )?\\d{3}(-| )?\\d{3}";
  17. std::regex wzorzec(wzorcowy);
  18. return regex_match(numer, wzorzec);
  19. }
  20. telefonkom(std::string numer)
  21. {
  22. this->numer = numer;
  23. }
  24. };
  25.  
  26. class kwota : public walidator
  27. {
  28. private:
  29. double ile;
  30. public:
  31. bool waliduj()
  32. {
  33. if (ile > 0)
  34. return 1;
  35. else return 0;
  36. }
  37. kwota(int ile)
  38. {
  39. this->ile = ile;
  40. }
  41. double &operator-(double &liczba)
  42. {
  43. ile = ile - liczba;
  44. return ile;
  45. }
  46. double &operator+(double &liczba)
  47. {
  48. ile = ile + liczba;
  49. return ile;
  50. }
  51. friend std::ostream & operator<<(std::ostream &wyjscie, const kwota &ile)
  52. {
  53. return wyjscie << ile;
  54. }
  55. };
  56.  
  57. class email : public walidator
  58. {
  59. private:
  60. std::string nazwa;
  61. public:
  62. bool waliduj()
  63. {
  64. const char* wzorcowy = "(\\w+)(\\.|_)?(\\w+)@(\\w+)(\\.(\\w+))+";
  65. std::regex wzorzec(wzorcowy);
  66. return regex_match(nazwa, wzorzec);
  67. }
  68. email(std::string numer)
  69. {
  70. this->nazwa = numer;
  71. }
  72. email();
  73. friend std::ostream & operator<<(std::ostream &wyjscie, const std::string nazwa)
  74. {
  75. return wyjscie << nazwa;
  76. }
  77. };
  78.  
  79. class telefonstac : public walidator
  80. {
  81. private:
  82. std::string numer;
  83. public:
  84. bool waliduj()
  85. {
  86. const char* wzorcowy = "\\d{2,3}(-| )?\\d{3}(-| )?\\d{3}(-| )?\\d{3}";
  87. std::regex wzorzec(wzorcowy);
  88. return regex_match(numer, wzorzec);
  89.  
  90. }
  91. telefonstac(std::string numer)
  92. {
  93. this->numer = numer;
  94. }
  95. };
  96.  
  97. class liczba_rzymska : public walidator
  98. {
  99. private:
  100. std::string liczba;
  101. public:
  102. bool waliduj()
  103. {
  104. const char* wzorcowa = "M{0,2}(C[MD]|D?C{0,3}|MCD|MD?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})";
  105. std::regex wzorzec(wzorcowa);
  106. return regex_match(liczba, wzorzec);
  107. }
  108. liczba_rzymska (std::string numer)
  109. {
  110. this->liczba = numer;
  111. }
  112. };
  113.  
  114. class nr_faxu : public walidator
  115. {
  116. private:
  117. std::string numer;
  118. public:
  119. bool waliduj()
  120. {
  121. const char* fax = "\\+?\\(?\\d{1,3}\\)?(-| )\\(?\\d+\\)?(-| )(\\d{2,}(-| )\\d{2,}|\\d+)"; //najpierw kod kraju, potem kod strefy, na koniec numer (w dwóch formatach dozwolonych)
  122. std::regex wzorzec(fax);
  123. return regex_match(numer, wzorzec);
  124. }
  125. nr_faxu(std::string numer)
  126. {
  127. this->numer = numer;
  128. }
  129. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement