Advertisement
Guest User

Untitled

a guest
Dec 26th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. void poprawnosc(string pesel, int &a)
  9. {
  10. a=0;
  11. if(pesel.length()==11)
  12. {
  13. for(int i=0; i<pesel.length();i++)
  14. {
  15. if(isdigit(pesel[i]) != 0)
  16. a++;
  17. }
  18. }else;
  19. if(a!=11)
  20. cout<<"Podano bledny numer PESEL";
  21.  
  22.  
  23. }
  24.  
  25. int data(string pesel)
  26. {
  27. string rok = pesel.substr(0,2);
  28. string miesiac = pesel.substr(2,2);
  29. string dzien = pesel.substr(4,2);
  30. cout<<"Data urodzenia: "<<dzien<<"."<<miesiac<<"."<<rok<<endl;
  31.  
  32.  
  33. }
  34.  
  35. int year(string pesel)
  36. {
  37. int a=10* pesel[0];
  38. cout<<pesel[0]<<endl;
  39. cout<<a;
  40. int rok=10*pesel[0]+pesel[1];
  41. int miesiac=10*pesel[2]+pesel[3];
  42. if (miesiac > 80 && miesiac < 93)
  43. {
  44. rok += 1800;
  45. }
  46. else if (miesiac > 0 && miesiac < 13)
  47. {
  48. rok += 1900;
  49. }
  50. else if (miesiac > 20 && miesiac < 33)
  51. {
  52. rok += 2000;
  53. }
  54. else if (miesiac > 40 && miesiac < 53)
  55. {
  56. rok += 2100;
  57. }
  58. else if (miesiac > 60 && miesiac < 73)
  59. {
  60. rok += 2200;
  61. }
  62. return rok;
  63. }
  64.  
  65. int month(string pesel)
  66. {
  67. int miesiac=10*pesel[2] +pesel[3];
  68. if (miesiac > 80 && miesiac < 93)
  69. {
  70. miesiac -= 80;
  71. }
  72. else if (miesiac > 20 && miesiac < 33)
  73. {
  74. miesiac -= 20;
  75. }
  76. else if (miesiac > 40 && miesiac < 53)
  77. {
  78. miesiac -= 40;
  79. }
  80. else if (miesiac > 60 && miesiac < 73)
  81. {
  82. miesiac -= 60;
  83. }
  84. if(miesiac > 0 && miesiac <13)
  85. {
  86. cout<<"Poprawny miesiac!"<<endl;
  87. }cout<<"Bledny miesiac!"<<endl;
  88.  
  89. }
  90.  
  91. void plec(string pesel)
  92. {
  93. cout<<"Plec: ";
  94. if(pesel[9]%2==0)
  95. {
  96. cout<<"kobieta"<<endl;}
  97. else cout<<"mezczyzna"<<endl;
  98. }
  99.  
  100. int poprawnosc(string pesel)
  101. {
  102. int rok=pesel[0]&&pesel[1];
  103. cout<<rok;
  104. }
  105. int kontrola(string pesel)
  106. {
  107. int i=0;
  108. //1×a + 3×b + 7×c + 9×d + 1×e + 3×f + 7×g + 9×h + 1×i + 3×j + 1×k
  109. int a=1*pesel[0]+3*pesel[1]+7*pesel[2]+9*pesel[3]+1*pesel[4]+3*pesel[5]+7*pesel[6]+9*pesel[7]+1*pesel[8]+3*pesel[9]+1*pesel[10];
  110. if(a%10==0)cout<<"PESEL zgodny z suma kontrolna."<<endl;
  111. else cout<<"PESEL niezgodny z suma kontrolna!"<<endl;
  112.  
  113. }
  114. int main()
  115. {
  116. int a,m=0;
  117. string pesel;
  118. cout<<"Podaj numer PESEL: ";
  119. getline(cin, pesel);
  120. poprawnosc(pesel,a);
  121. if(a==11)
  122. {
  123. year(pesel);
  124. month(pesel);
  125. data(pesel);
  126. plec(pesel);
  127. kontrola(pesel);
  128. }
  129.  
  130.  
  131. return( 0 );
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement