Tomi D

Tomi D

  • NA
  • 1
  • 764

Instruction Case for 3 programs

Jun 1 2015 2:28 AM
Welcome! Can anyone give me combine these three programs in order to be able to pick their own between them using the case. Please write code in the comments. Here are the 3 programs:
 
#include <stdio.h>
#include <stdlib.h>

short PESEL[12];
int valid = 0;

int getBirthYear() {
int year;
int month;
year = 10 * PESEL[0];
year += PESEL[1];
month = 10 * PESEL[2];
month += PESEL[3];
if (month > 80 && month < 93) {
year += 1800;
}
else if (month > 0 && month < 13) {
year += 1900;
}
else if (month > 20 && month < 33) {
year += 2000;
}
else if (month > 40 && month < 53) {
year += 2100;
}
else if (month > 60 && month < 73) {
year += 2200;
}
return year;
}

int getBirthMonth() {
int month;
month = 10 * PESEL[2];
month += PESEL[3];
if (month > 80 && month < 93) {
month -= 80;
}
else if (month > 20 && month < 33) {
month -= 20;
}
else if (month > 40 && month < 53) {
month -= 40;
}
else if (month > 60 && month < 73) {
month -= 60;
}
return month;
}

int getBirthDay() {
int day;
day = 10 * PESEL[4];
day += PESEL[5];
return day;
}

char* getSex() {
if (valid) {
if (PESEL[9] % 2 == 1) {
return "Mezczyzny";
}
else {
return "Kobiety";
}
}
else {
return "Bóg wie jeden kto ;)";
}
}

int checkSum() {
int sum = 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];
sum %= 10;
sum = 10 - sum;
sum %= 10;

if (sum == PESEL[10]) {
return 1;
}
else {
return 0;
}
}

int checkMonth() {
int month = getBirthMonth();
if (month > 0 && month < 13) {
return 1;
}
else {
return 0;
}
}

int checkDay() {
int year = getBirthYear();
int month = getBirthMonth();
int day = getBirthDay();
if ((day >0 && day < 32) &&
(month == 1 || month == 3 || month == 5 ||
month == 7 || month == 8 || month == 10 ||
month == 12)) {
return 1;
}
else if ((day >0 && day < 31) &&
(month == 4 || month == 6 || month == 9 ||
month == 11)) {
return 1;
}
else if ((day >0 && day < 30 && leapYear(year)) ||
(day >0 && day < 29 && !leapYear(year))) {
return 1;
}
else {
return 0;
}
}

int leapYear(int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
else
return 0;
}

void PeselValidator(char *PESELNumber) {
int i;

if (strlen(PESELNumber) != 11){
valid = 0;
}
else {
for (i = 0; i < 11; i++){
PESEL[i] = PESELNumber[i] - 48;
}
if (checkSum() && checkMonth() && checkDay()) {
valid = 1;
}
else {
valid = 0;
}
}
}

void main(void)
{
char PESEL[11];

printf("Podaj numer PESEL\n");
scanf("%s", PESEL);

PeselValidator(PESEL);

if (valid == 1) {
printf("Numer: %s jest prawidlowy dla %s\n",PESEL, getSex());
printf("Osoba ta urodzona jest w dniu: %d, w miseiacu: %d, w roku: %d \n",getBirthDay(), getBirthMonth(), getBirthYear());
}
else {
printf("Numer PESEL jest nieprawidlowy\n");
}
getch(0);
}


second:

#include <stdio.h>

char *letterValues = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int letterValuesLen = 36;

int getLetterValue(char letter)
{
int i;
for (i=0; i<letterValuesLen; i++)
{
if (letter == letterValues[i])
{
return i;
}
}
return -1;
}

int main()
{
char id[100];
int i=0;
int checkSum;

printf("Prosze o podanie numeru dowodu osobistego, NALEZY PODAC DUZE LITERY!\n");
scanf("%s", id);

if (strlen(id) != 9)
{
printf("Nieprawidlowa dlugosc numeru\n");
return -1;
}


for (i=0; i<3; i++)
{
if (getLetterValue(id[i]) < 10)
{
printf("Nieprawidlowa seria dowodu\n");
return -1;
}
}
for (i=3; i<9; i++)
{
if (getLetterValue(id[i]) < 0 || getLetterValue(id[i]) > 9)
{
printf("Nieprawidlowy numer dowodu\n");
return -1;
}
}


checkSum = 7 * getLetterValue(id[0]);
checkSum += 3 * getLetterValue(id[1]);
checkSum += 1 * getLetterValue(id[2]);
checkSum += 7 * getLetterValue(id[4]);
checkSum += 3 * getLetterValue(id[5]);
checkSum += 1 * getLetterValue(id[6]);
checkSum += 7 * getLetterValue(id[7]);
checkSum += 3 * getLetterValue(id[8]);
checkSum %= 10;
if (checkSum != getLetterValue(id[3]))
{
printf("Podany numer dowodu jest niepoprawny\n");
}
else
{
printf("Podany numer dowodu jest poprawny\n");
}

getch(0);
}

third:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include<conio.h>

char DoubleArray[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};


int luhnCheckDigit(char *number) {
int i;
int sum = 0;
int length = strlen(number);

for (i=2; i<=length; i++) {
if (i%2 != 0) {
sum += number[length - i] - 48;
} else {
sum += DoubleArray[number[length - i] - 48];
}
}

sum %= 10;
sum = 10 - sum;
sum %= 10;

return sum;
}

int luhnCheck(char *number) {
int i;
int sum = 0;
int length = strlen(number);

for (i=1; i<=length; i++) {
if (i%2 != 0) {
sum += number[length - i] - 48;
} else {
sum += DoubleArray[number[length - i] - 48];
}
}

if (sum % 10 == 0) {
return 1;
}
return 0;
}

int main(void)
{
char number[1000];

printf("Podaj numer do sprawdzenia\n");
scanf("%s", number);

if (luhnCheck(number))
{
printf("Numer jest prawidlowy\n");
}
else
{
printf("Numer jest nieprawidlowy\n");
}

getch(0);
}

I need this project for tommorow! ;)
 

Answers (1)