Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include "Person.h"
  2. #include <cstring>
  3. #include <iostream>
  4.  
  5. Person::Person(const char* name, int pnBirthPart, int pnCodePart) {
  6.         setName (name);
  7.         this -> pnBirthPart=pnBirthPart;
  8.         this -> pnCodePart=pnBirthPart;
  9.         }
  10.  
  11. void Person::setName(const char* name) {
  12.         memset(this->name, 0, MAX_NAME_LENGTH + 1);
  13.         strncpy(this->name, name,MAX_NAME_LENGTH);
  14.     }
  15.     /*vypocet roku narozeni*/
  16.     int Person::getYearOfBirth () const {
  17.             int year;
  18.             year = pnBirthPart / 10000;
  19.  
  20.             if (year < 54){
  21.                     return year+2000;
  22.                 }
  23.  
  24.             if (year >= 54){
  25.                 return year + 1900;
  26.             }
  27.             return year;
  28.         }
  29.     /*vypocet mesice narozeni*/
  30.     int Person::getMonthOfBirth () const {
  31.         int month;
  32.         month = ((pnBirthPart / 100)% 100);
  33.         if (month > 70) {
  34.         return month -70;
  35.         }
  36.  
  37.         if (month > 50) {
  38.             return month -50;
  39.  
  40.         }
  41.  
  42.         if (month > 20) {
  43.             return month -20;
  44.         }
  45.         return month;
  46.     }
  47.     /* vypocet dne narozeni*/
  48.     int Person::getDayOfBirth () const {
  49.             int day;
  50.             day = pnBirthPart % 100;
  51.             return day;
  52.         }
  53.  
  54.     /*vypocet veku*/
  55.     int Person::getAgeToDate (int year, int month, int day) const {
  56.         int age;
  57.         age = year - getYearOfBirth();
  58.     if (month < getMonthOfBirth() || (month == getMonthOfBirth() && day < getDayOfBirth()))
  59.         age--;
  60.  
  61.                 return age;
  62.     }
  63.     bool Person::isValidPersonalNumber(int pnBirthPart, int pnCodePart,int month, int day) const {
  64.         if (month==2 && day>28) {
  65.             return false;
  66.         }
  67.  
  68.         if (month == (1||3||5||7||8||10||12) && day >31){
  69.             return false;
  70.         }
  71.  
  72.         if (((pnBirthPart*10000 + pnCodePart) % 11) == 0){
  73.             return true;
  74.         }
  75.  
  76.         if ((pnBirthPart*1000 + pnCodePart/10) %11 ==10 && pnCodePart%10 ==0) {
  77.             return  true;
  78.         }
  79.  
  80.         else {
  81.             return false;
  82.         }
  83.  
  84.  
  85.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement