zoukankan      html  css  js  c++  java
  • 软件工程第三次作业——ATM管理系统

    博客班级 软件工程
    作业要求 作业要求
    作业目标 根据ATM机的功能设计代码,并完成ATM系统代码的创建
    学号 3180701219

    题目要求:

    编写一个ATM管理系统,语言不限,要求应包括以下主要功能:
    (1)开户,销户
    (2)查询账户余额
    (3)存款
    (4)取款
    (5)转账(一个账户转到另一个账户)等...

    代码提交

    头文件

    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <cstdio>
    using namespace std;
    

    结构体

    typedef struct {
    	string name;			//用户名
    	string password;		//密码
    	string accountNumber;	        //账户
    	double money;			//余额
    }AccountNode;
    
    typedef struct node{
    	AccountNode acc;
    	struct node* next;
    }Node;
    

    函数声明

    void Menu();					//主菜单
    void CreateAccount(Node* &head);		//开户
    void Login(Node* head);				//登录
    bool Cancel(Node* &head);			//销户
    void LoginMenu();				//登录菜单
    Node* Find(Node* head, string accountNumber);	//根据账号找客户
    

    主菜单

    void Menu()//主菜单
    {
    	printf("
    
    
    					 ————————————
    ");
    	printf("					|	ATM管理系统	 |
    ");
    	printf("					|	        	 |
    ");
    	printf("					|	  1.开户	 |
    ");
    	printf("					|	  2.登录	 |
    ");
    	printf("					|	  3.销户	 |
    ");
    	printf("					|	  4.退出	 |
    ");
    	printf("					 ————————————
    ");
    	printf("							请选择:");
    }
    

    开户

    void CreateAccount(Node* &head)
    {
    	printf("
    
    
    					请输入您的姓名:");
    	string name;
    	cin >> name;
    	
    	printf("
    					请设置您的银行卡密码:");
    	string password;
    	cin >> password;
    
    	printf("
    					请再次输入您的银行卡密码:");
    	string repassword;
    	cin >> repassword;
    
    	//判断两次输入的密码是否一致
    	while (password != repassword) {
    		printf("
    					两次输入密码不一致,请重新输入:");
    		cin >> repassword;
    	}
    
    	//随机生成银行账号
    	char temp[20];//0000 0000 0000 0000 0 0
    	string accountNumber;
    	srand((unsigned int)time(NULL));
    	sprintf(temp, "%d%d%d%d%d%d", rand() % 9000 + 1000,
    		rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 9000 + 1000, rand() % 10, rand() % 10);//sprintf格式化字符串 
    	accountNumber = temp;
    
    	Node* pNode = new Node;
    	pNode->acc.name = name;
    	pNode->acc.password = password;
    	pNode->acc.accountNumber = accountNumber;
    	pNode->acc.money = 0;
    	pNode->next = NULL;
    
    	Node* p = head;
    	while (p != NULL && p->next != NULL)
    		p = p->next;
    	if (head == NULL)
    		head = pNode;
    	else
    		p->next = pNode;
    
    	printf("
    
    					恭喜您,开户成功!
    ");
    	cout << "
    					您的账号为:" << accountNumber << endl;
    }
    

    登录菜单

    void LoginMenu()
    {
    	printf("
    
    
    					 ————————————
    ");
    	printf("					|	  欢迎您!	 |
    ");
    	printf("					|	        	 |
    ");
    	printf("					|	  1.存款	 |
    ");
    	printf("					|	  2.取款	 |
    ");
    	printf("					|	  3.转账	 |
    ");
    	printf("					|	  4.查询余额	 |
    ");
    	printf("					|	  5.修改密码	 |
    ");
    	printf("					|	  6.退出	 |
    ");
    	printf("					 ————————————
    ");
    	printf("							请选择:");
    }
    

    登录及(存取款、查询余额、转账、修改密码)

    void Login(Node* head)
    {
    	string accountNumber;
    	string password;
    	printf("
    
    
    					请输入您的账号:");
    	cin >> accountNumber;
    	Node* p = Find(head, accountNumber);
    	if (!p) {
    		printf("
    					账号输入有误!");
    		return;
    	}
    	printf("
    					请输入您的密码:");
    	cin >> password;
    	while (p->acc.password != password) {
    		printf("
    					密码错误,请重新输入:");
    		cin >> password;
    	}
    	while (1) {
    		system("cls");
    		LoginMenu();
    		int choice;
    		string otherAccountNumber;
    		double money;
    		string newPassword;
    		Node* temp;
    		cin >> choice;
    		switch (choice)
    		{
    		case 1:
    			printf("
    
    					请输入您的存款金额:");
    			cin >> money;
    			p->acc.money += money;
    			printf("
    						存款成功!
    ");
    			break;
    		case 2:
    			printf("
    
    					请输入您的取款金额:");
    			cin >> money;
    			if (money > p->acc.money)
    				printf("
    						余额不足!
    ");
    			else {
    				p->acc.money -= money;
    				printf("
    						取款成功!
    ");
    			}
    			break;
    		case 3:
    			printf("
    
    					请输入您的转账的账号:");
    			cin >> otherAccountNumber;
    			printf("
    					请输入您的转账金额:");
    			cin >> money;
    			temp = Find(head, otherAccountNumber);
    			if (!temp) {
    				printf("
    					账号输入有误!");
    				system("pause");
    				return;
    			}
    			p->acc.money -= money;
    			temp->acc.money += money;
    			printf("
    						转账成功!
    ");
    			break;
    		case 4:
    			printf("
    
    					您的余额为:%.2f
    ", p->acc.money);
    			break;
    		case 5:
    			printf("
    
    					请输入您的新密码:");
    			cin >> newPassword;
    			p->acc.password = newPassword;
    			printf("
    						密码修改成功!
    ");
    			break;
    		case 6:
    			return;
    		default:
    			printf("							输入有误!
    ");
    		}
    		system("pause");
    	}
    }
    

    查找函数

    Node* Find(Node* head, string accountNumber)
    {
    	Node* p = head;
    	while (p != NULL) {
    		if (p->acc.accountNumber == accountNumber)
    			break;
    		p = p->next;
    	}
    	return p;
    }
    

    销户

    bool Cancel(Node* &head)
    {
    	string accountNumber;
    	printf("
    
    					请输入您要注销的账号:");
    	cin >> accountNumber;
    	Node* p = head,* q;
    	if (p != NULL && p->acc.accountNumber == accountNumber) {
    		head = p->next;
    		free(p);
    		printf("							注销成功!
    ");
    		return true;
    	}
    	q = p;
    	p = p->next;
    	while (p != NULL) {
    		if (p->acc.accountNumber == accountNumber) {
    			q->next = p->next;
    			free(p);
    			printf("							注销成功!
    ");
    			return true;
    		}
    		q = p;
    	}
    	return false;
    }
    

    主函数

    int main()
    {
    	Node* head = NULL;
    
    	while (1) {
    		system("cls");
    		Menu();
    		int choice;
    		cin >> choice;
    		switch (choice)
    		{
    		case 1:
    			CreateAccount(head);
    			break;
    		case 2:
    			Login(head);
    			break;
    		case 3:
    			Cancel(head);
    			break;
    		case 4:
    			return 0;
    		default:
    			printf("							输入有误!
    ");
    		}
    		system("pause");
    	}
    	return 0;
    }
    

    程序运行界面

    主菜单

    创建账户

    存款界面

    转账界面

    注销账户

    三.个人小结

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

    个人总结

    本次对ATM管理系统的编写主要使用C++来进行编写,复习了一些C++的基本语法,其中在创建新节点的时候,由于使用了string容器,导致malloc不能使用,不过一开始并没有发现这个问题,导致我走了很多的弯路,好在后期及时发现,使用new来创建新的节点,才解决了问题。

  • 相关阅读:
    【转载】 c++中static的用法详解
    ROS学习 Python读写文本文件
    (论文分析) Machine Learning -- Learning from labeled and unlabeled data
    (论文分析) 图像相似度和图像可见性分析
    (论文分析) Machine Learning -- Support Vector Machine Learning for Interdependent and Structured Output Spaces
    (论文分析) Object Detection-- Discriminatively Trained Part Based Models
    (论文分析) Machine Learning -- Predicting Diverse Subsets Using Structural SVMs
    (论文分析) Machine Learning -- Online Choice of Active Learning Algorithms
    (论文分析) Object Detection -- Class-Specific Hough Forests for Object Detection
    (论文分析) Object Detection -- A Boundary Fragment Model for Object Detection
  • 原文地址:https://www.cnblogs.com/wlong/p/14001877.html
Copyright © 2011-2022 走看看