C++:编译银行管理系统(vector)

题目概述:
编译银行管理系统。
编译:
#include< iostream>
#include< fstream>
#include< vector>
#include< string>
using namespace std;
class BankAccount
{
public:
BankAccount() {};
BankAccount(int number, string name, double money, int phone);//构造函数
int renum() { return user_number; }
string renam() { return user_name; }
double remon() { return over_money; }
int repho() { return user_phone; }
void DisplayInformation();//展示账户信息
friend ostream& operator << (ostream& Out, BankAccount&p)
{
Out << "身份证; " << p.user_number << "姓名: " << p.user_name << "金额: " << p.over_money << "电话: " << p.user_phone ;
return Out;
}
int user_number;//账号
string user_name;//姓名
double over_money=0;//金额
int user_phone;//电话
};
vector v1;
BankAccount p[1000];
int number_temp;//账号`
string name_temp;//姓名
int phone_temp;//电话
void W_File();//打开输出文件
void DisplayAll();//展示全部账户信息
void CreateAccount();//开户
void Destroy();//销户
void DepoistMoney();//存钱
void WithdrawMoney();//取钱
void Find();//查询个人信息
void W_File()//打开输出文件,文件结尾写数据
{
ofstream outfile(“f1.dat”);
if (!outfile)
{
cerr << “此文件无效!” << endl;
exit(1);
}
outfile << “身份证:\t姓名:\t金额;\t电话:\t” << endl;
for (auto& x : v1)
{
outfile << x << endl;
}
outfile.close();
}

BankAccount::BankAccount(int number, string name, double money, int phone)//构造函数
{
user_number = number;
user_name = name;
over_money = money;
user_phone = phone;
}
void BankAccount::DisplayInformation()//展示用户信息
{
cout <<"身份号: " << user_number << " 用户名: " << user_name << " 账户余额: " << over_money << " 电话号: "<< user_phone;
cout << endl;
}
void DisplayAll()//展示全部账户信息
{
for (size_t i = 0; i < v1.size(); i++)
{
v1[i].DisplayInformation();
}
W_File();
}
void Mulu()//菜单
{
cout << “" << endl;
cout << “* 银行账户管理系统 " << endl;
cout << "
------------------------------" << endl;
cout << "
1.账户信息展示 " << endl;
cout << "
2.开 户 " << endl;
cout << "
3.销 户 " << endl;
cout << "
4.存 钱 " << endl;
cout << "
5.取 钱 " << endl;
cout << "
6.查询个人信息 " << endl;
cout << "
7.返 回 *” << endl;
cout << "
” << endl;
cout << "请输入您所要办理的业务-> ";
}
void CreateAccount(double money_temp)//开户
{
cout << “请输入所开账户的账号: 用户名:电话: ->”;
cin >> number_temp >> name_temp >> phone_temp;
v1.push_back(BankAccount(number_temp,name_temp,money_temp,phone_temp));
W_File();
}
void Destroy()//销户
{
cout << "输入删除对象的身份证: ";
cin >> number_temp;
for (vector::iterator it = v1.begin(); it != v1.end(); it++)
{
if (number_temp == it->renum())
{
v1.erase(it);
return;
}
else
cout << “无此用户身份证!”;
}
W_File();
}
void DepoistMoney(double money_temp)//存钱
{
int a = 1;
while (a == 1)
{
cout << "输入存钱用户的身份证和金额: ";
cin >> number_temp >> money_temp;

	for (int i = 0; i < v1.size(); i++)
	{
		if (v1[i].renum() == number_temp)
		{p[i].over_money += money_temp;
			v1[i].over_money =p[i].over_money;
			v1[i].DisplayInformation();//打印
			a = 0;
			break;
		}
		/*else
			cout << "没有找到该用户,请核实后重试!!" << endl;*/
	}
}
W_File();

}
void WithdrawMoney(double money_temp)//取钱
{
int b = 1;
while (b == 1)
{
cout << “请输入取钱用户名的身份证和取出金额->”;
cin >> number_temp >> money_temp;

	for (rsize_t i = 0; i < v1.size(); i++)
	{
		if (v1[i].renum() == number_temp)
		{
			if (p[i].over_money >= money_temp)
			{
				p[i].over_money -= money_temp;
				cout << money_temp << "元取出成功" << endl;
			}
			else
			{
				cout << "由于余额不足" << money_temp << "元" << endl << "仅成功取出" << p[i].over_money << "元" << endl;
				p[i].over_money = 0.0;
			}
			v1[i].over_money = p[i].over_money;
			v1[i].DisplayInformation();//打印
			b = 0;
			break;
		}	
		/*else
			cout << "没有找到该用户,请核实后重试!!" << endl;*/
	}
}
W_File();

}
void Find()//查询个人信息
{
cout << “请输入查询人的身份证:”;
cin >> number_temp;
for (rsize_t i = 0; i < v1.size(); i++)
{
if (v1[i].renum() == number_temp)
{
v1[i].DisplayInformation();//打印
system(“pause”);//暂停
return;
}
//else
// cout << “没有找到该用户,请核实后重试!!” << endl;
}
}
int main()
{
int choice = 0;

while (1)
{
	Mulu();//菜单
	cin >> choice;
	switch (choice)
	{
	case 1: //展示所有用户信息
	{
		system("cls");DisplayAll();  
	}break;
	case 2:  //开户
	{
		double money_temp = 0;//金额			
		 system("cls");CreateAccount(money_temp);
	}break;
	case 3://销户
	{
		system("cls");Destroy();  
	}break;
	case 4://存钱
	{
		double money_temp = 0;//金额
		system("cls"); DepoistMoney( money_temp);
	}break;
	case 5://取钱
	{
		double money_temp = 0;//金额
		system("cls");WithdrawMoney( money_temp);
	}break;
	case 6://查询个人信息
	{
		system("cls");Find();
	}break;
	default://清屏
		system("cls"); 
	break;
	}
}
	return 0;

}
上机实践:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值