当前位置:编程学习 > C/C++ >>

c语言模拟简单atm

初学者,老师的作业,不用太长,简单几个功能就行,取款,查询余额,修改密码,
答案:
#include <stdio.h>
#include <string.h>
#include <conio.h>
struct guke
{
int zhanghao;//账号
char xingming[10];//姓名
char mima[10];//密码
float zongjine;//总金额
};
typedef struct guke GUKE;

typedef struct _node
{
GUKE AccountInf;
_node* pNext;
}AccountNode;

int number=1;
AccountNode* pHead = NULL;
void GetPassword(char* pPassword);
AccountNode* NewAccount()
{
AccountNode* pNode = new AccountNode;
if (pNode == NULL)
return NULL;

memset(pNode,0,sizeof(AccountNode));
//input name
printf("请输入帐号名称:");
scanf("%s",pNode->AccountInf.xingming);

//input password
printf("请输入帐号密码:");
GetPassword(pNode->AccountInf.mima);

//set default value
pNode->AccountInf.zhanghao = number++;
pNode->AccountInf.zongjine = 0;
return pNode;
}

void InsertAccount(AccountNode* pNode)
{
if (pNode == NULL)
return;

//first node
if(pHead == NULL)
pHead = pNode;
else
{
AccountNode* pTmp = pHead;
while(pTmp->pNext)
{
pTmp = pTmp->pNext;
}
pTmp->pNext = pNode;
}
}

bool OpenAccount()
{
AccountNode* pAccount = NewAccount();
if (pAccount == NULL)
return false;

InsertAccount(pAccount);
printf("开户成功!你的帐号是%d\n",pAccount->AccountInf.zhanghao);
return true;
}

void ShowAllAccount()
{
if (pHead == NULL)
return;

AccountNode* pCurAccount = pHead;
while(pCurAccount)
{
printf("账号:%-4d ",pCurAccount->AccountInf.zhanghao);
printf("姓名:%-10s ",pCurAccount->AccountInf.xingming);
printf("密码:%-10s",pCurAccount->AccountInf.mima);
printf("余额:%.2f\n",pCurAccount->AccountInf.zongjine);
pCurAccount = pCurAccount->pNext;
}
}
网上有,自己去C网站下载吧

上一个:C语言学习的方向
下一个:C语言编程问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,