十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
真正的ATM系统不可能只是用C语言编写的,它应该是一套完整独立的系统,核心代码更机密,不会轻易的泄露。
我们提供的服务有:网站设计、成都做网站、微信公众号开发、网站优化、网站认证、康乐ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的康乐网站制作公司
C语言可以写一个类似于ATM系统的框架,用以模拟ATM机上的各种操作。
框架代码如下:
#includeiostream.h
#includestdio.h
int main()
{
int choice =- 1;
while(1) {
printf("请选择\n1.login\t2.regist\n");
scanf("%d", choice);
switch(choice) {
case 1:
login();
break;
case 2:
regist();
break;
default:
printf("输入有误,重新输入\n");
break;
}
}
return 0;
}
void login() {
printf("IN LOGIN\n");
int flag = -1;
int X = -1;
printf("输入账户和密码\n");
flag = search();
if(falg == 1) {
printf("存在,进入主页面\n");
X = menu();
if(X == 1)
return;
}
else if(flag == 0) {
printf("账户或密码错误\n");
return;
}
}
int regist() {
printf("IN REGIST\n");
return 1;
}
int menu() {
printf("IN MENU\n");
int key = -1;
int N = -1;
while(1) {
printf("请选择业务:1.refer\t2.deposit\t3.withdraw\t4.transfer\t5.resetPW\t6.退出\n");
scanf("%d", key);
switch(key) {
case 1:
N = refer();
break;
case 2:
N = deposit();
break;
case 3:
N = withdraw();
break;
case 4:
N = transfer();
break;
case 5:
N = resetPW();
break;
case 6:
N = 6;
return 1;
break;
default:
printf("输入有误,重新选择:\n");
break;
}
if(N%2 == 0) {
printf("Error!\n");
}
}
}
int refer() {
printf("IN REFER\n");
//输出余额
return 1;
}
int deposit() {
printf("IN DEPOSIT\n");
//存钱
return 3;
}
int withdraw() {
printf("IN WITHDRAW\n");
//取钱
return 5;
}
int transfer() {
ptintf("IN TRANSFER\n");
//转账
return 7;
}
int resetPW() {
prtintf("IN RESETPW\n");
//重设密码
return 9;
}
char szPassword[128] = {0};
int iNum = 0;
while(true)
{ //这里没有过滤特殊符号,比如 Backspace 回格符,循环中自己特殊处理下就OK了
if(iNum128)
{
puts("用户输入密码过长~!");
}
char ch = getch();
if(ch == 13) //按回车表示用户密码输入结束
{
szPassword[iNum]='\0';
putch('\n');
break;
}
putch('*');
szPassword[iNum++]=ch;
}
puts(szPassword);
#include iostream
using namespace std;
///////////////////////////////用户类//////////////////////////////////////
class User
{
private:
int money;
string userName;
string password;
public:
User();
~User();
User(string userName, string password);
int saveMoney(int money);// 存款
int getMoney(int money); // 取款
int checkMoney(); // 查询余额
string getUserName(); // 取得用户名
string getPassword(); // 取得密码
};
User::User()
{
money = 0;
}
User::User(string userName, string password)
{
money = 0;
this-userName = userName;
this-password = password;
}
int User::saveMoney(int money)
{
this-money += money;
return this-money;
}
int User::getMoney(int money)
{
this-money -= money;
return this-money;
}
int User::checkMoney()
{
return this-money;
}
string User::getUserName()
{
return this-userName;
}
string User::getPassword()
{
return this-password;
}
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////数据库类,用来存储用户//////////////////////
class DataBase
{
private:
User *users[40]; // 默认数据可最多能存放40个用户
int userNumber; // 已注册用户的数量
public:
DataBase();
~DataBase();
bool add(User *user); // 添加新用户
User * getUser(int i); // 按照索引取得用户
User * getUser(string name); // 按照用户名取得用户
int getUserNumber(); // 取得数据库中用户的数量
};
DataBase::DataBase()
{
userNumber = 0;
}
DataBase::~DataBase()
{
delete users;
}
bool DataBase::add(User *user)
{
if(userNumber 40 getUser(user-getUserName()) == NULL) // 如果当前用户名在数据库中不存在
{
users[userNumber] = user;
userNumber++;
return true; // 返回true表示新用户添加成功
}
return false; // 返回false表示新用户添加失败
}
User * DataBase::getUser(int i)
{
if(i 40 || i 0) return NULL;
return users[i];
}
User * DataBase::getUser(string userName)
{
for(int i = 0; i userNumber; i++)
{
User *user = getUser(i);
if(user-getUserName() == userName) return user;
}
return NULL;
}
/////////////////////////////////////////////////////////////////////////
DataBase database;
int welcom();
// 注册
User * user_register();
User * user_login();
int exit();
int user_process();
int main()
{
int state;
int user_state;
User *user;
do
{
state = welcom();
switch(state)
{
case 1:
user = user_register(); // 用户注册
if(NULL != user)
{
cout"\n注册成功\n";
do
{
user_state = user_process();
switch(user_state)
{
case 1:// 存钱
{
cout"输入存钱金额:";
int num;
cinnum;
cout"余额为:"user-saveMoney(num)endl;;
}
break;
case 2:// 取钱
{
cout"输入取钱金额:";
int num;
cinnum;
cout"余额为:"user-getMoney(num)endl;
}
break;
case 3:// 查看余额
{
cout"余额为:"user-checkMoney()endl;
}
break;
case 4://返回
user_state = 0;
default: break;
}
} while(user_state);
user = NULL;
}
else cout"\n注册失败\n";
break;
case 2:
user = user_login(); // 用户登陆
if(NULL != user)
{
cout"登陆成功"endl;
do
{
user_state = user_process();
switch(user_state)
{
case 1:// 存钱
{
cout"输入存钱金额:";
int num;
cinnum;
cout"余额为:"user-saveMoney(num)endl;;
}
break;
case 2:// 取钱
{
cout"输入取钱金额:";
int num;
cinnum;
cout"余额为:"user-getMoney(num)endl;
}
break;
case 3:// 查看余额
{
cout"余额为:"user-checkMoney()endl;
}
break;
case 4://返回
user_state = 0;
default: break;
}
} while(user_state);
user = NULL;
}
else cout"\n登陆失败\n";
break;
case 3:
state = exit();
break;
default: break;
}
}
while(state);
return 0;
}
int welcom()
{
cout"\t\t**********欢迎使用ATM系统**********\n";
cout"\t\t* 1.用户注册 *\n";
cout"\t\t* 2.用户登录 *\n";
cout"\t\t* 3.退出系统 *\n";
cout"\t\t***********************************\n";
int num;
cinnum;
return num;
}
// 注册
User * user_register()
{
string userName;
string password;
cout"请输入账号:";
cinuserName;
if(NULL != database.getUser(userName)) // 如果用户名存在
return NULL; // 注册失败
cout"请输入密码:";
cinpassword;
User *user = new User(userName, password);
database.add(user);
return user; // 注册成功
}
User * user_login()
{
string userName;
string password;
cout"请输入账号:";
cinuserName;
cout"请输入密码:";
cinpassword;
User *user = database.getUser(userName);
if(NULL != user) // 如果用户存在
if(user-getPassword() == password)
return user; // 如果密码匹配则登陆成功
return NULL; // 如果用户不存在
}
int exit()
{
return 0; // 退出系统
}
int user_process()
{
cout"\t\t******************************\n";
cout"\t\t* 请选择操作类型 *\n";
cout"\t\t* 1.存 钱 *\n";
cout"\t\t* 2.取 钱 *\n";
cout"\t\t* 3.查 看 余 额 *\n";
cout"\t\t* 4.返 回 *\n";
cout"\t\t******************************\n";
int num;
cinnum;
return num;
}
#includestdio.h
int chaxun(int a3)
{
int b;
b=a3;
printf("你的余额为:%d\n",b) ;
}
int qukuan(int a3)
{
int a,b;
printf("请输入您要提取的现金:\n");
scanf("%d",a);
b=a3-a;
if(b0)
printf("对不起 ,你的余额不足\n");
else
{
printf("请收好您的%d元现金\n",a);
a3=a3-a;
}
return (a3);
}
int gaini(int a2)
{
int a,b,c=1,d,e=1;
while(e)
{
printf("请输入你的旧密码:\n");
scanf("%d",d);
if(d==a2)
e=0;
else
{
e=1;
printf("你输入的密码错误,请重新输入:\n");
}
}
while(c)
{
printf("请输入您的六位数新密码\n");
scanf("%d",a2);
printf("请确认您的六位数新密码\n");
scanf("%d",b);
if(a2==b)
{
if(b100000b999999b/(b/100000)!=111111)
{
c=0;
printf("密码修改成功\n");
}
else
{
printf("您输入的密码不符合要求,请从新输入\n");
c=1;
}
}
else
{
c=1;
printf("您两次输入的密码不一致,请重新输入:\n");
}
}
return a2;
}
int quka()
{
printf("\n 梦若保保提醒您\n");
printf("请收好您的卡片,谢谢,再见\n\n");
}
int cunkuan(int a3)
{
int i,j,k;
printf("请输入你要存的金额\n");
scanf("%d",k);
if(k0)
{
printf("对不起,没有负存款\n");
}
else
{
printf("\n您好,您已经存进去了%d元\n",k);
a3=a3+k;
}
return a3;
}
main()
{
int i,j,b=1,c,k,l,m,n;
int a1=123456,a2=123456,a3=1000;
printf("欢迎使用自动柜员机:\n\n");
while(b==1)
{
printf("请输入您的账号:\n");
scanf("%d",k);
printf("请输入您的密码:\n");
scanf("%d",l);
if(k==a1l==a2)
{
b=0;
printf("您的账户余额为:%d\n",a3);
}
else
{
b=1;
printf("对不起,您输入的账号或者密码有误,请重新输入:\n");
}
}
do
{
printf("\n请选择您要的服务项目:\n");
printf("1.查询余额\n");
printf("2.取款\n");
printf("3.修改密码\n");
printf("4.取卡\n");
printf("5.存款\n");
scanf("%d",c);
switch(c)
{
case 1:
chaxun(a3);
break;
case 2:
a3=qukuan(a3);
break;
case 3:
a2=gaini(a2);
break;
case 4:
quka();
break;
case 5:
a3=cunkuan(a3);
break;
}
}while(c!=4);
}
#include stdio.h
#include stdlib.h
#include conio.h
#include string.h
void regist();
void login();
void quite();
void inputpassword(char mima[]);
void service();
struct bank
{
char name[20];
char password[7];
int account;
double money;
}kehu;
int find;
int a[10];
struct bank one;
FILE *fp;
void main()
{
int i;
int t=1;
for(i=0;i100;i++)
{
printf("\t\t\t\t\t\t欢迎使用青软ATM系统\n");
printf("\t\t\t\t\t\t正在进入主界面,请稍等");
int j;
for(j=1;jt;j++)
{
printf(".");
}
t++;
if(t==10)
{
t=1;
}
printf("\n\t\t\t\t\t\t%d%%",i);
system("cls");
}
while(1)
{
printf("\t\t\t\t\t\t服务类型: \n");
printf("\t\t\t\t\t\t[a]: 用户注册\n");
printf("\t\t\t\t\t\t[b]: 用户登录\n");
printf("\t\t\t\t\t\t[c]: 退出系统\n");
printf("\t\t\t\t\t\t请选择服务: ");
fflush(stdin);
char xz;
scanf("%c",xz);
if(xz=='a'||xz=='A')
{
regist();
} else if (xz=='b'||xz=='B')
{
login();
} else if(xz=='c'||xz=='C')
{
quite();
} else
{
printf("输入有误,请重新输入");
}
getch();
system("cls");
}
}
void inputpassword(char mima[])
{
int i=0;
char ch;
while(1)
{
ch=getch();
if(ch!='\r')
{
if(ch!='\b'){
mima[i]=ch;
i++;
printf("*");
}else{
if(i0){
i--;
printf("\b \b");
}
}
}else{
break;
}
}
mima[i]='\0';
printf("\n");
}
void regist()
{
fp=fopen("atm.txt","ab+");
if(fp==NULL)
{
printf("\n\t\t\t文件打开失败!");
return;
}
system("cls");
printf("\t\t\t现在执行的是注册函数的使用\n");
printf("\t\t请输入用户名: ");
fflush(stdin);
gets(kehu.name);
char password1[7];
while(1)
{
while(1)
{
printf("\n\n\t\t请输入密码:");
fflush(stdin);
inputpassword(kehu.password);
int n=strlen(kehu.password);
if(n==6)
{
break;
}else
{
printf("\n\t\t密码必须为6位!");
}
}
printf("\n\t\t请输入正确密码!: ");
fflush(stdin);
inputpassword(password1);
if(strcmp(kehu.password,password1)==0)
{
break;
}else{
printf("\n\n\t\t两次密码必须相同!");
}
}
rewind(fp);
struct bank k;
if(fread(k,sizeof(struct bank),1,fp)==1)
{
fseek(fp,-sizeof(k),2);
fread(k,sizeof(k),1,fp);
kehu.account=k.account+1;
}else{
kehu.account=20170001;
}
kehu.money=0;
fseek(fp,0,2);
fwrite(kehu,sizeof(struct bank),1,fp);
fclose(fp);
printf("\n\n\t\t开户成功! ");
printf("\n\t\t您的账号为%d!",kehu.account);
printf("\n\t\t现在请您重新登录!");
}
void searchmoney()
{
system("cls");
printf("您现在使用的是查询余额功能: \n");
printf("\n\n\t\t您的余额是%0.2lf",one.money);
}
void savemoney()
{
system("cls");
double inmoney;
printf("请您选择您要存款的金额 \n");
scanf("%lf",inmoney);
int q;
int r=1;
for(q=0;q100;q++)
{
int w;
for(w=1;wr;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在存款%d%%",q);
system("cls");
}
one.money=one.money+inmoney;
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已存款成功!");
}
void withdrawalmoney()
{
system("cls");
double outputsomemoney;
printf("请您选择您要取款的金额 \n");
scanf("%lf",outputsomemoney);
if(one.moneyoutputsomemoney){
printf("您的余额已不足,请您注意!");
}else {
int q;
int r=1;
for(q=0;q100;q++)
{
int w;
for(w=1;wr;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在取款%d%%",q);
system("cls");
}
one.money=one.money-outputsomemoney;
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已取款成功!请点清钞票!");
printf("\n\n\t\t\t\t\t\t您现在的余额为%lf",one.money);
}
}
void transfermoney()
{
system("cls");
int duifang;
int qian;
fflush(stdin);
printf("\n\n\n\t\t您现在使用的是转账功能");
printf("\n\t\t\t请输入您要转账的账户:");
scanf("%d",duifang);
int n=ftell(fp);
rewind(fp);
int flag=0;
struct bank temp;
while(fread(temp,sizeof(temp),1,fp)==1)
{
if(temp.account==duifang)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("请输入转账金额:");
scanf("%d",qian);
if(one.money=qian)
{
int q;
int r=1;
for(q=0;q100;q++)
{
int w;
for(w=1;wr;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在转账,请稍后!%d%%",q);
system("cls");
}
temp.money=temp.money+qian;
fseek(fp,-sizeof(temp),1);
fwrite(temp,sizeof(temp),1,fp);
one.money=one.money-qian;
fseek(fp,n-sizeof(one),0);
fwrite(one,sizeof(one),1,fp);
printf("\n\t\t\t\t转账成功!");
}else{
printf("\n\t\t\t\t您的余额已不足!");
}
}
}
void xiugai(){
system("cls");
printf("\n\n\t\t 现在进行的是修改密码功能\n");
char oldpassword[7];
char newpassword[7];
char newpassword1[7];
int i;
for(i=0;i3;i++){
printf("\n\t\t\t 请输入旧密码:\n");
inputpassword(oldpassword);
if(strcmp(oldpassword,one.password)==0){
printf("\n\t\t\t 输入成功!\n");
break;
}else{
printf("\n\t\t\t 密码输入有误,请重新输入!\n");
}
}
if(i3){
while(1){
printf("\n\t\t\t 请输入您的新密码:\n");
inputpassword(newpassword);
printf("\n\t\t\t 请输入您的确认密码:\n ");
inputpassword(newpassword1);
if(strcmp(newpassword,newpassword1)==0){
strcpy(one.password,newpassword);
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\t\t\t 密码修改成功!");
break;
}else{
printf("\n\t\t\t 两次密码输入不一致!");
}
}
}else{
printf("\n\t\t\t 密码输入错误!");
}
}
int zhuxiaozhanghao()
{
system("cls");
int zhuxiaoxitong;
char sf;
printf("你要注销的账号是%d",one.account);
printf("你是否要对此账号进行注销?\n\n\t\t请您选择:注销(Y)or不注销(N):");
fflush(stdin);
scanf("%c",sf);
if(sf=='y'||sf=='Y')
{
printf("正在为您注销!\n",one.account);
zhuxiaoxitong=1;
}else{
printf("不注销系统!\n",one.account);
}
return zhuxiaoxitong;
}
void service()
{
while(1){
system("cls");
printf("\n\n\n\t\t\t\t\t\t现在是服务系统,本系统有以下服务");
printf("\n\t\t\t\t\t\t[a] 查询余额\n");
printf("\n\t\t\t\t\t\t[b] 存款服务\n");
printf("\n\t\t\t\t\t\t[c] 转账服务\n");
printf("\n\t\t\t\t\t\t[d] 取款服务\n");
printf("\n\t\t\t\t\t\t[e] 修改密码\n");
printf("\n\t\t\t\t\t\t[f] 注销 \n");
printf("\n\t\t\t\t\t\t[g] 退出系统\n");
char e;
printf("\n\t\t\t\t\t\t您要选择的服务是:");
fflush(stdin);
scanf("%c",e);
switch(e)
{ case'A':
case'a': searchmoney() ;break;
case'B':
case'b': savemoney() ;break;
case'C':
case'c': transfermoney() ;break;
case'D':
case'd': withdrawalmoney() ;break;
case'E':
case'e': xiugai() ;break;
case'F':
case'f': {int zhuxiaoxitong=zhuxiaozhanghao();{if(zhuxiaoxitong==1) return;}break;}
case'G':
case'g': quite();break;
}
printf("\n\n\n\t\t\t\t按任意键继续......\n");
getch();
}
}
void login()
{
fp=fopen("atm.txt","rb+");
if(fp==NULL)
{
printf("\n\n\n\t\t\t\t文件打开失败!");
return;
}
system("cls");
printf("\n\t\t\t\t\t\t现在执行的是登录函数的使用\n");
int zhanghao;
printf("\n\t\t\t\t\t\t请输入账号:");
scanf("%d",zhanghao);
int flag=0;
while(fread(one,sizeof(one),1,fp)==1)
{
if(zhanghao==one.account){
flag=1;
break;
}
}
char password2[7];
if(flag==1){
int h;
for(h=0;h3;h++){
printf("\n\t\t\t\t\t\t请输入密码:");
fflush(stdin);
inputpassword(password2);
if(strcmp(password2,one.password)==0)
{
printf("\n\t\t\t\t\t\t登陆成功!");
service();
break;
}else{
printf("密码不正确!");
}
}
if(h==3){
printf("\n\t\t\t您的密码三次输入有误,返回");
}
}else{
printf("无此账号!");
}
fclose(fp);
}
void quite()
{
system("cls");
printf("\t\t\t现在执行的是退出函数的使用\n");
exit(0);
}