银行账户管理系统c++
时间: 2023-11-18 19:44:04 浏览: 60
银行账户管理系统通常包括以下功能:
1. 新建账户:输入账户信息,包括账户名、账户类型、账户余额等,生成唯一的账户号码。
2. 存款:输入账户号码和存款金额,更新账户余额。
3. 取款:输入账户号码和取款金额,更新账户余额。
4. 转账:输入转出账户号码、转入账户号码和转账金额,更新两个账户的余额。
5. 查询余额:输入账户号码,显示该账户的余额信息。
6. 修改账户信息:输入账户号码和修改后的账户信息,更新账户信息。
7. 删除账户:输入账户号码,删除该账户信息。
以下是一个简单的银行账户管理系统的C++代码实现:
```c++
#include <iostream>
#include <string>
#include <map>
using namespace std;
// 账户类
class Account {
public:
Account(string name, string type, double balance) : m_name(name), m_type(type), m_balance(balance) { }
string getname() const {
return m_name;
}
string gettype() const {
return m_type;
}
double getbalance() const {
return m_balance;
}
void deposit(double amount) {
m_balance += amount;
}
void withdraw(double amount) {
m_balance -= amount;
}
private:
string m_name; // 账户名
string m_type; // 账户类型
double m_balance; // 账户余额
};
// 银行类
class Bank {
public:
void addAccount(Account account) {
m_accounts[getAccountNumber()] = account;
}
void deposit(string accountNumber, double amount) {
m_accounts[accountNumber].deposit(amount);
}
void withdraw(string accountNumber, double amount) {
m_accounts[accountNumber].withdraw(amount);
}
void transfer(string fromAccountNumber, string toAccountNumber, double amount) {
m_accounts[fromAccountNumber].withdraw(amount);
m_accounts[toAccountNumber].deposit(amount);
}
double getBalance(string accountNumber) const {
return m_accounts[accountNumber].getbalance();
}
void modifyAccount(string accountNumber, string name, string type, double balance) {
m_accounts[accountNumber] = Account(name, type, balance);
}
void deleteAccount(string accountNumber) {
m_accounts.erase(accountNumber);
}
private:
string getAccountNumber() {
static int accountNumber = 1001;
return to_string(accountNumber++);
}
map<string, Account> m_accounts; // 存储账户信息
};
int main() {
Bank bank;
// 新建账户
Account account1("张三", "储蓄账户", 1000);
bank.addAccount(account1);
Account account2("李四", "信用卡账户", 2000);
bank.addAccount(account2);
// 存款
bank.deposit("1001", 500);
cout << "账户1001余额:" << bank.getBalance("1001") << endl;
// 取款
bank.withdraw("1002", 1000);
cout << "账户1002余额:" << bank.getBalance("1002") << endl;
// 转账
bank.transfer("1001", "1002", 300);
cout << "账户1001余额:" << bank.getBalance("1001") << endl;
cout << "账户1002余额:" << bank.getBalance("1002") << endl;
// 修改账户信息
bank.modifyAccount("1001", "张三", "信用卡账户", 2000);
cout << "账户1001余额:" << bank.getBalance("1001") << endl;
// 删除账户
bank.deleteAccount("1002");
cout << "账户1002余额:" << bank.getBalance("1002") << endl; // 输出0,因为该账户已被删除
return 0;
}
```
阅读全文