Hello, I'm Chen Meng~
After a few months, I met you again. It's close to the end of the term. I'm really busy recently.
Today, I want to share with you the ATM code. Although there is a lot of code, it is not difficult. If you want to understand the soul of C language - pointer, you may be disappointed. My article is suitable for novices. How to learn function modularization? Each function module is independent and interrelated.
If you don't have much to say, please look at the following:
(friendly note: please first create a "bank" folder in disk D, and then create a text document "account" in the "bank" folder to save data)
1. Function header file
There are not many header files in the whole code, and the core stdio H there must be. I won't say much about this.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <process.h> #include <math.h> #include<conio. h> / / getch() function header file
About process H header file to ensure exit(0) exits the program
string.h beginners should know that this is about the header file of string.
2. Structure and function declaration
As far as I am concerned, there are many functions to be used in this ATM program. First, copy and paste all the function declarations here into this article.
int init();//initialization void menu_welcome();//Welcome interface void menu_main();//Main control interface void addAccount();//New account opening void menu_addAccount(); //New account opening interface directory void menu_addAccountDetail(); //Details of depositor to be filled in for new account opening void updateAccount();//Modify account opening information void copystr(char str1[],char str2[],int len);//Assign the modified information to the original data (i.e. overwrite the original depositor information) void menu_updateAccount();//Interface directory for modifying account opening information void queryAccount();//Query account opening information void quit();//sign out void quit2();//Save the account opening information but do not exit int save(int accountCard);//Save without exiting void login();//ATM login void menu_login();//Login menu void ATM_login();//ATM authentication, such as entering a password void change_password();//Depositor changes password, non bank teller (bank teller is used to modify depositor information) void help();//ATM help void help2();//ATM help int ATM_catalog(int accountCard);//ATM function menu int depoist(int accountCard);//deposit int withdrawal(int accountCard);//withdraw money int find_money(int accountCard);//Check the balance int transfer_accounts(int accountCard);//transfer accounts void admin_login();//Administrator (i.e. bank teller) login void menu_admin();//Specific function information of bank administrator login void admin();//Specific operations of bank staff void finish();//End ATM int finish2(int accountCard);//Select the page that appears when the depositor completes the transaction and exits void save_password();//The depositor modifies the password and saves it in the file int save_transfer(int accountCard);//Save the transfer information and save it in the file
Although there are so many functions, in fact, several functions are similar, such as saving file information. There are several functions (mostly similar or the same) in this program
The structure, the representative of the soul of ATM, officially appeared!!
struct BankAccount1 { int accountCard;//Account card number char accountName[11];//End tag '/ 0' after account name string char mobile[12];//phone number char cardId[19];//ID char password[7];//password double money;// balance } bankAccounts[46],bac={0,'\0','\0','\0','\0',0.0};
In the ATM teller machine program, it contains six parts: card number, name, telephone number, ID number, password and balance. I believe you can write more, such as depositors' home address writing structure.
3. Relevant codes of bank account opening function
In this regard, to log in to the ATM, you must first register the information before you choose to log in to the ATM to perform functions such as withdrawal, deposit and balance query.
Here, I'll post the relevant codes for your reference!
void menu_addAccountDetail(){ puts("\n Please enter the new depositor account opening information:\n"); puts("Name ID number (18 bits) Mobile phone number (11 digits) Initial balance (100)-20000)\n"); } void addAccount() { //When the depositor opens a new account, the menu is displayed char ch1; char digitFlag='1';//The ID number tag '0' is not a number‘ 1 'all numbers int i=0; while(1) { menu_addAccount(); //Control input can only be '0' and '1' do{ ch1=getchar(); }while(ch1<'0'||ch1>'1'); if(ch1=='0') break; //Jump out of the while (1) loop and return to the bank staff menu //Execute new account opening of depositor while(1) { menu_addAccountDetail(); //Enter the depositor's information //Name ID number mobile phone number initial balance scanf("%s%s%s%lf",&bac.accountName,&bac.cardId,&bac.mobile,&bac.money); printf("\n Depositor's name and ID number phone number Initial balance\n"); printf("%s %s %s %lf\n",bac.accountName,bac.cardId,bac.mobile,bac.money); // Verify whether the entered name information is legal if(strlen(bac.accountName)<1||strlen(bac.accountName)>10) { printf("The length of the account name must be between 1 and 10, please re-enter!\n"); system("pause"); system("cls"); continue; } // ID card No. // The ID number must be 17 digits. if(strlen(bac.cardId)!=18) { printf("The ID number is only 18 bits, please re input!\n"); system("pause"); system("cls"); continue; } //The first 18 digits of ID number must be numeric. //ID number is all digital by digital mark. // '0' is not a number‘ 1 'all numbers digitFlag='1'; for(i=0;i<18;i++) { if(bac.cardId[i]<'0'||bac.cardId[i]>'9') digitFlag='0'; } //If the ID number is not a number, go back to re input. // All numbers, continue; if(digitFlag=='0') { printf("ID number 18 must be number, please re input!\n"); system("pause"); system("cls"); continue; } //If the mobile phone number is not 11 digits, go back and re-enter // Is 11, continue to execute; if(strlen(bac.mobile)!=11) { printf("The length of mobile phone number can only be 11 digits, please re-enter!\n"); system("pause"); system("cls"); continue; } //The default phone number is all numbers digitFlag='1'; //After judging that the mobile phone is 11 digits, judge whether the mobile phone number is all digits for(i=0;i<11;i++) { if(bac.mobile[i]<'0'||bac.mobile[i]>'9') digitFlag='0'; } //If the mobile phone number is not a number, go back and re-enter; // All numbers, continue; if(digitFlag=='0') { printf("Mobile phone number must be a number, please re-enter!\n"); system("pause"); system("cls"); continue; } //Judge whether the initial balance is 50 yuan, if not, return to re-enter; // Yes, continue; if(bac.money<100||bac.money>20000) { printf("The initial balance must be greater than 100 yuan or less than 20000 yuan, please re-enter!\n"); system("pause"); system("cls"); continue; } if(fmod(bac.money,100)!=0)//When the initial amount entered is not an integer multiple of 100, you will be prompted that the input is illegal { printf("The initial amount you entered is not an integer multiple of 100, please re-enter!\n"); system("pause"); system("cls"); continue; } // If the verification input is correct, save to the new depositor information // The system automatically generates a new depositor card number and password //The system automatically generates a new depositor card number and password //bac.accountCard =842+N; bac.accountCard =842+N; //Save the last six digits of the entered ID card as the initial password bac.password[0]=bac.cardId[12]; bac.password[1]=bac.cardId[13]; bac.password[2]=bac.cardId[14]; bac.password[3]=bac.cardId[15]; bac.password[4]=bac.cardId[16]; bac.password[5]=bac.cardId[17]; //Save the currently entered verified legal depositor information to the newly opened depositor information bankAccounts[N] = bac; printf("\n\n Card No.:%d\n",bac.accountCard); printf("Initial password:%s\n",bac.password); N++; break; } } }
The above code is about the bank account opening process, that is, the depositor's registration information enters the structure.