Subscribe Us

Responsive Advertisement

Advertisement

credit cards

 #include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<conio.h>

struct clientInfo

{

    char firstName[32];

    char lastName[32];

    int birthDay[4];

    int age;

    char email1[51];

    int phoneType;

    char phoneNumber[4][12];

    char homeaddress[7][51];

    int livingSituation;

    int livingDuration[4];

    long long int SIN;

    int jobCategory;

    char jobDescription[50];

    int yearlyIncome[3];

    int housing;

    long long int customerId;

    char password[50];



};

struct clientInfo info;

FILE *file;

int checkName(char arr[])

{

    int ans=0;

    for(int i=0; i<strlen(arr); i++)

    {


        if(arr[i]>='0'&&arr[i]<='9')

        {


            ans=1;

        }

    }

    if(strlen(arr)>30||ans)return 0;

    return 1;


}

int getAge(int m,int year)

{

    time_t ctime=time(NULL);

    char curdate[20];

    strftime(curdate, 20, "%Y-%m-%d", localtime(&ctime));

    // printf("%s\n",curdate);

    char month[5];

    month[0]=curdate[5];

    month[1]=curdate[6];

    char yea[5];

    for(int i=0; i<4; i++)

    {


        yea[i]=curdate[i];

    }

    int mm=atoi(month);

    int yy=atoi(yea);

    int totmonth=yy*12+mm;

    int totm=year*12+m;

    totm=totmonth-totm;


    return (totm/12);



}

void getFirstName()

{

    printf("Enter first name : ");


    scanf("%s", info.firstName);

    if(checkName(info.firstName)==0)

    {


        printf("Invalid first Name : \n");

        getch();

        getFirstName();


    }



}

void getLastName()

{

    printf("Enter last name : ");


    scanf("%s", info.lastName);

    if(checkName(info.lastName)==0)

    {


        printf("Invalid first Name : \n");

        getch();

        getLastName();


    }


}

int checkAge(int age)

{


    if(age<18)return 0;

    return 1;

}

void getDateOfBirth()

{

    printf("Enter day-month-year : ");

    scanf("%d%d%d",&info.birthDay[1],&info.birthDay[2],&info.birthDay[3]);

    int ans=0;

    if(info.birthDay[1]<1||info.birthDay[1]>31)ans=1;

    if(info.birthDay[2]<1||info.birthDay[2]>12)ans=1;

    if(info.birthDay[3]<1900||info.birthDay[3]>2020)ans=1;

    if(ans)

    {


        printf("Invalid Birthday \n");

        getch();

        getDateOfBirth();

    }

    info.age=getAge(info.birthDay[2],info.birthDay[3]);

    if(checkAge(info.age)==0)

    {


        printf("Invalid age \n");

        getch();

        home();


    }


}

int checkEmail(char e[])

{


    int ans1=0;

    int ans=0;

    for(int i=0; i<strlen(e); i++)

    {


        if(e[i]=='@')ans=1;

        if(e[i]=='.')ans1=1;

    }

    if(strlen(e)>50)return 0;

    if(ans&&ans1)return 1;

    return 0;

}

void getEmail()

{


    printf("Enter your Email : ");

    scanf("%s",info.email1);

    if(checkEmail(info.email1)==0)

    {

        printf("Invalid age \n");

        getch();

        getEmail();


    }


}

void getPhoneType()

{

    int choose;

    printf("Enter Phone Tyepe : ");

    printf("\n1.HOME\n2.Work\n3.Mobile\n");

    printf("Enter Choose : ");

    scanf("%d",&choose);

    if(choose>=1&&choose<=3)

    {


        info.phoneType=choose;

    }

    else


    {


        printf("Invalid Phone type : ");

        getch();

        getPhoneType();

    }


}

int checkNumber(char arr[])

{

    int r=0;

    if(strlen(arr)!=10)return 0;

    for(int i=0; i<strlen(arr); i++)

    {


        if(arr[i]>='0'&&arr[i]<='9')continue;

        else r=1;

    }

    if(r)return 0;

    else return 1;


}

void getPhoneNumber()

{


    printf("How many number do you insert(Must between 1 to 3) : ");

    int num;

    scanf("%d",&num);

    if(num>3)

    {

        getPhoneNumber();

    }

    for(int i=1; i<=num; i++)

    {

        printf("Enter number %d : ",i);

        scanf("%s",info.phoneNumber[i]);

        if(checkNumber(info.phoneNumber[i])==0)

        {


            printf("Invalid number ");

            getch();

            getPhoneNumber();

        }


    }


}

int checkProvince(char arr[])

{

    if(strcmp(arr,"AB")==0||strcmp(arr,"BC")==0||strcmp(arr,"MB")==0||strcmp(arr,"NB")==0||strcmp(arr,"NL")==0||strcmp(arr,"NS")==0||strcmp(arr,"NT")==0||strcmp(arr,"NU")==0||strcmp(arr,"ON")==0||strcmp(arr,"PE")==0||strcmp(arr,"QC")==0||strcmp(arr,"SK")==0||strcmp(arr,"YT")==0)

    {


        return 1;

    }

    return 0;


}

void getAddress()

{


    printf("Enter Address1 : ");

    scanf("%s",info.homeaddress[1]);

    printf("Enter Address2 : ");

    scanf("%s",info.homeaddress[2]);

    printf("Enter city : ");

    scanf("%s",info.homeaddress[3]);

    printf("Enter Province : ");

    scanf("%s",info.homeaddress[4]);

    if(checkProvince(info.homeaddress[4])==0)

    {


        printf("Invalid Province\n");

        getch();

        getAddress();


    }

    printf("Enter Postal Code : ");

    scanf("%s",info.homeaddress[5]);

    if(strlen(info.homeaddress[5])!=6)

    {


        printf("Invalid postal Code \n");

        getch();

        getAddress();


    }



}

void getlivingSituation()

{

    printf("Enter you living situation : ");

    printf("\n1.Rent\n2.Own\n3.Live with parents\n4.Room or Board\n5.Other\n");

    printf("Enter choose : ");

    scanf("%d",&info.livingSituation);

    if(info.livingSituation<1||info.livingSituation>5)

    {


        info.livingSituation=1;

        printf("Invalid choose\n");

        getch();

        getlivingSituation();

    }



}

void getlivingDuration()

{

    printf("Enter Year: ");

    scanf("%d",&info.livingDuration[1]);

    printf("Enter Month : ");

    scanf("%d",&info.livingDuration[2]);

    if(info.livingDuration[2]<1||info.livingDuration[2]>12)

    {


        printf("Invalid month\n");

        getch();

        getlivingDuration();


    }


}

int checkSIN(long long int r)

{


    int cnt=0;

    int sum=0;

    while(r)

    {

        cnt++;

        int x=r%10;

        if(x<0||x>9)

        {


            sum=1;

            break;

        }

        r/=10;


    }

    if(cnt!=9||sum)return 0;

    return 1;

}

void getSIN()

{

    printf("Enter SIN : ");

    scanf("%lld",&info.SIN);

    if(checkSIN(info.SIN)==0)

    {


        printf("Invalid SIN\n");

        getch();

        getSIN();

    }


}

void getJobcategory()

{

    printf("Enter your Job category : ");

    scanf("%d",&info.jobCategory);

    if(info.jobCategory<1&&info.jobCategory>5)

    {


        printf("Invalid job Category\n");

        getch();

        getJobcategory();

    }


}

void getJobDescription()

{

    //info.jobDescription

    printf("Enter your job Description : ");

    for(int i=0; i<50; i++)

    {

        scanf("%c",&info.jobDescription[i]);

        if(info.jobDescription[i]=='\n'&&i>0)break;

    }



}

void getYearlyIncome()

{


    printf("Enter Your Personal Income : ");

    scanf("%d",&info.yearlyIncome[1]);

    printf("Enter YourOther Household income: ");

    scanf("%d",&info.yearlyIncome[2]);

    if(info.yearlyIncome[1]+info.yearlyIncome[2]<15000)

    {


        printf("Income must greater than or equal to $15000\n");

        getch();

        getYearlyIncome();

    }

}

void getHousing()

{


    printf("Enter How much do you pay for housing? : ");

    scanf("%d",&info.housing);

}

void getCustomerId()

{

     long long int mx=-1;

    info.customerId=10;


              FILE *fp;

      fp=fopen("custid.txt","r");

      fscanf(fp,"%lld",&mx);

      fclose(fp);




          mx++;

           info.customerId=mx;


          FILE *fp1;

      fp1=fopen("custid.txt","w");

      fprintf(fp1,"%lld",mx);

        fclose(fp1);


}

int checkPassword(char arr[])

{

    int len=0;

    int u=0;

    int l=0;

    int let=0;

    int num=0;

    int spe=0;

    len=strlen(arr);

    for(int i=0; i<strlen(arr); i++)

    {

        if(arr[i]>='A'&&arr[i]<='Z')u++;

        if(arr[i]>='a'&&arr[i]<='z')l++;

        if(arr[i]>='$'||arr[i]<='@'||arr[i]=='!'||arr[i]=='#'||arr[i]=='?')spe++;

        if(arr[i]<='9'&&arr[i]>='0')num++;


    }

    if(len>=8&&u&&l&&num&&spe)return 1;

    return 0;


}

void getPassword()

{

    printf("Enter a password : ");

    scanf("%s",info.password);

    if(checkPassword(info.password)==0)

    {


        printf("Not a strong passwora\n");

        getch();

        getPassword();

    }

}

void collectInfo()

