Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Person.h"
- #include <cstring>
- #include <iostream>
- Person::Person(const char* name, int pnBirthPart, int pnCodePart) {
- setName (name);
- this -> pnBirthPart=pnBirthPart;
- this -> pnCodePart=pnBirthPart;
- }
- void Person::setName(const char* name) {
- memset(this->name, 0, MAX_NAME_LENGTH + 1);
- strncpy(this->name, name,MAX_NAME_LENGTH);
- }
- /*vypocet roku narozeni*/
- int Person::getYearOfBirth () const {
- int year;
- year = pnBirthPart / 10000;
- if (year < 54){
- return year+2000;
- }
- if (year >= 54){
- return year + 1900;
- }
- return year;
- }
- /*vypocet mesice narozeni*/
- int Person::getMonthOfBirth () const {
- int month;
- month = ((pnBirthPart / 100)% 100);
- if (month > 70) {
- return month -70;
- }
- if (month > 50) {
- return month -50;
- }
- if (month > 20) {
- return month -20;
- }
- return month;
- }
- /* vypocet dne narozeni*/
- int Person::getDayOfBirth () const {
- int day;
- day = pnBirthPart % 100;
- return day;
- }
- /*vypocet veku*/
- int Person::getAgeToDate (int year, int month, int day) const {
- int age;
- age = year - getYearOfBirth();
- if (month < getMonthOfBirth() || (month == getMonthOfBirth() && day < getDayOfBirth()))
- age--;
- return age;
- }
- bool Person::isValidPersonalNumber(int pnBirthPart, int pnCodePart,int month, int day) const {
- if (month==2 && day>28) {
- return false;
- }
- if (month == (1||3||5||7||8||10||12) && day >31){
- return false;
- }
- if (((pnBirthPart*10000 + pnCodePart) % 11) == 0){
- return true;
- }
- if ((pnBirthPart*1000 + pnCodePart/10) %11 ==10 && pnCodePart%10 ==0) {
- return true;
- }
- else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement