zoukankan      html  css  js  c++  java
  • ATM管理系统

    ATM管理系统


    博客班级 AHPU软件工程
    作业要求 ATM管理系统
    作业目标
    学号 3180701214


    题目要求

    编写一个ATM管理系统,语言不限,要求应包括以下主要功能:

    (1)开户,销户

    (2)查询账户余额

    (3)存款

    (4)取款

    (5)转账(一个账户转到另一个账户)等...

    代码

    头文件部分

    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    #include<string.h>
    #include<time.h>
    

    结构体部分(定义一个银行账户的基本信息)

    //定义一个银行账户基本信息
    typedef struct tagPerson{
    	char szUsername[20];//用户名
    	char szPassword[7];//密码 
    	char szAccountNumber[20];//银行账户 
    	float fMoney;//余额 
    }Person; 
    

    链表部分

    //链表的一个节点 
    typedef struct tagNode{
    	Person per;//数据域 
    	struct tagNode *pNext;//指针域 
    }Node;
    Node *g_pHead=NULL;//链表头结点 
    

    声明函数

    //开户 
    int CreateAccount(); 
    //登录
    int Login(); 
    //销户
    int CancelAccount(); 
    //菜单
    void Menu(Node *pNode); 
    //取款 
    int WithDrawal(Node *pNode);
    //存款
    int Deposits(Node *pNode);
    //转账
    int TransFer(Node *pNode); 
    //修改密码
    int ChangePa(Node *pNode); 
    //查找
    int Find(Node *pNode);
    

    开户

    int CreateAccount(){
    	printf("
    					请输入您的姓名:");
    	char szUsername[20];
    	scanf("%s",szUsername);//szUsername指针 地址 
    	
    	printf("
    					请设置您的银行卡密码:"); 
    	char szPassword[7];
    	scanf("%s",szPassword);
    	
    	printf("
    					请再次输入您的银行卡密码:"); 
    	char szRePassword[7];
    	scanf("%s",szRePassword);
    	
    	//判断两次输入的密码是否一致 
    	if(strcmp(szPassword,szRePassword)!=0){//相同为0,不同不为0 
    		printf("
    					两次输入的密码不一致!
    ");
    		return 0;
    	}
    
    	//随机生成银行账号
    	char szAccountNum[20];//0000 0000 0000 0000 0 0
    	//1000~9999
    	srand((unsigned int)time(NULL));
    	sprintf(szAccountNum,"%d%d%d%d%d%d",rand()%9000+1000,
    					rand()%9000+1000,rand()%9000+1000,rand()%9000+1000,rand()%10,rand()%10);//sprintf格式化字符串 
    		
    	//循环找到链表的尾结点	
    	Node *p=g_pHead;
    	while(g_pHead!=NULL&&p->pNext!=NULL){
    		p = p->pNext;
    	}
    	
    	//开辟一个新节点 
    	Node *pNewNode=(Node*)malloc(sizeof(Node));
    	strcpy(pNewNode->per.szUsername,szUsername);
    	strcpy(pNewNode->per.szPassword,szPassword);
    	strcpy(pNewNode->per.szAccountNumber,szAccountNum);
    	pNewNode->per.fMoney=0.0f;
    	pNewNode->pNext=NULL;
    	
    	//添加到尾结点后面
    	if(g_pHead==NULL){
    		g_pHead=pNewNode;
    	}
    	else{
    		p->pNext=pNewNode; 
    	}
    	
    	//打印信息
    	printf("
    					您的账户信息如下:
    "); 
    	printf("
    						姓名:%s
    ",pNewNode->per.szUsername); 
    	printf("
    						卡号:%s
    ",pNewNode->per.szAccountNumber); 
    	printf("
    						余额:%0.2f
    ",pNewNode->per.fMoney); 
    	
    	printf("
    					恭喜!账户申请成功!
    ");
    	
    	return 1; 
    } 
    

    登录

    int Login(){
    	char szAccountNum[20];//账号
    	char szPassword[7];//密码 
    	
    	printf("
    					请输入您的卡号:");
    	scanf("%s",szAccountNum);
    	
    	//遍历链表寻找当前账号 
    	Node *p=g_pHead;
    	while(p!=NULL){
    		if(strcmp(p->per.szAccountNumber,szAccountNum)!=0){
    			p=p->pNext;
    			continue;
    		}
    		else{
    			int i=0;
    			for(i=0;i<3;i++){
    				printf("
    					请输入您的密码:");
    				scanf("%s",szPassword);
    				
    				if(strcmp(szPassword,p->per.szPassword)!=0){
    					printf("
    					密码输入错误,请重新输入密码,剩余次数:%d
    ",2-i);
    					system("pause");
    					system("cls");
    					continue;
    				}
    				else{
    					system("cls");
    					//进入菜单页面 
    					Menu(p);
    					
    					return 1; 
    				}
    			}
    		}
    	} 
    	printf("
    					请输入您的密码:");
    	
    	return 1;
    }
    

    销户

    int CancelAccount(){
    	char Number[20],passWord[7];
    	printf("
    					请输入所需要注销的账户卡号:");
    	scanf("%s",Number);
    	
    	Node *p=g_pHead,*q=g_pHead;
    	while(p!=NULL){
    		if(strcmp(p->per.szAccountNumber,Number)!=0){
    			q=p;
    			p=p->pNext;
    			continue;
    		}
    		else{
    			int i=0;
    			for(i=0;i<3;i++){
    				printf("
    					请输入所需要注销的账户卡号密码:");
    				scanf("%s",passWord);
    				if(strcmp(passWord,p->per.szPassword)!=0){
    					printf("
    					密码输入错误,请重新输入密码,剩余次数:%d
    ",2-i);
    					system("pause");
    					system("cls");
    					continue;
    				}
    				else{
    					q->pNext=p->pNext;
    					free(p);
    					printf("
    					注销账户成功!
    ");
    					return 1;
    				}
    				printf("
    					注销账户失败!
    ");
    				return 0;
    			}
    		}
    	}
    	return 1;
    }
    

    取款

    int WithDrawal(Node *pNode){
    	float fMoney;
    	printf("
    					请输入要取款的金额:");
    	fflush(stdin);
    	scanf("%f",&fMoney);
    	while(fMoney<=0||fMoney>pNode->per.fMoney){
    		printf("
    					取款额不能小于等于零或者大于余额,请重新输入!
    ");
    		scanf("%f",&fMoney);
    	}
    	pNode->per.fMoney-=fMoney;
    	printf("
    					您的账户成功取出%.2f元!
    ",fMoney); 
    	return 1;
    } 
    

    存款

    int Deposits(Node *pNode){
    	float fMoney;
    	printf("
    					请输入要存款的金额:");
    	fflush(stdin);
    	scanf("%f",&fMoney);
    	while(fMoney<=0){
    		printf("
    					存款额不能小于等于零,请重新输入!
    ");
    		printf("
    					请输入要存款的金额:");
    		scanf("%f",&fMoney);
    	}
    	pNode->per.fMoney+=fMoney;
    	printf("
    					您的账户成功存入%.2f元!
    ",fMoney); 
    	return 1;
    }
    

    转账

    int TransFer(Node *pNode){
    	char szAccountNum[20];
    	float fMoney;
    	printf("
    					请输入要转入的账户卡号:");
    	fflush(stdin);
    	scanf("%s",szAccountNum);
    	
    	printf("
    					请输入要转入的金额:");
    	fflush(stdin);
    	scanf("%f",&fMoney);
    	
    	//遍历寻找需要转入的账号
    	Node *p=g_pHead;
    	while(p!=NULL){
    		if(strcmp(p->per.szAccountNumber,szAccountNum)!=0){
    			p=p->pNext; 
    			continue;
    		}
    		else{
    			pNode->per.fMoney-=fMoney;
    			p->per.fMoney+=fMoney;
    			printf("
    					转账成功!
    "); 
    			return 1; 
    		}
    	}
    	printf("
    					转出账户不存在!
    ");
    	return 1;	
    }
    

    修改密码

    int ChangePa(Node *pNode){
    	char passWord1[7],passWord2[7];
    	printf("
    					请输入原密码:");
    	scanf("%s",passWord1);
    	printf("
    					请输入新密码:");
    	scanf("%s",passWord2);
    	for(int i=0;i<3;i++){
    		if(strcmp(passWord1,pNode->per.szPassword)!=0){
    			printf("
    					原密码输入错误!还有%d次输入机会,请重新输入:
    ",2-i);
    			scanf("%s",passWord1);
    		}
    		else{
    			strcpy(pNode->per.szPassword,passWord2);
    			printf("
    					密码修改完成!
    ");
    			return 1;
    		} 
    	}
    	return 1;
    }
    

    查询余额

    int Find(Node *pNode){
    	printf("
    					当前账户余额为%.2f
    ",pNode->per.fMoney);
    	return 1;
    }
    

    主菜单

    void Menu(Node *pNode){
    	char ch;
    	start:
    		printf("
    
    							请选择您需要的业务:
    
    
    ");
    		printf("
    					  1>取款			2>查询
    ");
    		printf("
    					  3>转账			4>修改密码
    ");
    		printf("
    					  5>存款			6>退出
    ");
    		
    		ch=getch();
    		
    		switch(ch){
    			case '1'://取款
    				WithDrawal(pNode); 
    				system("pause");
    				system("cls"); 
    				break;
    			case '2'://查询
    				Find(pNode); 
    				system("pause");
    				system("cls");
    				break;
    			case '3'://转账 
    				TransFer(pNode);
    				system("pause");
    				system("cls");
    				break; 
    			case '4'://修改密码
    				ChangePa(pNode);
    				system("pause");
    				system("cls");
    				break;
    			case '5'://存款 
    				Deposits(pNode);
    				system("pause");
    				system("cls");
    				break;
    			case '6'://退出 
    				return;	
    		}
    		goto start;
    }
    

    主函数

    int main(){
    	//设置文字和背景颜色
    	system("color F2"); 
    	start:
    		printf("
    
    							ATM管理系统
    
    
    ");
    		
    		printf("							  1.开户
    ");
    		printf("							  2.登录
    ");
    		printf("							  3.销户
    ");
    		printf("							  4.退出
    ");
    	
    		char ch = getch();
    		switch(ch){
    			case '1'://开户
    				CreateAccount();
    				system("pause");
    				system("cls");
    				break;
    			case '2'://登录
    				Login();
    				system("pause");
    				system("cls");
    				break; 
    			case '3'://销户
    				CancelAccount(); 
    				system("pause");
    				system("cls");
    				break;
    			case '4'://退出 
    				exit(0); 
    				break;	
    		}
    	goto start;
    	return 0;
    } 
    

    运行界面

    主界面截图

    开户界面

    登录界面


    存款界面

    取款界面

    转账界面

    查询余额界面

    修改密码界面

    退出登录界面

    销户界面

    作业小结

    1.psp表格

    psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
    Planning 计划 100 90
    Development 开发 90 100
    Analysis 需求分析(包括学习新技术) 60 80
    Design Spec 生成设计文档 30 40
    Design Review 设计复审 5 10
    Coding Standard 代码规范 60 70
    Design 具体设计 10 12
    Coding 具体编码 240 240
    Code Review 代码复审 5 7
    Test 测试(自我测试,修改代码,提交修改) 50 50
    Reporting 报告 9 6
    Test Report 测试报告 3 10
    Size Measurement 计算工作量 20 40
    Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 30 30

    2.心得和经验

    通过本次作业,我复习了指针、链表、结构体的相关知识,对指针的传参方式有了更深入的掌握,同时也学习了很多新的知识,包括getch()函数的使用,使用scanf时在运行界面上会有显示输入的数据,但是使用getch()函数键盘在接受输入之后不会显示输入的数据,对界面的优化起到了很好的效果;第二个就是sprintf()函数,它可以将字符串进行格式化。总之,本次作业收获很多,也感受到了编程的乐趣,相信接下来的时间还能学到更多的东西。

  • 相关阅读:
    c# 使用ajaxfileupload上传文件,通过一般处理程序(Handler)接收文件 ashx 图片 Excel文件都可以
    C#+aspx+ajaxfileupload 实现文件上传
    Java中的int与String互相转换方式
    简述 readyonly 与 disabled 的区别
    was应用服务器搭建
    MVC中贫血模型与充血模型
    npm安装教程 Vue环境搭建
    使用vs Code从0开始搭建一个vue项目(手把手教会你,包会)
    使用VS code 打开Vue项目
    Task , Thread 学习
  • 原文地址:https://www.cnblogs.com/wufan111/p/13996528.html
Copyright © 2011-2022 走看看