This example will include basic functionalities such as creating an account, depositing funds, withdrawing funds, and checking the balance. Keep in mind that this is a basic tutorial and doesn’t cover all aspects of a real-world banking application (e.g., security, concurrency, database integration).
#include <iostream>
#include <string>
using namespace std;
class BankAccount {
// Define a class representing a bank account
private:
string accountNumber; // Stores the account number
string holderName; // Stores the name of the account holder
double balance; // Stores the account balance
public:
BankAccount(string accountNumber, string holderName) {
// Constructor to initialize the account with account number and holder name
this->accountNumber = accountNumber; // Initialize account number
this->holderName = holderName; // Initialize holder name
this->balance = 0.0; // Initialize balance to 0
}
void deposit(double amount) {
// Method to deposit funds into the account
balance += amount; // Add the deposited amount to the balance
cout << amount << " deposited successfully." << endl; // Print a success message
}
void withdraw(double amount) {
// Method to withdraw funds from the account
if (balance >= amount) { // Check if the balance is sufficient for withdrawal
balance -= amount; // Subtract the withdrawal amount from the balance
cout << amount << " withdrawn successfully." << endl; // Print a success message
} else {
cout << "Insufficient funds." << endl; // Print an error message if balance is insufficient
}
}
double getBalance() {
// Method to get the current balance of the account
return balance; // Return the current balance
}
string getAccountNumber() {
// Method to get the account number
return accountNumber; // Return the account number
}
string getHolderName() {
// Method to get the holder name
return holderName; // Return the holder name
}
};
int main() {
// Main function for the banking application
cout << "Welcome to Our Bank!" << endl; // Display a welcome message
string accountNumber, holderName;
cout << "Enter your account number: ";
cin >> accountNumber; // Prompt user to enter account number
cout << "Enter your name: ";
cin >> holderName; // Prompt user to enter their name
BankAccount account(accountNumber, holderName); // Create a BankAccount object
int choice;
// Display a menu for banking operations
while (true) {
cout << "\n1. Deposit" << endl;
cout << "2. Withdraw" << endl;
cout << "3. Check Balance" << endl;
cout << "4. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice; // Read user's choice
switch (choice) {
case 1: // If user chooses deposit
double depositAmount;
cout << "Enter deposit amount: ";
cin >> depositAmount; // Read deposit amount
account.deposit(depositAmount); // Call deposit method
break;
case 2: // If user chooses withdraw
double withdrawAmount;
cout << "Enter withdrawal amount: ";
cin >> withdrawAmount; // Read withdrawal amount
account.withdraw(withdrawAmount); // Call withdraw method
break;
case 3: // If user chooses check balance
cout << "Account Holder: " << account.getHolderName() << endl;
cout << "Account Number: " << account.getAccountNumber() << endl;
cout << "Balance: " << account.getBalance() << endl;
break;
case 4: // If user chooses exit
cout << "Thank you for using our bank!" << endl;
return 0; // Exit the program
default: // If user enters an invalid choice
cout << "Invalid choice. Please try again." << endl;
}
}
return 0;
}
This code sets up a basic banking application where users can deposit, withdraw, and check their balance. The BankAccount
class represents a bank account with attributes such as account number, holder name, and balance. The main
method in the BankingApplication
class serves as the entry point for the application. It prompts the user for their account number and name, creates a BankAccount
object, and then presents a menu for performing banking operations.
Welcome to DevTechTutor.com, your ultimate resource for mastering web development and technology! Whether you're a beginner eager to dive into coding or an experienced developer looking to sharpen your skills, DevTechTutor.com is here to guide you every step of the way. Our mission is to make learning web development accessible, engaging, and effective.