个人作业三--ATM管理系统

博客班级 软件工程
作业链接 第三次作业
作业要求 编写一个ATM系统
学号 3180701333

作业要求

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

(1)开户,销户

(2)查询账户余额

(3)存款

(4)取款

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

部分模块代码

结构体

{
public:  
	ATM(YongHu& y):yh(y)
	{}   
	void DLJM();//登陆界面  
	bool HDMM(char ID[],char password[]);//核对密码  
	void QK();//取款  
	void CX();//查询  
	void GG();//更改密码  
	void GNJM();//功能界面  
	void LK();//锁卡  
	void TC();//退出 
	char *GetPassword();
private:  
	int times;  
	YongHu& yh; 
};

用户类

class YongHu//用户类 
{  
public:  
	friend class ATM;  
	YongHu(char id[],float Money,char Password[]);  
	char* get_ID();//获取卡号  
	char* get_password();//获取密码 
	float get_money();//获取余额      
	void set_password(char Password[]);//设置密码  
	void set_money(float m);
private:  
	char ID[20];//卡号  
	char password[10];//密码  
	float money;//卡上余额 
};

登录界面

void ATM::DLJM()//登陆界面   
	{  
		times=0;      
		char ID[20],password[10],ch;    
		int i=0;    
		do    
		{
			i=0;    
			cout<<"     ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆"<<endl;   
			cout<<"            ◆欢迎使用中国农业银行!◆"<<endl;    
			cout<<"     ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆"<<endl<<endl;   
			cout<<"              测试卡号为:123456"<<endl;   
			cout<<"              测试密码为:123456"<<endl;    
			cout<<"              测试卡号余额为:10000元"<<endl<<endl<<endl;   
			cout<<"                   请输入您的卡号                "<<endl;    
			cout<<"★卡号:";  
			do 
			{      
				cin.get(ch);      
				ID[i++]=ch;     
			}while(ch!='
');     
			ID[i-1]='';      
			i=0;    
			cout<<endl<<"             请输入您的密码                "<<endl;   
			cout<<"★密码:";     
			strcpy(password,GetPassword());     
			if(!HDMM(ID,password))     
			{      
				cout<<"~对不起,您的卡号或密码有误,请重新输入"<<endl;         
				times++;     
			}     
			else     
			{     
				GNJM();     
			}    
		}while(times<3);    
		LK();   
	}   
	bool ATM::HDMM(char ID[],char password[])  
	{  
		if(strcmp(ID,yh.get_ID())==0&&strcmp(password,yh.get_password())==0) 
		return true; 
		else     
			return false;  
}

操作选择

void ATM::GNJM() 
{
	int n;    
	cout<<endl<<endl<<endl;    
	cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl;      
	cout<<"☆             1)取款★"<<endl;   
	cout<<"★             2)查询余额☆"<<endl;   
	cout<<"☆             3)更改密码★"<<endl;   
	cout<<"★             4)退出系统☆"<<endl;    
	cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl; 
	cout<<endl<<"★请输入你想操作的序号:";  
	cin>>n;    
	if(n<0||n>4)   
	{ 
		cout<<"★您输入的序号不正确,请重新输入:";     
		cin>>n;  
    }
	switch(n)   
	{    
	case 1:QK();
		break;   
	case 2:CX();
		break;   
	case 3:GG();
		break;   
	case 4:TC();
		break;   
}while(true); 
}    

取钱

void ATM::QK() 
{    
	float m;   
	char ch;    
		cout<<endl<<"★请输入您要取多少钱:";    
		cin>>m;    
		while(m<=0)    
		{     
			cout<<"★请输入正确的取款数:"<<endl;     
			cin>>m;    
		}
		if(yh.get_money()-m<0)    
		{     
			cout<<"~对不起,您的余额不足!"<<endl;    
		}        
		else   
		{    
			if((int)m%100!=0)    
			{      
				cout<<"~对不起,您的取款金额必须为100的倍数!"<<endl;      
			}     
			else  
			{    
				if(m>2000)    
				{    
					cout<<"~对不起,您每次只能取2000元!"<<endl;    
				}    
				else    
				{         
					cout<<"~操作成功,请稍后!!!"<<endl;     
					yh.set_money(m);
					cout<<"★请输入(y/n)确认是否取钱!"<<endl;   
		            cin>>ch;           
		            while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')   
		            {    
		              cout<<"★请再次输入(y/n)确认是否取钱!"<<endl;
			          cin>>ch;  
		            }
		            if(ch=='y'||ch=='Y')
					cout<<"~您已取款成功!请收好钱!";
					else
					cout<<"~您已取款成功!请尽快取钱!";
				}  
			}   
		}
	GNJM();
} 

存钱

void ATM::CX() 
{  
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
	cout<<"                                            "<<endl;  
	cout<<"   卡号:"<<yh.get_ID()<<endl;  
	cout<<"   余额:"<<yh.get_money()<<"元"<<endl;  
	cout<<"                                            "<<endl;
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
	GNJM(); 
}  

改密码

void ATM::GG()
{  
	char password[10],Xpassword[10];  
	times=0;  
	do  
	{   
		cout<<endl<<"★请输入旧密码:";    
		strcpy(password,GetPassword());
		if(!HDMM(yh.get_ID(),password))    
			times++;   
		else    
			break;
	}while(times<3);  
	if(times==3)  
		LK();  
	int t=1;
	do {   
		cout<<endl<<"★请输入新密码:";  
		strcpy(password,GetPassword());  
		cout<<endl<<"★请再次输入新密码:";  
		strcpy(Xpassword,GetPassword());  
		t=strcmp(password,Xpassword);//对新密码进行比较,如果相等,则返回0    
		if(t!=0)     
			cout<<endl<<"~您输入的密码不一致,请重新输入!"<<endl;  
}while(t!=0);
	yh.set_password(password);
	cout<<endl<<"~密码修改成功,请您牢记!"<<endl; 
	GNJM(); 
}

个人小结

一.PSP表格

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

二.心得体会

通过这次作业,加深了我对编程的理解,达到了学与用的结合,增强了对编程应用的理解,积累了不少经验,在整个学习与设计过程中,在完成作业过程中不免遇到各种各样的困难,通过与同学间的探讨,查阅资料解决困难,增强了自己的自学能力。锻炼了自己,强化专业,我相信,只要认真学习,多借鉴别人的经验,多思考,多实践,最后就能成功。

源码

//funtion.h
#include<iostream> 
#include<cstring> 
#include<cstdlib>  
class YongHu;//定义全局类class 
class ATM//ATM类 
{
public:  
	ATM(YongHu& y):yh(y)
	{}   
	void DLJM();//登陆界面  
	bool HDMM(char ID[],char password[]);//核对密码  
	void QK();//取款  
	void CX();//查询  
	void GG();//更改密码  
	void GNJM();//功能界面  
	void LK();//锁卡  
	void TC();//退出 
	char *GetPassword();
private:  
	int times;  
	YongHu& yh; 
}; 
class YongHu//用户类 
{  
public:  
	friend class ATM;  
	YongHu(char id[],float Money,char Password[]);  
	char* get_ID();//获取卡号  
	char* get_password();//获取密码 
	float get_money();//获取余额      
	void set_password(char Password[]);//设置密码  
	void set_money(float m);
private:  
	char ID[20];//卡号  
	char password[10];//密码  
	float money;//卡上余额 
};
//ATM.cpp
#include<iostream>
#include<conio.h>
#include "funtion.h"
#include <cstring>
using namespace std;
 void ATM::DLJM()//登陆界面   
	{  
		times=0;      
		char ID[20],password[10],ch;    
		int i=0;    
		do    
		{
			i=0;    
			cout<<"     ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆"<<endl;   
			cout<<"            ◆欢迎使用中国农业银行!◆"<<endl;    
			cout<<"     ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆"<<endl<<endl;   
			cout<<"              测试卡号为:123456"<<endl;   
			cout<<"              测试密码为:123456"<<endl;    
			cout<<"              测试卡号余额为:10000元"<<endl<<endl<<endl;   
			cout<<"                   请输入您的卡号                "<<endl;    
			cout<<"★卡号:";  
			do 
			{      
				cin.get(ch);      
				ID[i++]=ch;     
			}while(ch!='
');     
			ID[i-1]='';      
			i=0;    
			cout<<endl<<"             请输入您的密码                "<<endl;   
			cout<<"★密码:";     
			strcpy(password,GetPassword());     
			if(!HDMM(ID,password))     
			{      
				cout<<"~对不起,您的卡号或密码有误,请重新输入"<<endl;         
				times++;     
			}     
			else     
			{     
				GNJM();     
			}    
		}while(times<3);    
		LK();   
	}   
	bool ATM::HDMM(char ID[],char password[])  
	{  
		if(strcmp(ID,yh.get_ID())==0&&strcmp(password,yh.get_password())==0) 
		return true; 
		else     
			return false;  
}
void ATM::GNJM() 
{
	int n;    
	cout<<endl<<endl<<endl;    
	cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl;      
	cout<<"☆             1)取款★"<<endl;   
	cout<<"★             2)查询余额☆"<<endl;   
	cout<<"☆             3)更改密码★"<<endl;   
	cout<<"★             4)退出系统☆"<<endl;    
	cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl; 
	cout<<endl<<"★请输入你想操作的序号:";  
	cin>>n;    
	if(n<0||n>4)   
	{ 
		cout<<"★您输入的序号不正确,请重新输入:";     
		cin>>n;  
    }
	switch(n)   
	{    
	case 1:QK();
		break;   
	case 2:CX();
		break;   
	case 3:GG();
		break;   
	case 4:TC();
		break;   
}while(true); 
}    
void ATM::QK() 
{    
	float m;   
	char ch;    
		cout<<endl<<"★请输入您要取多少钱:";    
		cin>>m;    
		while(m<=0)    
		{     
			cout<<"★请输入正确的取款数:"<<endl;     
			cin>>m;    
		}
		if(yh.get_money()-m<0)    
		{     
			cout<<"~对不起,您的余额不足!"<<endl;    
		}        
		else   
		{    
			if((int)m%100!=0)    
			{      
				cout<<"~对不起,您的取款金额必须为100的倍数!"<<endl;      
			}     
			else  
			{    
				if(m>2000)    
				{    
					cout<<"~对不起,您每次只能取2000元!"<<endl;    
				}    
				else    
				{         
					cout<<"~操作成功,请稍后!!!"<<endl;     
					yh.set_money(m);
					cout<<"★请输入(y/n)确认是否取钱!"<<endl;   
		            cin>>ch;           
		            while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')   
		            {    
		              cout<<"★请再次输入(y/n)确认是否取钱!"<<endl;
			          cin>>ch;  
		            }
		            if(ch=='y'||ch=='Y')
					cout<<"~您已取款成功!请收好钱!";
					else
					cout<<"~您已取款成功!请尽快取钱!";
				}  
			}   
		}
	GNJM();
} 
void ATM::CX() 
{  
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
	cout<<"                                            "<<endl;  
	cout<<"   卡号:"<<yh.get_ID()<<endl;  
	cout<<"   余额:"<<yh.get_money()<<"元"<<endl;  
	cout<<"                                            "<<endl;
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
	GNJM(); 
}   
void ATM::GG()
{  
	char password[10],Xpassword[10];  
	times=0;  
	do  
	{   
		cout<<endl<<"★请输入旧密码:";    
		strcpy(password,GetPassword());
		if(!HDMM(yh.get_ID(),password))    
			times++;   
		else    
			break;
	}while(times<3);  
	if(times==3)  
		LK();  
	int t=1;
	do {   
		cout<<endl<<"★请输入新密码:";  
		strcpy(password,GetPassword());  
		cout<<endl<<"★请再次输入新密码:";  
		strcpy(Xpassword,GetPassword());  
		t=strcmp(password,Xpassword);//对新密码进行比较,如果相等,则返回0    
		if(t!=0)     
			cout<<endl<<"~您输入的密码不一致,请重新输入!"<<endl;  
}while(t!=0);
	yh.set_password(password);
	cout<<endl<<"~密码修改成功,请您牢记!"<<endl; 
	GNJM(); 
}   
void ATM::LK() 
{  
	cout<<"~对不起,你输入的密码错误已达三次,您的卡已被没收!"<<endl;     
	exit(1);
}
void ATM::TC() 
{  
	cout<<"~请取走您的卡,感谢您的使用,欢迎您下次再来!"<<endl;     
	exit(0); 
}
char * ATM::GetPassword()
{
    char c;
    int i=0;
    char password[6];
    while ((c=getch())!='
')
    {
        password[i]=c;
        putchar('*');
        i++;
        if (i>=6)
        {
            break;
        }
    }
    
    return password;
}
//YongHu.cpp
#include "funtion.h"
#include <cstring>
    YongHu::YongHu(char id[],float Money,char Password[])//用户的构造函数 
	{  
		strcpy(ID,id);//strcpy函数是复制两字符串的函数,头文件为<cstring>     
		money=Money;  
		strcpy(password,Password); 
	}  
	float YongHu::get_money()//获取余额函数 
	{  
		return money; 
	}   
	char* YongHu::get_ID()//获取卡号 
	{  
		return ID; 
	}   
	void YongHu::set_money(float m) 
	{  
		money-=m; 
	}   
	char* YongHu::get_password()//获取密码 
	{  
		return password; 
	}   
	void YongHu::set_password(char Password[])//设置密码   
	{    
		strcpy(password,Password);   
	} 
//main.cpp
#include<iostream>
#include "funtion.h"
int main(void) 
{  
	YongHu y1("123456",10000,"123456");//创建用户y1  
	ATM a(y1);  
	a.DLJM();  
	a.GNJM(); 
	return 0;
}
原文地址:https://www.cnblogs.com/hukoutian123/p/14003013.html