实现一个银行账目自动存取款系统,包括的功能有:1查询余额2存钱3取钱4退出
时间: 2023-04-23 22:02:32 浏览: 82
好的,以下是实现一个银行账目自动存取款系统的功能:
1. 查询余额:用户可以通过输入账号和密码来查询自己的账户余额。
2. 存钱:用户可以输入存款金额,系统会自动将金额加入到用户的账户余额中。
3. 取钱:用户可以输入取款金额,系统会自动从用户的账户余额中扣除相应的金额。
4. 退出:用户可以选择退出系统,结束操作。
以上就是银行账目自动存取款系统的基本功能。
相关问题
用C++NurHar: 设计一个Bank类,实现银行某账户资金往来账目管理。程序要求完成以下操作。 NurHar: 1, 创建账户:包括账号,创建日期,余额(创建账户时存入的钱数) NurHar: 2存钱:执行存钱操作,并记录存钱日期和存钱数目 NurHar: 3,取钱:执行取钱操作,并记录取钱日期和取钱数目。 NurHar: 4,查询交易明细:查询近一个月的账户交易记录
好的,下面是Bank类的设计及实现代码:
```cpp
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
class Account {
public:
Account(string number, double balance) : number(number), balance(balance) {
time_t now = time(nullptr);
created = ctime(&now);
}
void deposit(double amount) {
balance += amount;
time_t now = time(nullptr);
string date = ctime(&now);
transactions.push_back("Deposit of " + to_string(amount) + " on " + date);
}
void withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
time_t now = time(nullptr);
string date = ctime(&now);
transactions.push_back("Withdrawal of " + to_string(amount) + " on " + date);
} else {
cout << "Insufficient balance!" << endl;
}
}
void showTransactions() {
time_t now = time(nullptr);
string endDate = ctime(&now);
string startDate = ctime(&now - 30 * 24 * 60 * 60);
cout << "Transactions from " << startDate << "to " << endDate << endl;
for (auto transaction : transactions) {
if (transaction.compare(11, 24, startDate) >= 0 && transaction.compare(11, 24, endDate) <= 0) {
cout << transaction << endl;
}
}
}
void showDetails() {
cout << "Account number: " << number << endl;
cout << "Created on: " << created;
cout << "Balance: " << balance << endl;
}
private:
string number;
string created;
double balance;
vector<string> transactions;
};
class Bank {
public:
void createAccount() {
string number;
double balance;
cout << "Enter account number: ";
cin >> number;
cout << "Enter initial balance: ";
cin >> balance;
Account account(number, balance);
accounts.push_back(account);
cout << "Account created successfully!" << endl;
}
void deposit() {
string number;
double amount;
cout << "Enter account number: ";
cin >> number;
cout << "Enter amount to deposit: ";
cin >> amount;
for (auto& account : accounts) {
if (account.number == number) {
account.deposit(amount);
cout << "Deposit successful!" << endl;
return;
}
}
cout << "Account not found!" << endl;
}
void withdraw() {
string number;
double amount;
cout << "Enter account number: ";
cin >> number;
cout << "Enter amount to withdraw: ";
cin >> amount;
for (auto& account : accounts) {
if (account.number == number) {
account.withdraw(amount);
return;
}
}
cout << "Account not found!" << endl;
}
void showTransactions() {
string number;
cout << "Enter account number: ";
cin >> number;
for (auto& account : accounts) {
if (account.number == number) {
account.showTransactions();
return;
}
}
cout << "Account not found!" << endl;
}
void showDetails() {
string number;
cout << "Enter account number: ";
cin >> number;
for (auto& account : accounts) {
if (account.number == number) {
account.showDetails();
return;
}
}
cout << "Account not found!" << endl;
}
private:
vector<Account> accounts;
};
int main() {
Bank bank;
int choice;
while (true) {
cout << "1. Create account" << endl;
cout << "2. Deposit" << endl;
cout << "3. Withdraw" << endl;
cout << "4. Show transactions" << endl;
cout << "5. Show details" << endl;
cout << "6. Exit" << endl;
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1:
bank.createAccount();
break;
case 2:
bank.deposit();
break;
case 3:
bank.withdraw();
break;
case 4:
bank.showTransactions();
break;
case 5:
bank.showDetails();
break;
case 6:
return 0;
default:
cout << "Invalid choice!" << endl;
}
}
}
```
Bank类包含了创建账户、存钱、取钱、查询交易明细、查询账户详情等操作。每个账户有一个账号、创建日期、余额和交易记录,交易记录包含了交易日期、交易类型和交易金额。当执行存钱或取钱操作时,会记录一条交易记录。查询交易明细时,会按照交易日期筛选出近一个月的交易记录并输出。查询账户详情时,会输出账户的账号、创建日期和余额。
在main函数中,我们创建了一个Bank对象,并提供了一个简单的菜单供用户选择操作。用户可以输入数字来选择相应的操作,或输入6来退出程序。
用c++设计一个Bank类,实现银行某账户的资金往来账目管理。程序要求: 1)创建账户:包括账号、创建日期、余额 (创建账户时存入的钱数)。 2)存钱:执行存钱操作,并记录存钱日期和存钱数目。 3)取钱:执行取钱操作,并记录取钱日期和取钱数目。
好的,我会尽力回答你的问题。以下是一个简单的 C++ Bank 类的实现,实现了银行账户的资金往来账目管理:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
class Bank {
private:
string account; // 账号
string create_date; // 创建日期
double balance; // 余额
vector< pair<time_t, double> > history; // 存储历史交易记录
public:
Bank(string account, string create_date, double balance) : account(account), create_date(create_date), balance(balance) {}
// 存钱
void deposit(double amount) {
balance += amount;
history.push_back(make_pair(time(NULL), amount));
cout << "Deposit success, current balance: " << balance << endl;
}
// 取钱
bool withdraw(double amount) {
if (balance < amount) {
cout << "Withdraw failed, not enough balance!" << endl;
return false;
}
balance -= amount;
history.push_back(make_pair(time(NULL), -amount));
cout << "Withdraw success, current balance: " << balance << endl;
return true;
}
// 打印历史交易记录
void print_history() {
cout << "Transaction history of account " << account << ":" << endl;
for (auto trans : history) {
tm* tm_time = localtime(&trans.first);
cout << asctime(tm_time) << " ";
if (trans.second > 0) {
cout << "Deposit: " << trans.second;
} else {
cout << "Withdraw: " << -trans.second;
}
cout << endl;
}
}
};
int main() {
Bank account("123456789", "2022-11-11", 5000);
account.deposit(1000);
account.withdraw(2000);
account.withdraw(7000);
account.print_history();
return 0;
}
```
在这个 Bank 类中,我们定义了四个私有成员变量:账号、创建日期、余额以及历史交易记录,其中历史交易记录用了一个 vector 来存储,每条记录包括交易时间和交易金额。
类中有三个公有成员函数,分别为存钱、取钱和打印历史交易记录。存钱和取钱的实现比较简单,只需要修改余额和添加一条历史交易记录即可。在取钱时,需要先判断余额是否足够。打印历史交易记录则遍历历史记录 vector,并根据交易金额的正负来判断是存款还是取款。
在 main 函数中,我们创建了一个账户,并进行了存钱、取钱和打印历史交易记录的操作,最后输出如下:
```
Deposit success, current balance: 6000
Withdraw success, current balance: 4000
Withdraw failed, not enough balance!
Transaction history of account 123456789:
Tue Nov 15 22:42:38 2022 Deposit: 1000
Tue Nov 15 22:42:38 2022 Withdraw: 2000
```
希望能对你有所帮助!
相关推荐
![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)