个人作业三-ATM管理系统

作业通知

| 博客班级 | AHPU-软件工程导论-计算机18级 |
| ---- | ---- | ---- |
| 作业要求 | 个人作业三-ATM管理系统 |
| 作业目标 | 编写一个ATM管理系统 |
| 学号 | 3180701231 |

作业要求

编写一个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(); //开户 

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("\n\t\t请输入姓名:");
	char szUsername[20];
	scanf("%s",szUsername);
	
	printf("\n\t\t请设置银行卡密码:"); 
	char szPassword[7];
	scanf("%s",szPassword);
	
	printf("\n\t\t请再次输入银行卡密码:"); 
	char szRePassword[7];
	scanf("%s",szRePassword);
	
	//判断两次输入的密码是否一致 
	if(strcmp(szPassword,szRePassword)!=0){//相同为0,不同不为0 
		printf("\n\t\t两次输入的密码不一致!\n");
		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("\n\t\t您的账户信息如下:\n"); 
	printf("\n\t\t姓名:%s\n",pNewNode->per.szUsername); 
	printf("\n\t\t卡号:%s\n",pNewNode->per.szAccountNumber); 
	printf("\n\t\t余额:%0.2f\n",pNewNode->per.fMoney); 
	
	printf("\n\t\t恭喜!账户申请成功!\n");
	
	return 1; 
}
 
//登录
int Login(){
	char szAccountNum[20];//账号
	char szPassword[7];//密码 
	
	printf("\n\t\t请输入卡号:");
	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("\n\t\t请输入密码:");
				scanf("%s",szPassword);
				
				if(strcmp(szPassword,p->per.szPassword)!=0){
					printf("\n\t\t密码输入错误,请重新输入密码,剩余次数:%d\n",2-i);
					system("pause");
					system("cls");
					continue;
				}
				else{
					system("cls");
					//进入菜单页面 
					Menu(p);
					
					return 1; 
				}
			}
		}
	} 
	printf("\n\t\t请输入密码:");
	
	return 1;
}

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

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

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

//转账
int TransFer(Node *pNode){
	char szAccountNum[20];
	float fMoney;
	printf("\n\t\t请输入要转入的账户卡号:");
	fflush(stdin);
	scanf("%s",szAccountNum);
	
	printf("\n\t\t请输入要转入的金额:");
	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("\n\t\t转账成功!\n"); 
			return 1; 
		}
	}
	printf("\n\t\t转出账户不存在!\n");
	return 1;	
}

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

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

主菜单


//主菜单
void Menu(Node *pNode){
	char ch;
	start:
		printf("\n\n\t\t请选择您需要的业务:\n\n\n");
		printf("\n\t\t  1>取款\t\t\t2>查询\n");
		printf("\n\t\t 3>转账\t\t\t4>修改密码\n");
		printf("\n\t\t  5>存款\t\t\t6>退出\n");
		
		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("\n\n\t\t\t\t\t\t\tATM管理系统\n\n\n");
		
		printf("\t\t\t\t\t\t 1.开户\n");
		printf("\t\t\t\t\t\t 2.登录\n");
		printf("\t\t\t\t\t\t 3.销户\n");
		printf("\t\t\t\t\t\t 4.退出\n");
	
		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;
} 

功能块运行截图

开户

销户

存款

取款

查询账户余额

转账


个人小结

psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 60 85
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 200 150
Development 开发 120 150
Analysis 需求分析(包括学习新技术) 40 30
Design Spec 生成设计文档 20 20
Design Review 设计复审 10 10
Coding Standard 代码规范 20 45
Design 具体设计 200 150
Coding 具体编码 180 200
Code Review 代码复审 15 10
Test 测试(自我测试,修改代码,提交修改) 10 15
Reporting 报告 60 70
Test Report 测试报告 15 10
Size Measurement 计算工作量 10 10
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 10 15

收获

通过这次实验重新回顾了如何编写一个小程序,这仿佛回到了曾经数据结构课设的时候。通过回顾各个部分代码所需要的功能并通过具体代码实现的过程,重新回顾了许多函数的使用方法,虽然过程比较耗费时间,但是重新掌握这些基本的概念还是十分有意义的。

posted @ 2020-11-19 00:27  可依旧少年  阅读(123)  评论(0编辑  收藏  举报