⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank_system.cpp

📁 这是我在大一时编的
💻 CPP
字号:
#include<iostream.h>
#include<string.h>

class bank
{
public:
	bank();
	void create_new_user();//创建新用户
	void modify_code();//修改密码
	void get_money();//取款
	void storage_money();//存款
	void print_obtain_storage();//用于存钱和取钱时打印清单
	void identify_function();//确认身份函数和查询函数
	void process();//运程函数
private:
	int get_money_order,storage_money_order,order_num;//三个命令按钮
	char user_name[10];//用户名
	char code_num[6];//密码,起始为000000
	int year1,month1,day1,year2,month2,day2;//日期,相对于存钱和取钱的两个日期
	double total_money,get_money_num,storage_money_num;//存款方式
	char card_number[6];//卡号
};

//设置一些初始项
bank::bank()
{
	code_num[0]='0';//设置起始密码
	code_num[1]='0';
	code_num[2]='0';
	code_num[3]='0';
	code_num[4]='0';
	code_num[5]='0';
	total_money=0.0;
	get_money_num=storage_money_num=0.0;
	get_money_order=storage_money_order=0;
}

//创建新用户函数的实现
void bank::create_new_user()
{
	char code1[6];
	int i,count=1,order=1;
	cout<<"Input a new card number:(6 bit)"<<endl;
	cin>>card_number;
	order=1;
	cout<<"Input user name:"<<endl;
	cin>>user_name;
	while(order)//校正密码
	{
		cout<<"Input a new code:"<<endl;
		cin>>code_num;
		cout<<"Input again:"<<endl;
		cin>>code1;
		i=strcmp(code_num,code1);
		if(i==0)
		{
			cout<<"You have successfully reseted a new code!"<<endl;
			order=0;
		}
		else
			cout<<"Input error!"<<endl;
	}
	cout<<"Successfully creat a new account!"<<endl;
}

//修改密码
void bank::modify_code()
{
	char c1[6];
	int order=1;
	identify_function();//对用户确认
	while(order)//校正密码
	{
		cout<<"Input the code you want to reset..."<<endl;
		cin>>code_num;
		cout<<"Input the mode again..."<<endl;
		cin>>c1;
		if(strcmp(c1,code_num)==0)
		{
			cout<<"Successfully reseted!"<<endl;
			order=0;
		}
		else
			cout<<"error!Input again..."<<endl;
	}
}

//用户确认,同时还是咨询函数
void bank::identify_function()
{
	int order=1,ident_num;
	char card[6];
	while(order)
	{
		cout<<"Input your card number..."<<endl;
		cin>>card;
		if(strcmp(card,card_number)==0)
			order=0;
		else
			cout<<"Input error!Input again..."<<endl;;
	}
	order=1;
	while(order)
	{
		cout<<"Input your card's code..."<<endl;
		cin>>card;
		ident_num=strcmp(card,code_num);
		if(ident_num!=0)
			cout<<"Input error!"<<endl;
		else
		{
			order=0;
			cout<<"User name:* "<<user_name<<" *           Please identify..."<<endl;
			cout<<endl<<"The left money you have is:* "<<total_money<<" *     Please check it!"<<endl;
			cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
			cout<<"Successfully identified!"<<endl;
			cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
		}
	}
}

//存钱
void bank::storage_money()
{
	identify_function();//用户确认
	cout<<"Tell me the sum of money you want to storge..."<<endl;
	cin>>storage_money_num;
	cout<<"Input the date as the order of 'year month day'..."<<endl;
	cin>>year2>>month2>>day2;
	cout<<"Successfully exchanged!"<<endl;
	storage_money_order=1;//使存钱按钮生效
	print_obtain_storage();//打印
}

//取钱
void bank::get_money()
{
	identify_function();
	cout<<"Tell me the sum of money you want to get..."<<endl;
	cin>>get_money_num;
	cout<<"Input the date as the order of 'year month day'..."<<endl;
	cin>>year1>>month1>>day1;
	cout<<"Successfully exchanged!"<<endl;
	get_money_order=1;//使取钱按钮生效
	print_obtain_storage();//打印
}

