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
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,银行账户管理系统是一个比较典型的应用程序,它主要用于管理银行客户的账户信息,包括账户余额、交易记录、利息计算等功能。以下是一个简单的银行账户管理系统C++代码示例: ```c++ #include <iostream> #include <string> #include <vector> using namespace std; // 定义账户类 class Account { private: string name; // 客户姓名 string account_number; // 账户号码 double balance; // 账户余额 public: Account(string name, string account_number, double balance) { this->name = name; this->account_number = account_number; this->balance = balance; } void deposit(double amount) { // 存款 balance += amount; } void withdraw(double amount) { // 取款 if (balance >= amount) { balance -= amount; } else { cout << "余额不足!" << endl; } } double get_balance() { // 获取余额 return balance; } string get_account_number() { // 获取账户号码 return account_number; } }; // 定义银行类 class Bank { private: vector<Account> accounts; // 存储所有账户信息 public: void add_account(Account account) { // 添加账户 accounts.push_back(account); } Account* find_account(string account_number) { // 查找账户 for (int i = 0; i < accounts.size(); i++) { if (accounts[i].get_account_number() == account_number) { return &accounts[i]; } } return NULL; } }; int main() { Bank bank; // 创建银行对象 // 添加账户 Account account1("张三", "10001", 1000); Account account2("李四", "10002", 2000); bank.add_account(account1); bank.add_account(account2); // 存款 Account* ptr = bank.find_account("10001"); if (ptr != NULL) { ptr->deposit(500); cout << "账户余额:" << ptr->get_balance() << endl; } // 取款 ptr = bank.find_account("10002"); if (ptr != NULL) { ptr->withdraw(1000); cout << "账户余额:" << ptr->get_balance() << endl; } return 0; } ``` 以上代码实现了一个简单的银行账户管理系统,包括账户类和银行类两个主要类,可以进行账户的添加、查找、存款、取款等操作。需要注意的是,这只是一个简单的示例代码,实际应用中还需要考虑更多的功能和安全性问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值