{

    system("cls");


    getFirstName();


    getLastName();


    getDateOfBirth();

    getEmail();

//ok

    getPhoneType();

    getPhoneNumber();

    getAddress();

    getlivingSituation();

    getlivingDuration();

    getSIN();

  //ok

    getJobcategory();

    getJobDescription();

    getYearlyIncome();

    getHousing();

    getCustomerId();


    getPassword();






      file=fopen("Client.dat","ab+");


      fseek(file,0,SEEK_END);

      fwrite(&info,sizeof(info),1,file);

      fclose(file);


       system("cls");


        FILE *fp1;

      fp1=fopen("savepass.txt","a");

      fprintf(fp1,"%s %s %lld\n",info.email1,info.password,info.customerId);

        fclose(fp1);


          printf("Your all information here : \n");

        printf("First name : %s\n",info.firstName);

        printf("last name : %s\n",info.lastName);

        printf("Birth day : \n");

        printf("Day : %d Month : %d Year : %d\n",info.birthDay[1],info.birthDay[2],info.birthDay[3]);

        printf("Age : %d\n",info.age);

        printf("Email : %s\n",info.email1);

        printf("Phone Type : ");

        if(info.phoneType==1)

        {

             printf("HOME\n");


        }

          if(info.phoneType==2)

        {

             printf("WORK\n");


        }

                if(info.phoneType==3)

        {

              printf("MOBILE\n");


        }

        printf("Your Phone Number : %s\n",info.phoneNumber[1]);


        printf("Your Address : \n");

        printf("Address1 : %s\n",info.homeaddress[1]);

        printf("Address2 : %s\n",info.homeaddress[2]);

        printf("City : %s\n",info.homeaddress[3]);

        printf("Province : %s\n",info.homeaddress[4]);

        printf("Postal Code : %s\n",info.homeaddress[5]);

        printf("Living situation : ");

        if(info.livingSituation==1)

        {

            printf("Rent\n");

        }

       if(info.livingSituation==2)

        {

            printf("Own\n");

        }

       if(info.livingSituation==3)

        {

            printf("Live with parents\n");

        }

         if(info.livingSituation==4)

        {

            printf("Room or Board\n");

        }

        if(info.livingSituation==5) printf("Other\n");


        printf("Your living Duration : %d year %d months\n",info.livingDuration[1],info.livingDuration[2]);

        printf("Your SIN number : %lld\n",info.SIN);

        printf("Job category: category%d\n",info.jobCategory);

        printf("Job description : %s\n",info.jobDescription);

        printf("Your Income : %d\n",info.yearlyIncome[1]+info.yearlyIncome[2]);

        printf("you pay for housing : %d\n",info.housing);

        printf("Your customer ID : %lld\n",info.customerId);

        printf("Your Passward : %s\n",info.password);







}

void getCardNumber(char email[],char pass[],long long int id)

{


     char cardno[17];

     for(int i=0;i<8;i++)

     {


         cardno[i]='1';


     }

     long long int temp=id;

     int i=15;

     while(id)

     {

         int r=id%10;

         id/=10;

         cardno[i]=(char)(r+'0');

         i--;


     }

     for(int j=i;j>=8;j--)

     {

          cardno[j]='0';

     }

     //printf("%s",cardno);

     cardno[16]='\0';

             FILE *fp1;

      fp1=fopen("CreditCards.dat","a");

      fprintf(fp1,"%s %lld\n",cardno,temp);

        fclose(fp1);



}

int take=0;

 void verify()

 {

      take++;

      if(take>3)

      {


          printf("sorry You have completed 3 time wrong try\n");

          getch();

          return 0;

      }

     system("cls");

     char takeEmail[50];

     char takePass[50];

     printf("Enter email: ");

     scanf("%s",takeEmail);

     printf("Enter Passward: ");

     scanf("%s",takePass);


           int ans=0;

           long long int ansId;

               FILE *fp1;

      fp1=fopen("savepass.txt","r");


         while(1)

         {

               char Tmail[50],Tpass[50];

              long long int id;

             int x=fscanf(fp1,"%s%s%lld",Tmail,Tpass,&id);

             if(strcmp(takeEmail,Tmail)==0&&strcmp(Tpass,takePass)==0)

             {

                     ansId=id;

                    ans=1;

                    break;

             }

             if(x==EOF)break;




         }

        fclose(fp1);

       if(ans==1)

       {


           getCardNumber(takeEmail,takePass,ansId);



       }

       else

       {


             printf("does not match email or passward\n");

             getch();

             verify();

       }


 }

void home()

{


    system("cls");

    printf("Are you existing customer ? : ");

    char choose[10];

    scanf("%s",choose);

    if(strcmp(choose,"yes")==0)

    {

       take=0;

       verify();


    }

    else if(strcmp(choose,"no")==0)

    {

        collectInfo();


    }

    else

    {

        system("cls");

        printf("You enter wrong choose. Please try again");

        getch();

        home();


    }




}

int main()

{




     home();


}


Post a Comment

0 Comments