//打印函数的实现
void bank::print_obtain_storage()
{
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~ Listing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
	cout<<"User name: * "<<user_name<<" *     total money: "<<total_money<<" $ "<<endl;
	if(get_money_order==1)
	{
		cout<<"Operate ways: * getting money *    "<<"The amounts is: "<<get_money_num<<" $"<<endl;
		cout<<"The date is: "<<month1<<"/"<<day1<<"/"<<year1<<"    The left: "<<total_money-get_money_num<<" $ "<<endl;
		total_money-=get_money_num;
		get_money_num=0;
		get_money_order=0;//使取钱按钮失效
	}
	if(storage_money_order==1)
	{
		cout<<"Operate ways: * storage money *    "<<"The amounts is: "<<storage_money_num<<" $"<<endl;
		cout<<"The date is: "<<month2<<"/"<<day2<<"/"<<year2<<"    The left: "<<total_money+storage_money_num<<" $ "<<endl;
		total_money+=storage_money_num;
		storage_money_num=0.0;
		storage_money_order=0;//使存钱按钮失效
	}
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
}

//过程函数
void bank::process()
{
	cout<<"*************************Welcome to Bank of China*******************************"<<endl;
	while(order_num)
	{
		cout<<endl;
		cout<<"********************************Menu*****************************************"<<endl;
		cout<<" Creat a new account->1                      Modify code->2"<<endl;
		cout<<" Inquire about Information->3                Obtain money->4"<<endl;
		cout<<" Storge money->5                             Exit system->6"<<endl;
		cout<<"********************************Menu*****************************************"<<endl;
		cout<<endl;
		cout<<"Select a service type..."<<endl;
		int service_type;
		cin>>service_type;
		switch(service_type)
		{
			case 1:cout<<"--------------------------------------------------------------------------"<<endl;
				cout<<"************  Welcome to 'Creat a new account' system  *******************"<<endl;
				create_new_user();
				cout<<"**************************************************************************"<<endl;
				break;
			case 2:cout<<"---------------------------------------------------------------------------"<<endl;
				cout<<"************  Welcome to 'Modify code' system  ****************************"<<endl;
				modify_code();
				cout<<"***************************************************************************"<<endl;
				break;
			case 3:cout<<"----------------------------------------------------------------------------"<<endl;
				cout<<"************  Welcome to 'Inquire about Information' system  **************"<<endl;
				identify_function();
				cout<<"***************************************************************************"<<endl;
				break;
			case 4:cout<<"----------------------------------------------------------------------------"<<endl;
				cout<<"*************  Welcome to 'Obtain money' system****************************"<<endl;
				get_money();
				cout<<"***************************************************************************"<<endl;
				break;
			case 5:cout<<"-----------------------------------------------------------------------------"<<endl;
				cout<<"*************  Welcome to 'Storge money' system****************************"<<endl;
				storage_money();
				cout<<"***************************************************************************"<<endl;
				break;
			case 6:cout<<"-----------------------------------------------------------------------------"<<endl;
				cout<<"**********************   Welcme to Bank of China   *******************************"<<endl;
				cout<<"                Exit system...."<<endl;
				cout<<"                Thank you !"<<endl;
				order_num=0;
				cout<<"*************************   Bank of China    *************************************"<<endl;
				break;
			default:cout<<"Service type is not existed!"<<endl;
				break;
		}

	}
}
void main()
{
	
	cout<<"=============================================================================="<<endl;
	cout<<"读者必读:"<<endl;
	cout<<"本系统是模拟银行操作系统,主要有5个用途:(1)创建新用户     (2)修改密码"<<endl;
	cout<<"(3)取款  (4)还款.由于本人能力有限,只能编到这个程度,我已经尽力了。"<<endl;
	cout<<"=============================================================================="<<endl;
	cout<<endl;
	cout<<"=============================================================================="<<endl;
	cout<<"                                 **声明**                                     "<<endl;
	cout<<endl<<"请尊重别人知识产权,未经许可,严禁盗版!!!   谢谢合作!!!"<<endl;
	cout<<"=============================================================================="<<endl;
	cout<<endl;
	cout<<"系统运行正常!初始化中..."<<endl;
	int or;
	cout<<"开启系统 Yes-->1  NO-->0"<<endl;
	cin>>or;
	while(or==1)
	{
		bank b;
		b.process();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -