⭐一、工作前的准备
⭐1、需求概述
1.产品类型:简易ATM自助取款机
2.产品背景:本产品旨在满足人们财产存取等需求,为人们提供更加方便的服务
3.设计目的:ATM自助取款机的设计意图是为了方便人们更加合理妥善地管理自己的财产,确保个人财产的安全,提高人们的生活质量。
⭐2、功能概述
1.登入:需要输入用户的账号密码,账号密码正确才可以进入ATM系统
2.存款:存取用户想要存取的金额,并修改txt文档中的数据
3.取款:取出用户想要取出的金额,并修改txt文档中的数据
4.查询:查询用户的财产信息
5.修改密码:修改用户的个人密码(只有在登入成功后才可进行)
6.转账:用户对其他用户进行金额的转账,并修改各自在文档中的数据信息
7.语音播报:在运行程序后进行语音播报(欢迎使用本ATM自助取款机)
8.弹窗:弹出一个广告页面,点击窗口右上角即可关闭(暂不完善)
9.开户:注册一个全新的本ATM系统中的账号
10.销户:删除该用户需要销毁账号在txt文档中的数据
11.忘记密码:用户忘记密码时可通过一系列个人密保等找回密码
12.流水记录:记录用户账号存款、取款、转账等操作
⭐二、代码实现
⭐1、结构体的定义
struct LoginData { char user[MAX_USER_LEN]; //用户的账号 char pass[MAX_PASS_LEN]; //用户的密码 double balance; //用户的余额 };
⭐2、主函数
#include "atmdemo.h" #include <stdio.h> #include <cstdlib> int main() { //speak(); printf("*********************************\n"); printf("*****欢迎来到ATM银行取款系统*****\n"); printf("*********************************\n"); int choose; while (true) { printf("1.登录\t2.注册\n"); printf("3.忘记密码 4.退出\n"); printf("请选择你需要进行的业务:\n"); scanf("%d",&choose); getchar(); switch (choose) { case 1: login(); break; case 2: enroll(); break; case 3: forgotpassword(); break; case 4: printf("退出成功\n"); exit(0); default: printf("非法输入,请重新输入:\n"); break; } } }
⭐3、功能函数
⭐01、用户登入
登入:用户需要输入账号和密码进行登入,只有当账号密码都正确时才能登入成功。登入时有三次机会,每次输入错误减少一次机会并提示剩余几次机会,若三次输入都错误用户将无法再次进行登入且显示登入失败。
#include "atmdemo.h" #include <stdio.h> #include <string.h> struct LoginData Account; bool check_account(char name[MAX_USER_LEN], char pass[MAX_PASS_LEN]); void login() { FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); if(fp==NULL){ printf("该系统没有用户,请注册\n"); return; } fclose(fp); char user_name[MAX_USER_LEN]; char user_pass[MAX_PASS_LEN]; int count=0; while (true) { printf("请输入用户名:\n"); scanf("%s",user_name); printf("请输入密码:\n"); scanf("%s",user_pass); bool flag=check_account(user_name,user_pass); if(flag == false) { if(count==2){ printf("登陆失败!!!\n"); return; } count++; printf("用户名或密码错误,还剩"); printf("%d",3-count); printf("次机会,请重新输入\n"); } else{ break; } } printf("登录成功\n"); mnue(Account); } bool check_account(char name[MAX_USER_LEN], char pass[MAX_PASS_LEN]) { FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); char stored_user[MAX_USER_LEN]; char stored_pass[MAX_PASS_LEN]; double stored_balance; while (fscanf(fp, "%s %s %lf", stored_user, stored_pass, &stored_balance) == 3) { if (strcmp(name, stored_user) == 0 && strcmp(pass, stored_pass) == 0) { strcpy(Account.user,stored_user); strcpy(Account.pass,stored_pass); Account.balance=stored_balance; fclose(fp); return true; } } fclose(fp); return false; }
⭐02、用户存款
存款:用户输入自己需要存取的金额,若存取金额小于等于0,显示非法输入,否则将用户需要存取的金额在原有金额上进行相加,并且更新txt文档中该用户的信息。
#include "atmdemo.h" #include <stdio.h> #include <string.h> bool deposit(struct LoginData loginData, double amount) { if (amount <= 0) { printf("非法输入,请重新输入\n"); return false; } else { FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE *temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); char file_user[MAX_USER_LEN]; char file_pass[MAX_PASS_LEN]; double file_balance; double temp_balance; while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(loginData.user, file_user) == 0 && strcmp(loginData.pass, file_pass) == 0) { temp_balance = file_balance + amount; fprintf(temp, "%s %s %.2lf\n", loginData.user, loginData.pass, temp_balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("存款成功,账户余额为: %.2lf\n", temp_balance); char type[20]="deposit"; char c='+'; FILE *fr = fopen("D:\\Users\\AdolBook\\Desktop\\transaction_history.txt", "a"); fprintf(fr,"%s %s %c %.2lf\n",loginData.user,type,c,amount); fclose(fr); return true; } }
⭐03、用户取款
取款:用户输入自己需要取出的金额,若取出的金额小于等于0,显示非法输入,若取出的金额大于该用户所拥有的金额,显示余额不足,请重新输入。否则的话在用户原有的金额上减去取出的金额,并且更新txt文档中该用户的信息。
#include "atmdemo.h" #include <stdio.h> #include <string.h> bool withdraw(struct LoginData loginData, double amount) { if (amount <= 0) { printf("非法输入,请重新输入\n"); return false; } else if (amount > loginData.balance) { printf("余额不足,请重新输入\n"); return false; } else { FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE *temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); char file_user[MAX_USER_LEN]; char file_pass[MAX_PASS_LEN]; double file_balance; double temp_balance; while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(loginData.user, file_user) == 0 && strcmp(loginData.pass, file_pass) == 0) { temp_balance = file_balance - amount; fprintf(temp, "%s %s %.2lf\n", loginData.user, loginData.pass, temp_balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("取款成功,账户余额为:%.2lf\n", temp_balance); char type[20]="withdraw"; char c='-'; FILE *fr = fopen("D:\\Users\\AdolBook\\Desktop\\transaction_history.txt", "a"); fprintf(fr,"%s %s %c %.2lf\n",loginData.user,type,c,amount); fclose(fr); return true; } }
⭐04、用户查询
查询:打开txt文档在里面查询该用户所拥有的财产并向该用户展示出来
#include "atmdemo.h" #include <stdio.h> #include <string.h> void check(struct LoginData loginData) { FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); char check_user[MAX_USER_LEN]; char check_pass[MAX_PASS_LEN]; double check_balance; while (fscanf(fp, "%s %s %lf", check_user, check_pass, &check_balance) == 3) { if (strcmp(loginData.user, check_user) == 0) { printf("查询成功,您的余额为 %.2lf\n", check_balance); break; } } fclose(fp); }
⭐05、修改密码
修改密码:先输入该用户现在的密码,然后输入需要修改的新密码,输入新密码后要求再次输入新密码以确认(密码要求为6位数)
#include "atmdemo.h" #include <stdio.h> #include <string.h> void changePassword(struct LoginData loginData) { printf("请输入新密码\n"); char change_pass[MAX_PASS_LEN]; scanf("%s", change_pass); FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE* temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); char file_user[MAX_USER_LEN]; char file_pass[MAX_PASS_LEN]; double file_balance; while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(loginData.user, file_user) == 0 && strcmp(loginData.pass, file_pass) == 0) { fprintf(temp, "%s %s %.2lf\n", loginData.user, change_pass, loginData.balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("修改密码成功\n"); }
⭐06、用户转账
转账:当前用户输入需要转账的用户账号,若被转账的用户账号不存在,显示该账户不存在,否则的话输入需要转账的金额,若转账金额大于当前用户所拥有的金额,显示余额不足,反之则向被转账的用户进行转账,当前用户的金额在原有金额上减去转出去的金额,被转账的用户在原有的金额上加上转过去的那笔钱。双方的用户信息都需要在文档中进行更新。
#include "atmdemo.h" #include <stdio.h> #include <string.h> bool transferaccounts(struct LoginData loginData, char transfer_name[]) { FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE *temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); char file_user[MAX_USER_LEN]; char file_pass[MAX_PASS_LEN]; double file_balance; char transfer_pass[MAX_USER_LEN]; double balance; bool found = false; while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(transfer_name, file_user) == 0) { found = true; strcpy(transfer_pass, file_pass); balance = file_balance; fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); if (!found) { printf("账户不存在\n"); return false; } printf("请输入转账金额\n"); double transfer_balance; scanf("%lf", &transfer_balance); if (transfer_balance > loginData.balance) { printf("您的余额不足\n"); return false; } fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(loginData.user, file_user) == 0 && strcmp(loginData.pass, file_pass) == 0) { fprintf(temp, "%s %s %.2lf\n", loginData.user, loginData.pass, file_balance - transfer_balance); } else if (strcmp(transfer_name, file_user) == 0) { fprintf(temp, "%s %s %.2lf\n", transfer_name, transfer_pass, transfer_balance + balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("转账成功\n"); char type[20]="transfer"; char c1='+'; char c2='-'; FILE *fr = fopen("D:\\Users\\AdolBook\\Desktop\\transaction_history.txt", "a"); fprintf(fr,"%s %s %c %.2lf\n",loginData.user,type,c2,transfer_balance); fprintf(fr,"%s %s %c %.2lf\n",transfer_name,type,c1,transfer_balance); fclose(fr); return true; }
⭐07、语音播报
语音播报:在运行ATM系统后自动播报一段语音,并且在次基础上设置一下系统页面(颜色、标题)
#include"atmdemo.h" #include<stdio.h> #include<stdlib.h> void showStyle() { //system("color f3"); system("title 哈哈语音播报系统"); } char userData[10000] = "欢迎使用22计软6班程序一组的ATM自助取款机"; void speak() { //界面设定 showStyle(); //生产vbs文件 FILE* fp = fopen("voice.vbs", "w"); //写入CreteObject("SAPI.SpVoice"),Speak("用户输入的内容"); fprintf(fp, "CreateObject(\"SAPI.SpVoice\").Speak(\"%s\")", "欢迎使用二二计软6班程序一组的ATM自助取款机"); fclose(fp); system("voice.vbs"); //语音读取vbs文件 //system("del voice.vbs"); //删除vbs文件 system("pause"); }
⭐08、用户注册
注册:如若当前用户没有账号的话可立即注册一个,注册时首先需要输入一个自定义账号,然后自己设定一个私密密码,该密码的长度为6位,注册成功后该用户注册的该账号相关信息将存入txt文档中,且初始余额为0。
#include "atmdemo.h" #include <stdio.h> #include <string.h> bool check_username(char name[MAX_USER_LEN]); bool check_pass(char pass[MAX_PASS_LEN]); bool againcheck_pass(char pass[MAX_PASS_LEN], char pass1[MAX_PASS_LEN]); bool checkPhone(char num[11]); bool checkCode(int code, int code1); void enroll(void){ printf("-------------------------\n"); printf("-----欢迎来到注册界面----\n"); printf("-------------------------\n"); FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "a"); char user_name[MAX_USER_LEN]; char user_pass[MAX_PASS_LEN]; char again_pass[MAX_PASS_LEN]; double user_balance=0; printf("请输入用户名:(按0退出)\n"); while (true) { scanf("%s", user_name); if(strcmp(user_name,"0")==0){ return; } bool flag1 = check_username(user_name); if (flag1 == false) { printf("用户名已存在,请重新输入:(按0退出)\n"); continue; }else { printf("请输入密码:(密码应为6为数字)\n"); scanf("%s",user_pass); bool flag2=check_pass(user_pass); if(flag2 == false){ printf("密码格式错误,请重新操作。\n"); continue; }else{ printf("请再次输入密码:\n"); scanf("%s",again_pass); bool flag3=againcheck_pass(user_pass,again_pass); if(flag3 == false){ printf("两次密码不一致,请重新操作。\n"); continue; } else{ fprintf(fp,"%s %s %.2lf\n",user_name,user_pass,user_balance); printf("注册成功。\n"); break; } } } } fclose(fp); printf("请绑定您的手机号码\n"); char phoneNum[11]; while (true) { scanf("%s", phoneNum); bool flag = checkPhone(phoneNum); if (!flag) { printf("电话号码格式错误,请重新输入\n"); continue; } else { break; } } while (true) { int RandCode=getRandomCode(); printf("%d\n",RandCode); int inRandCode; printf("请输入验证码\n"); scanf("%d",&inRandCode); bool flag=checkCode(RandCode,inRandCode); if(!flag){ printf("验证码错误,请重新输入\n"); continue; } else{ break; } } FILE* basic = fopen("D:\\Users\\AdolBook\\Desktop\\basic_data.txt", "a"); fprintf(basic,"%s %s\n",user_name,phoneNum); printf("绑定成功\n"); fclose(basic); } bool checkCode(int code, int code1) { if(code==code1){ return true; } else { return false; } } bool checkPhone(char num[11]) { if(strlen(num)!=11){ return false; } else { return true; } } bool againcheck_pass(char pass[6], char pass1[6]) { if(strcmp(pass,pass1)==0){ return true; } else{ return false; } } bool check_pass(char pass[6]) { if(strlen(pass)!=6){ return false; }else{ for(int i=0;i< strlen(pass);i++){ if(pass[i]<'0'||pass[i]>'9'){ return false; } } } return true; } bool check_username(char name[MAX_USER_LEN]) { FILE* fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); char checkuser[MAX_USER_LEN]; char checkpass[MAX_PASS_LEN]; double checkbalance; while (fscanf(fp, "%s %s %lf", checkuser, checkpass, &checkbalance) == 3) { if (strcmp(name, checkuser) == 0) { fclose(fp); return false; } } fclose(fp); return true; }
⭐09、用户注销
注销:如果当前用户不想要某个账号时可对账号进行销户处理,即将该账号进行销毁,销户时需先进行身份验证,首先要输入电话号码,电话号码正确后再输入验证码,验证码正确后才可成功销户。
#include "atmdemo.h" #include "stdio.h" #include "string.h" #include "stdlib.h" bool checkPhone(char phone[12], char account[20]); void cancellation(char account[20]) { char check_phone[12]; printf("注销前需验证身份,请输入手机号码(按0退出)\n"); while (true) { scanf("%s", check_phone); if (strcmp(check_phone, "0") == 0) { printf("退出成功\n"); return; } bool flag1 = checkPhone(check_phone, account); if (!flag1) { printf("电话号码错误,请重新输入\n"); continue; } else { break; } } while (true) { int RandCode = getRandomCode(); int inRandCode; printf("%04d\n", RandCode); printf("请输入验证码\n"); scanf("%d", &inRandCode); if (RandCode == inRandCode) { break; } else { printf("验证码错误\n"); continue; } } char file_user[20]; char file_pass[20]; char file_phone[12]; double file_balance; FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\basic_data.txt", "r"); FILE *temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp_data.txt", "w"); while (fscanf(fp, "%s %s", file_user, file_phone) == 2) { if (strcmp(account, file_user) == 0) { continue; } else { fprintf(temp, "%s %s\n", file_user, file_phone); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\basic_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp_data.txt", "D:\\Users\\AdolBook\\Desktop\\basic_data.txt"); FILE *fp1 = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE *temp1 = fopen("D:\\Users\\AdolBook\\Desktop\\temp1_data.txt", "w"); while (fscanf(fp1, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(account, file_user) == 0) { continue; } else { fprintf(temp1, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp1); fclose(temp1); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp1_data.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("注销成功\n"); exit(0); } bool checkPhone(char phone[12], char account[20]) { char file_user[MAX_USER_LEN]; char file_phone[12]; FILE *fo = fopen("D:\\Users\\AdolBook\\Desktop\\basic_data.txt", "r"); while (fscanf(fo, "%s %s", file_user, file_phone) == 2) { if (strcmp(file_user, account) == 0 && strcmp(file_phone, phone) == 0) { return true; } } fclose(fo); return false; }
验证码功能的实现代码:
#include "atmdemo.h" #include <stdio.h> #include <stdlib.h> #include <time.h> int getRandomCode() { int Code; srand(time(NULL)); Code = rand() % 10000; return Code; }
⭐10、忘记密码
忘记密码:当前用户忘记账号密码时可选择忘记密码选项,首先需要输入用户账号,然后输入该用户账号绑定的手机号,然后通过该账号绑定的手机号发送的验证码才可进行密码的修改,修改密码时先输入新密码,然后再次输入密码来确认,密码格式必须为6位数,,且前后两次密码必须相同。以上步骤均正确后才可成功修改密码。
#include "atmdemo.h" #include <stdio.h> #include <string.h> bool checkPass(char pass[6]); bool againcheck(char pass[6], char again[6]); bool CheckCode(int code1, int code2); void forgotpassword() { char user_name[MAX_USER_LEN]; char file_user[MAX_USER_LEN]; char file_pass[MAX_PASS_LEN]; double file_balance; char file_phone[12]; char phoneNum[12]; printf("请输入用户名\n"); scanf("%s", user_name); bool flag1 = false; FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(user_name, file_user) == 0) { flag1 = true; break; } } fclose(fp); if (!flag1) { printf("该账户不存在\n"); return; } bool flag2 = false; int count=0; printf("请输入电话号码\n"); FILE *fo = fopen("D:\\Users\\AdolBook\\Desktop\\basic_data.txt", "r"); while (true) { scanf("%s", phoneNum); while (fscanf(fo, "%s %s", file_user, file_phone) == 2) { if (strcmp(file_user,user_name)==0 && strcmp(file_phone, phoneNum) == 0) { flag2 = true; break; } } if (flag2 == false) { if(count==2){ return; } count++; printf("电话号码错误,请重新输入\n"); continue; } else { break; } } fclose(fo); while (true) { int RandCode = getRandomCode(); int inRandCode; printf("%04d\n",RandCode); printf("请输入验证码\n"); scanf("%d", &inRandCode); bool flag3 = CheckCode(RandCode, inRandCode); if (!flag3) { printf("验证码错误,请重新输入\n"); continue; } else { break; } } char pass[MAX_PASS_LEN]; char again[MAX_PASS_LEN]; while (true) { printf("请输入新密码(应为6为数字)\n"); scanf("%s", pass); bool flag1 = checkPass(pass); if(!flag1){ printf("密码格式错误\n"); continue; } else { printf("请再次输入密码\n"); scanf("%s",again); bool flag2=againcheck(pass,again); if(!flag2){ printf("两次密码不一致\n"); continue; } else { break; } } } fp = fopen("D:\\Users\\AdolBook\\Desktop\\login_data.txt", "r"); FILE *temp = fopen("D:\\Users\\AdolBook\\Desktop\\temp.txt", "w"); while (fscanf(fp, "%s %s %lf", file_user, file_pass, &file_balance) == 3) { if (strcmp(user_name, file_user) == 0 ) { fprintf(temp, "%s %s %.2lf\n", file_user, pass, file_balance); } else { fprintf(temp, "%s %s %.2lf\n", file_user, file_pass, file_balance); } } fclose(fp); fclose(temp); remove("D:\\Users\\AdolBook\\Desktop\\login_data.txt"); rename("D:\\Users\\AdolBook\\Desktop\\temp.txt", "D:\\Users\\AdolBook\\Desktop\\login_data.txt"); printf("密码修改成功\n"); } bool CheckCode(int code1, int code2) { if(code1==code2){ return true; } else { return false; } } bool againcheck(char pass[6], char again[6]) { if(strcmp(pass,again)==0){ return true; } else { return false; } } bool checkPass(char pass[6]) { if(strlen(pass)!=6){ return false; }else{ return true; } }
⭐11、流水记录
流水记录:根据当前用户的账号回溯其帐号的交易记录,每次进行的交易操作都会被存取到一个txt文档中,进行流水记录查询时就会将该账号存取在该txt文档中的交易过程一一展示出来。
#include "atmdemo.h" #include "stdio.h" #include "string.h" void QueryStatements(char account[20]) { char file_user[MAX_USER_LEN]; char file_type[MAX_PASS_LEN]; double file_balance; char file_c; FILE *fp = fopen("D:\\Users\\AdolBook\\Desktop\\transaction_history.txt", "r"); while (fscanf(fp, "%s %s %c %lf", file_user, file_type, &file_c, &file_balance) == 4) { if (strcmp(account, file_user) == 0) { printf("%s %s %c %.2lf\n", file_user, file_type, file_c, file_balance); } } fclose(fp); }
⭐项目自定义头文件
这个简易ATM的实现时通过将各个功能函数封装在每个cpp文件中,然后通过自定义头文件在主函数中调用实现的。
#ifndef WORK_ATMDEMO_H #define WORK_ATMDEMO_H #include "stdio.h" #include "stdlib.h" #define MAX_USER_LEN 20 #define MAX_PASS_LEN 20 struct LoginData { char user[MAX_USER_LEN]; char pass[MAX_PASS_LEN]; double balance; }; void login(); bool withdraw(struct LoginData loginData, double amount); bool deposit(struct LoginData loginData, double amount); void check(struct LoginData loginData); void changePassword(struct LoginData loginData); bool transferaccounts(struct LoginData loginData, char transfer_name[]); void enroll(void); void forgotpassword(); void mnue(struct LoginData); int getRandomCode(); void speak(); void QueryStatements(char account[20]); void cancellation(char account[20]); #endif //WORK_ATMDEMO_H
⭐三、写在最后
OK本文的学习就到此结束啦,希望本文可以帮助到各位有需要的小伙伴们喔,也希望各位小伙伴们可以不要吝惜手里的三连哦!感谢你们的支持,你们的支持就是我创作最大的动力哦!❤️❤️❤️
💕
回头看,轻舟已过万重山,向前看,前路漫漫亦漫漫。