银行管理系统菜单驱动程序
先决条件: C/C++ 中的 Switch Case
问题陈述:
编写一个程序,使用 C++ 构建一个简单的银行管理系统,它可以执行以下操作:
- 开户口
- 存钱
- 提款
- 显示帐户
方法:以下是进行上述操作的方法:
- 开立账户:此方法从客户那里获取详细信息,例如姓名、地址、账户类型、存款和创建新账户。
// Method to Open a new account.
void Bank::open_account()
{
// Enter Name of a Customer
name = "xyz Gupta";
cout << "Enter your full name: "
<< name << endl;
// Enter City of a Customer
address = "Banglore";
cout << "Enter your address: "
<< address << endl;
// Enter Type of Account(Saving or Current)
acc_type = 'S';
cout << "Type of account you want "
<< "to open saving(S) or Current(C): "
<< acc_type << endl;
// Enter Amount to deposit
balance = 8000;
cout << "Enter the amount for deposit: "
<< balance << endl;
cout << "Account Created Successfully";
}
2.存款:存款函数是通过客户询问金额将钱存入账户。
它将询问金额并将其添加到可用余额中。
总余额=可用余额+存入金额
// Method to add balance in account
void Bank::deposit_money()
{
int Amount;
// Enter Amount to Deposit
Amount = 9500;
cout << "Enter How much money "
<< "you want to deposit: "
<< Amount << endl;
// Total_Balance = Available_Balance + Amount
balance += Amount;
cout << "\Available Balance: "
<< balance;
}
3. 显示账户:显示账户函数将显示客户的详细信息,如姓名、地址、账户类型和可用余额。
// Method to Display the details of account
void Bank::display_account()
{
cout << "Name: " << name << endl
<< "Address: " << address << endl
<< "Type: " << acc_type << endl
<< "Balance: " << balance << endl
<< endl;
}
4.提款:提款函数是通过客户询问金额从账户中提款。
它将询问金额并将其从可用余额中减去。
总余额=可用余额-提款金额
void Bank::withdraw_money()
{
float amount;
// Enter Amount to Withdraw
amount = 3200;
cout << "Enter How much money "
<< "you want to withdraw: "
<< amount << endl;
// Total_Balance = Available_Balance - Withdrawal_Amount
balance -= amount;
cout << "Available balance: "
<< balance;
}
下面是上述方法的实现:
CPP
// C++ program to implement
// Bank Management System
#include
#include
#include
#include
#include
using namespace std;
class Bank {
string name, address;
char acc_type;
float balance;
public:
void open_account();
void deposit_money();
void withdraw_money();
void display_account();
};
// Function to open the account
void Bank::open_account()
{
name = "Aman Jhurani";
cout << "Enter your full name: "
<< name << endl;
address = "Surat";
cout << "Enter your address: "
<< address << endl;
acc_type = 'S';
cout << "What type of account you want"
<< " to open saving(S) or Current(C): "
<< acc_type << endl;
balance = 8000;
cout << "Enter How much money you want to deposit: "
<< balance << endl;
cout << "Account Created Successfully";
}
// Function to deposit the account
void Bank::deposit_money()
{
int Amount;
Amount = 9500;
cout << "Enter how much money"
<< " you want to deposit: "
<< Amount << endl;
balance += Amount;
cout << "\n Available Balance: "
<< balance;
}
// Function to display the account
void Bank::display_account()
{
cout << "Name: " << name << endl
<< "Address: " << address << endl
<< "Type: " << acc_type << endl
<< "Balance: " << balance << endl
<< endl;
}
// Function to withdraw the account
void Bank::withdraw_money()
{
float amount;
amount = 3200;
cout << "Enter how much money "
<< "you want to withdraw: "
<< amount << endl;
balance -= amount;
cout << "\n Available balance: "
<< balance;
}
// Driver code
int main()
{
int choice;
// Creating Customer Object of Bank Class
Bank customer;
cout << "\n1) Open account \n\n";
// Calling open_account() function
// through customer object.
customer.open_account();
cout << "\n------------------------"
<< "-------------------------\n";
cout << "\n2) Deposit account \n\n";
// Calling deposit_money() function
// through customer object.
customer.deposit_money();
cout << "\n------------------------"
<< "-------------------------\n";
cout << "\n2) Withdraw money \n\n";
// Calling withdraw_money() function
// through customer object.
customer.withdraw_money();
cout << "\n------------------------"
<< "-------------------------\n";
cout << "\n4) Display Account \n\n";
// Calling display_account() function
// through customer object.
customer.display_account();
cout << "\n------------------------"
<< "-------------------------\n";
return 0;
}
Java
// Java program for above approach
package GeeksforGeeks;
import java.util.Scanner;
class Bank
{
private String name;
private String address;
private char acc_type;
private float balance;
// Constructor of class Bank
Bank(){
// Initializing values 0 for float
// and null for String and character
name=" ";
address=" ";
acc_type=' ';
balance=0;
}
// Method to open the account
void open_account()
{
name = "Aman Jhurani";
System.out.println("Enter your full name: ");
address = "Surat";
System.out.println("Enter your address: ");
acc_type = 'S';
System.out.println("What type of
account you want");
System.out.println(" to open saving(S)
or Current(C): ");
balance = 8000;
System.out.println("Enter How much money
you want to deposit: ");
System.out.println("Account Created
Successfully");
}
// Method to deposit the account
void deposit_money()
{
int Amount;
Amount = 9500;
System.out.println( "Enter how much money you
want to deposit: "+ Amount);
balance += Amount;
System.out.println( "\n Available Balance: "
+ balance);
}
// Method to display the account
void display_account()
{
System.out.println( "Name: " +name);
System.out.println("Address: "+ address);
System.out.println("Type: "+acc_type);
System.out.println("Balance: " +balance);
}
// Method to withdraw the account
void withdraw_money()
{
float amount;
amount = 3200;
System.out.println("Enter how much money
you want to withdraw: "+amount );
balance -= amount;
System.out.println("\n Available balance: "
+ balance);
}
// Driver code
public static void main(String[] args)
{
int choice;
// Creating Customer Object of Bank Class
Bank customer=new Bank();
System.out.println("\n1) Open account \n");
// Calling open_account() method
// through customer object.
customer.open_account();
System.out.println("\n----------------------
---------------------------\n");
System.out.println("\n2) Deposit account \n");
// Calling deposit_money() method
// through customer object.
customer.deposit_money();
System.out.println("\n----------------------
---------------------------\n");
System.out.println("\n3) Withdraw money \n\n");
// Calling withdraw_money() method
// through customer object.
customer.withdraw_money();
System.out.println("\n---------------
----------------------------------\n");
System.out.println("\n4) Display Account \n\n");
// Calling display_account() method
// through customer object.
customer.display_account();
System.out.println("\n------------------------
-------------------------\n");
}
}
//This code is contributed by sahilnaik2712
输出
1) Open account
Enter your full name: Aman Jhurani
Enter your address: Surat
What type of account you want to open saving(S) or Current(C): S
Enter How much money you want to deposit: 8000
Account Created Successfully
-------------------------------------------------
2) Deposit account
Enter how much money you want to deposit: 9500
Available Balance: 17500
-------------------------------------------------
2) Withdraw money
Enter how much money you want to withdraw: 3200
Available balance: 14300
-------------------------------------------------
4) Display Account
Name: Aman Jhurani
Address: Surat
Type: S
Balance: 14300
-------------------------------------------------