我想要一个银行管理系统的C++代码
时间: 2024-04-08 21:32:32 浏览: 22
好的,下面是一个简单的银行管理系统的C++代码示例:
```cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Account {
private:
string accountNumber;
string accountHolder;
float balance;
public:
Account(string number, string holder, float initialBalance) {
accountNumber = number;
accountHolder = holder;
balance = initialBalance;
}
string getAccountNumber() {
return accountNumber;
}
string getAccountHolder() {
return accountHolder;
}
float getBalance() {
return balance;
}
void deposit(float amount) {
balance += amount;
cout << "Deposit of $" << amount << " successful." << endl;
}
void withdraw(float amount) {
if (balance >= amount) {
balance -= amount;
cout << "Withdrawal of $" << amount << " successful." << endl;
} else {
cout << "Insufficient balance." << endl;
}
}
};
int main() {
vector<Account> accounts;
// 创建两个账户
Account account1("123456789", "John Smith", 1000.0);
Account account2("987654321", "Jane Doe", 500.0);
// 将账户添加到账户列表中
accounts.push_back(account1);
accounts.push_back(account2);
// 显示账户信息
for (int i = 0; i < accounts.size(); i++) {
cout << "Account Number: " << accounts[i].getAccountNumber() << endl;
cout << "Account Holder: " << accounts[i].getAccountHolder() << endl;
cout << "Balance: $" << accounts[i].getBalance() << endl;
cout << endl;
}
// 对其中一个账户进行存款和取款操作
accounts[0].deposit(500.0);
accounts[1].withdraw(200.0);
// 显示更新后的账户信息
for (int i = 0; i < accounts.size(); i++) {
cout << "Account Number: " << accounts[i].getAccountNumber() << endl;
cout << "Account Holder: " << accounts[i].getAccountHolder() << endl;
cout << "Balance: $" << accounts[i].getBalance() << endl;
cout << endl;
}
return 0;
}
```
这是一个简单的银行管理系统代码示例,演示了如何创建账户对象、进行存款和取款操作,并显示账户信息。请注意,这只是一个基本示例,实际的银行管理系统可能需要更多功能和安全性的考虑。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)