C++

C Language Banking System Curriculum design


This paper shares the curriculum design of C language banking system for your reference. The specific content is as follows

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#define MaxNum 200
#define N_P 6
typedef struct
{
 int AccountNumber[3];
 char name[20];
 char password[N_P+1];
 unsigned long amount;
 int state;
} Account;
void Load(FILE *,Account *);
void ShowMenu(int );
int MakeChoice(int );
void EnterPassword(char *);
void CreatAccount(unsigned char *,Account *,int); // The first 1 The parameters are encryption keywords, and the 2 The parameters are account serial number
int JudgePassword(char *,char *);
int decrypt(int *,unsigned char *);
void LogIn(unsigned char *,Account *,int); // The first 2 Parameters are the current number of accounts , Login and return successfully 1 , return after failure 0
int EnterAccountNumber(unsigned char *,int );
void EnterNum(char *,int );
void Operate(unsigned char *,Account *,int ,int );
void ShowSubMenu(char *);
void AdministratorMode(unsigned char *,unsigned char *,Account *,char *,int);
void ShowAdministratorMenu();
void WriteToFile(FILE *,unsigned char *,Account*,char *,int);
int main()
{
 FILE *fp;
 int i,total;
 unsigned char key[4],key_en[4];
 char administrator_password[10];
 Account *user;
 user=(Account *)malloc(sizeof(Account)*MaxNum);
 fp=fopen("bank.txt","r+");
 if(fp==NULL)
 {
  printf(" Bank database cannot be opened, press any key to end the program! \n");
  getch();
  exit(1);
 }
 fscanf(fp,"%d\n%s\n%s",&total,administrator_password,key);
 for(i=0;i<3;++i)// with key_en save key The value of the
  key_en[i]=key[i];
 key_en[0]=(key_en[0]<<3)|(key_en[0]>>(sizeof(key_en[0])*8-3));
 key_en[2]=(key_en[2]>>3)|(key_en[2]<<(sizeof(key_en[2])*8-3));
 Load(fp,user);// Store the data in an array user In the
 while(1)
 {
  system("cls");
  ShowMenu(total);
  switch(MakeChoice(4))
  {
  case 1:
   system("cls");
   LogIn(key_en,user,total);
   break;
  case 2:
   system("cls");
   CreatAccount(key_en,user,total++);
   break;
  case 3:
   system("cls");
   AdministratorMode(key,key_en,user,administrator_password,total);
   break;
  default:
   system("cls");
   WriteToFile(fp,key,user,administrator_password,total);
   return 0;
  }
 }
 return 0;
}

function.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#define MaxNum 200
#define N_P 6
// Account status  0 For the normal  1 To report the loss of  2 To freeze  3 For the pin households
typedef struct
{
 int AccountNumber[3];
 char name[20];
 char password[N_P];
 unsigned long amount;
 int state;
} Account;
void Load(FILE *,Account *);
void ShowMenu(int );
int MakeChoice(int );
void EnterPassword(char *);
void CreatAccount(unsigned char *,Account *,int); // The first 1 The parameters are encryption keywords, and the 2 The parameters are account serial number
int JudgePassword(char *,char *);
int decrypt(int *,unsigned char *);
void LogIn(unsigned char *,Account *,int); // The first 2 Parameters are the current number of accounts , Login and return successfully 1 , return after failure 0
int EnterAccountNumber(unsigned char *,int );
void EnterNum(char *,int );
void Operate(unsigned char *,Account *,int,int );
void ShowSubMenu(char *);
void AdministratorMode(unsigned char *,unsigned char *,Account *,char *,int);
void ShowAdministratorMenu();
void WriteToFile(FILE *,unsigned char *,Account*,char *,int);
void Load(FILE *fp,Account *user)
{
 int count=0;
 // Stores user information from the file into an array
 while(fscanf(fp,"\n%d%d%d %s %s %lu %d\n",&user[count].AccountNumber[0],&user[count].AccountNumber[1],\
     &user[count].AccountNumber[2],user[count].name,\
     user[count].password,&user[count].amount,&user[count].state)!=EOF)
  ++count;
}
void ShowMenu(int total)
{
 printf("**** Bank of China tobacco Plan 163-1 branch ****\n");
 printf(" At present a total of %d Name registered user *****\n",total);
 printf("1. landing *************************\n");
 printf("2. Open an account *************************\n");
 printf("3. Go into administrator mode ***************\n");
 printf("4. exit *************************\n");
}
int MakeChoice(int n)
{
 int judge;
 printf(" Please enter the 1~%d\n",n);
 scanf("%d",&judge);
 while(judge<1||judge>n)// Make sure you type yes 1~n
 {
  printf(" The input is not valid, please enter 1~%d\n",n);
  fflush(stdin);// If you don't add this, type 1 The letters cause the function to loop forever
  scanf("%d",&judge);
 }
 return judge;
}
void EnterPassword(char *password)
{
 int i;
 char t;
 for(i=0; i<N_P; ++i)
 {
  t=getch();
  if(t=='\b')// Perform a backspace delete operation
  {
   printf("\b \b");
   i-=2;
   continue;
  }
  while(t<'0'||t>'9')
   t=getch();
  password[i]=t;
  putchar('*');
 }
}
void EnterNum(char *s,int n)
{
 int i=0;
 char t;
 while(i<n)
 {
  t=getch();
  if(t=='\b')
  {
   printf("\b \b");
   --i;
   continue;
  }
  else if(t=='\r'||t=='\n')
   break;
  while(t<'0'||t>'9')
   t=getch();
  s[i]=t;
  putchar(t);
  ++i;
 }
}
int JudgePassword(char *temp_password,char *password)
{
 int i;
 for(i=0; i<N_P; ++i)
 {
  if(temp_password[i]!=password[i])
   break;
 }
 if(i==N_P)
  return 0;
 else
  return 1;
}
void CreatAccount(unsigned char *key,Account *user,int num)
{
 if(num>=MaxNum)
 {
  printf(" The number of bank users has reached the limit! \n Press any key to return to the main interface ");
  getch();
  return;
 }
 int i,flag,num_de[3];
 int num_en[3];
 char temp_password[N_P],password[N_P];
 // will num The bits of 10 The hundreds and the bits, num_de[2] Save the ones place, and so on
 for(i=0; i<3; ++i)
  num_de[i]=0;
 for(i=0; i<3; ++i)
  num_en[i]=0;
 if(num<10)
  num_de[2]=num;
 else if(num<100)
 {
  num_de[2]=num%10;
  num_de[1]=num/10;
 }
 else
 {
  for(i=0; i<3; ++i)
  {
   num_de[i]=num%10;
   num/=10;
  }
 }
 // Decomposition to complete
 while(1)
 {
  flag=0;
  printf(" Please enter user name: ");
  fflush(stdin);
  scanf("%19[^\n]",user[num].name);
  for(i=0; i<strlen(user[num].name); ++i)
  {
   if(user[num].name[i]==' ')
   {
    printf(" User names cannot contain Spaces! \n");
    flag=1;
    break;
   }
  }
  if(flag==0)
   break;
 }
 for(i=0; i<3; ++i)
  num_en[i]=num_de[i]^key[i];
 for(i=0; i<3; ++i)
  user[num].AccountNumber[i]=num_en[i];
 printf(" Your account number is: ");
 for(i=0; i<3; ++i)
  printf("%03d ",num_en[i]);
 while(1)
 {
  printf("\n Please set password: ");
  EnterPassword(password);
  printf("\n Please confirm the password again: ");
  EnterPassword(temp_password);
  if(JudgePassword(temp_password,password))
   printf("\n Two input is not equal, password setting failed! ");
  else
  {
   strcpy(user[num].password,password);
   user[num].password[N_P]='\0';
   break;
  }
 }
 user[num].amount=0;
 user[num].state=0;
 printf("\n Account created successfully! \n Press any key to return to the main menu ");
 getch();
}
int decrypt(int *num_en,unsigned char *key)
{
 int i,num,num_de[3];
 for(i=0; i<3; ++i)
  num_de[i]=num_en[i]^key[i];
 num=num_de[0]*100+num_de[1]*10+num_de[2];
 return num;
}
int EnterAccountNumber(unsigned char *key,int total)
{
 int i,num;
 int num_en[3];
 char num_en_char[3];
 while(1)// Enter account
 {
  printf(" Please enter your account number: ");
  for(i=0;i<3;++i)
  {
   EnterNum(num_en_char,3);
   num_en[i]=atoi(num_en_char);
  }
  num=decrypt(num_en,key);
  if(num>total)// if num Is greater than total Then the account input is wrong
   printf("\n Account input error! \n");
  else
   break;
 }
 return num;
}
void LogIn(unsigned char *key,Account *user,int total)
{
 int num,i;
 char password[N_P];
 num=EnterAccountNumber(key,total);
 // Determine the account status
 if(user[num].state==3)
 {
  printf(" This account has been closed and cannot be used! \n");
  printf(" Press any key to return to the operation interface ");
  getch();
  return;
 }
 else if(user[num].state==2)
 {
  printf(" The account entered the wrong number of password 3 Time, already frozen! \n Please enter administrator mode to remove the exception! \n");
  printf(" Press any key to return to the operation interface ");
  getch();
  return;
 }
 // Determine the end
 i=0;
 while(1)// Enter the password
 {
  printf("\n Please enter your password: ");
  EnterPassword(password);
  if(JudgePassword(password,user[num].password)&&(++i<3))
   printf("\n The password is incorrect and you still have %d Second chance \n",3-i);
  else if(i>=3)
  {
   user[num].state=2;
   printf("\n Too many password errors and the account has been frozen !\n");
   printf(" You will soon return to the main screen  ");
   for(i=0; i<3; ++i)
   {
    printf("%d",i);
    Sleep(1000);
    printf("\b");
   }
   return ;
  }
  else
  {
   printf(" Login successful! \n");
   break;
  }
 }
 Operate(key,user,num,total);
}
void ShowSubMenu(char *name)
{
 printf("**** welcome %s Log in the bank ********\n",name);
 printf("1. deposit *************************\n");
 printf("2. withdrawals *************************\n");
 printf("3. The query *************************\n");
 printf("4. transfer *************************\n");
 printf("5. Report the loss of *************************\n");
 printf("6. Pin households *************************\n");
 printf("7. To close *************************\n");
 printf("8. Back to the main menu *******************\n");
}
void Operate(unsigned char *key,Account *user,int num,int total)
{
 int i,num_t;
 unsigned long amount_t,max=1;
 char password[N_P],temp_password[N_P],amount_judge[6];
 for(i=0; i<(sizeof(unsigned long)*8-1); ++i) // Calculate the maximum deposit max
  max*=2;
 while(1)
 {
  system("cls");
  ShowSubMenu(user[num].name);
  switch(MakeChoice(8))
  {
  case 1:
   system("cls");
   while(1)
   {
    printf(" Please enter the deposit amount: ");
    for(i=0;i<6;++i)
     amount_judge[i]='\0';
    EnterNum(amount_judge,5);
    amount_t=atol(amount_judge);
    if(amount_t>99999)
     printf("\n The amount of each deposit is 0~99999 Yuan, deposit failure! \n");
    else if(amount_t>=max-user[num].amount)
     printf(" If the total amount exceeds the limit, the deposit fails! \n");
    else
    {
     user[num].amount+=amount_t;
     printf("\n Successful deposit! Press any key to return to the operation interface ");
     getch();
     system("cls");
     break;
    }
   }
   break;
  case 2:
   system("cls");
   if(user[num].state==1)
   {
    printf(" The account has been reported loss, unable to perform the withdrawal operation! \n");
    printf(" Press any key to return to the operation interface ");
    getch();
    break;
   }
   while(1)
   {
    printf(" Please enter the withdrawal amount: ");
    for(i=0;i<6;++i)
     amount_judge[i]='\0';
    EnterNum(amount_judge,5);
    amount_t=atol(amount_judge);
    if(amount_t>99999)
     printf("\n The amount of each deposit is 0~99999 Yuan, deposit failure! \n");
    else if(amount_t>user[num].amount)
     printf("\n The account balance is insufficient, the withdrawal fails !\n");
    else
    {
     user[num].amount-=amount_t;
     printf("\n Successful withdrawal! Press any key to return to the operation interface ");
     getch();
     system("cls");
     break;
    }
   }
   break;
  case 3:
   system("cls");
   printf(" User name: %s",user[num].name);
   printf(" Account balance: %lu\n",user[num].amount);
   printf(" Account status: ");
   if(user[num].state==1)
    printf(" Have report the loss of \n");
   else
    printf(" normal \n");
   printf(" Press any key to return to the operation interface ");
   getch();
   system("cls");
   break;
  case 4:
   system("cls");
   if(user[num].state==1)
   {
    printf(" The loss of the account has been reported and the transfer operation cannot be carried out! \n");
    printf(" Press any key to return to the operation interface ");
    getch();
    break;
   }
   num_t=EnterAccountNumber(key,total);
   while(1)
   {
    printf(" Please enter the transfer amount: ");
    for(i=0;i<6;++i)
     amount_judge[i]='\0';
    EnterNum(amount_judge,5);
    amount_t=atol(amount_judge);
    if(amount_t>99999)
     printf("\n The amount of each deposit is 0~99999 Yuan, deposit failure! \n");
    else if(amount_t>user[num].amount)
     printf(" Insufficient amount in the account, the transfer failed !\n");
    else if(amount_t>=max-user[num_t].amount)
     printf("\n The total amount of the other party exceeds the upper limit, the transfer fails! \n");
    else
    {
     user[num].amount-=amount_t;
     user[num_t].amount+=amount_t;
     printf("\n Transfer successful! Press any key to return to the operation interface ");
     getch();
     system("cls");
     break;
    }
   }
   break;
  case 5:
   system("cls");
   printf(" Are you sure you want to report the loss? \n");
   printf("1. determine  2. cancel \n");
   if(MakeChoice(2)==1)
   {
    user[num].state=1;
    printf(" Loss reporting successful! \n Press any key to return to the main interface ");
    getch();
   }
   system("cls");
   break;
  case 6:
   system("cls");
   printf(" Are you sure you want to close your account? After closing the account, all functions will be impossible to achieve, the deposit in the account will be frozen! \n");
   printf("1. determine  2. cancel \n");
   if(MakeChoice(2)==1)
   {
    user[num].state=3;
    printf(" Close account successfully! \n Press any key to return to the main interface ");
    getch();
    system("cls");
    return;
   }
   else
    break;
  case 7:
   system("cls");
   while(1)
   {
    printf("\n Please enter the original password: ");
    EnterPassword(password);
    if(JudgePassword(password,user[num].password))
     printf("\n Error in original password! \n");
    else
     break;
   }
   while(1)
   {
    printf("\n Please enter your new password: ");
    EnterPassword(password);
    printf("\n Please confirm the password again: ");
    EnterPassword(temp_password);
    if(JudgePassword(temp_password,password))
     printf("\n Two input is not equal, password setting failed! ");
    else
    {
     strcpy(user[num].password,password);
     break;
    }
   }
   printf("\n Password changed successfully! \n Press any key to return to the operation interface ");
   getch();
   system("cls");
   break;
  default:
   return;
  }
 }
}
void AdministratorMode(unsigned char *key_orig,unsigned char *key,Account *user,char *administrator_password,int total)
{
 int num;
 char password[N_P],temp_password[N_P];
 while(1)// Enter the password
 {
  printf(" Please enter the administrator password: ");
  EnterPassword(password);
  if(JudgePassword(password,administrator_password))
   printf(" Wrong password! \n");
  else
   break;
 }
 printf("\n Login successful! Press any key to continue ");
 getch();
 while(1)
 {
  system("cls");
  ShowAdministratorMenu();
  switch(MakeChoice(6))
  {
  case 1:
   system("cls");
   num=EnterAccountNumber(key,total);
   printf(" Please set password: ");
   EnterPassword(password);
   printf(" The password you set is: ");
   puts(user[num].password);
   printf("\n Press any key to return to the operation interface ");
   getch();
   break;
  case 2:
   system("cls");
   num=EnterAccountNumber(key,total);
   printf(" Are you sure you want to cancel this user's loss reporting status? \n");
   printf("1. determine  2. cancel \n");
   if(MakeChoice(2)==1)
   {
    user[num].state=0;
    printf(" The loss reporting has been successfully relieved! \n Press any key to return to the main interface ");
    getch();
   }
   break;
  case 3:
   system("cls");
   num=EnterAccountNumber(key,total);
   printf("\n Are you sure you want to lift this user's freeze? \n");
   printf("1. determine  2. cancel \n");
   if(MakeChoice(2)==1)
   {
    user[num].state=0;
    printf(" Lift the freeze! \n Press any key to return to the main interface ");
    getch();
   }
   break;
  case 4:
   system("cls");
   while(1)
   {
    printf(" Please enter your new password: ");
    EnterPassword(password);
    printf("\n Please confirm the password again: ");
    EnterPassword(temp_password);
    if(JudgePassword(temp_password,password))
     printf("\n Two input is not equal, password setting failed! \n");
    else
    {
     strcpy(administrator_password,password);
     break;
    }
   }
   printf("\n Administrator password changed successfully! \n Press any key to return to the operation interface ");
   getch();
   break;
  case 5:
   system("cls");
   printf(" The current account generation keyword is" %s All previously created accounts will not be opened after the change! \n",key_orig);
   printf(" Are you sure you want to change the account generation keyword? \n");
   printf("1. determine  2. cancel \n");
   if(MakeChoice(2)==1)
   {
    printf(" Please enter a new keyword: ");
    scanf("%3s",key_orig);
    printf(" The current keyword has been changed to" %s " \n Press any key to return to the operation interface ",key_orig);
    getch();
   }
   break;
  default:
   return;
  }
 }
}
void ShowAdministratorMenu()
{
 printf("**** Bank of China tobacco Plan 163-1 branch ****\n");
 printf("********** Administrator mode ***********\n");
 printf("1. Change user password *****************\n");
 printf("2. Cancel the report the loss of *********************\n");
 printf("3. Remove freeze *********************\n");
 printf("4. Change administrator password ***************\n");
 printf("5. Modify the account generation keywords ***********\n");
 printf("6. Return to main interface *******************\n");
}
void WriteToFile(FILE *fp,unsigned char *key,Account *user,char *administrator_password,int total)
{
 int i,j;
 rewind(fp);
 fprintf(fp,"%d\n%6s\n%3s\n",total,administrator_password,key);
 for(i=0; i<total; ++i)
 {
  for(j=0; j<3; ++j)
   fprintf(fp,"%03d ",user[i].AccountNumber[j]);
  fprintf(fp,"%s %6s %lu %d\n",user[i].name,user[i].password,\
    user[i].amount,user[i].state);
 }
 fclose(fp);
}