# vernon **Repository Path**: vernonchenyili/vernon ## Basic Information - **Project Name**: vernon - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-07 - **Last Updated**: 2025-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Mini Banking System ## Student Information - Chinese Name: 陈亦力 - Student ID: 2023905494 - English Name: vernon ## Project Overview This is a C++ console application that simulates a banking system with multiple account types, transactions, and reporting capabilities. It allows users to manage customer accounts, perform deposits and withdrawals, make transfers, and generate transaction reports. ## Project Architecture ### Class Design #### Account (Abstract Base Class) **Attributes:** - `accountId` (string): Unique identifier for the account - `ownerName` (string): Name of the account owner - `balance` (double): Current account balance - `transactions` (vector>): History of transactions for this account **Methods:** - `Account(const string&, const string&, double)`: Constructor with account ID, owner name, and initial balance - `getAccountId()`, `getOwnerName()`, `getBalance()`: Getter methods - `getAccountType()`, `canDeposit()`, `canWithdraw()`: Pure virtual methods defining account behavior - `addTransaction(shared_ptr)`: Adds a transaction to the account history - `getTransactions()`: Returns all transactions for this account - `deposit()`, `withdraw()`, `transfer()`: Virtual methods for transaction operations #### SavingsAccount (Derived Class) **Attributes:** - Inherits all attributes from Account base class **Methods:** - `SavingsAccount(const string&, const string&, double)`: Constructor - `getAccountType()`: Returns "Savings Account" - `canDeposit()`: Returns false (savings accounts cannot deposit directly) - `canWithdraw()`: Returns false (savings accounts cannot withdraw directly) - `transfer()`: Overridden to only allow transfers to the same customer's checking account #### CheckingAccount (Derived Class) **Attributes:** - Inherits all attributes from Account base class **Methods:** - `CheckingAccount(const string&, const string&, double)`: Constructor - `getAccountType()`: Returns "Checking Account" - `canDeposit()`: Returns true (checking accounts can deposit) - `canWithdraw()`: Returns true (checking accounts can withdraw) - `transfer()`: Overridden to allow transfers to any account #### Transaction **Attributes:** - `transactionId` (string): Unique identifier for the transaction - `type` (TransactionType): Type of transaction (deposit, withdraw, transfer) - `sourceAccountId` (string): ID of the source account - `destinationAccountId` (string): ID of the destination account (for transfers) - `amount` (double): Transaction amount - `note` (string): Optional note for the transaction - `timestamp` (time_t): When the transaction occurred **Methods:** - Two constructors for different transaction types - `getTransactionId()`, `getType()`, `getSourceAccountId()`, etc.: Getter methods - `getTypeAsString()`: Returns transaction type as a readable string - `getFormattedDate()`: Returns formatted timestamp #### Customer **Attributes:** - `name` (string): Customer name - `savingsAccount` (shared_ptr): Customer's savings account - `checkingAccount` (shared_ptr): Customer's checking account **Methods:** - `Customer(const string&)`: Constructor with customer name - `getName()`, `getSavingsAccount()`, `getCheckingAccount()`: Getter methods - `setSavingsAccount()`, `setCheckingAccount()`: Setter methods - `getAllAccounts()`: Returns both accounts as a vector - `getAllTransactions()`: Returns all transactions from all accounts #### BankSystem **Attributes:** - `customers` (vector>): All customers in the system - `transactions` (vector>): All transactions in the system - `randomGenerator` (mt19937): Random number generator for account IDs - `transactionCounter` (int): Counter for generating transaction IDs **Methods:** - `BankSystem()`: Constructor initializing the random generator and transaction counter - `generateAccountId()`: Generates Chinese-style bank account numbers (private) - `isAccountIdUnique()`: Checks if a generated ID is unique (private) - `createTransaction()`: Creates and records a new transaction (private) - `findAccountById()`: Finds an account by its ID (public) - `registerCustomer()`: Registers a new customer with accounts - `findCustomerByName()`, `customerExists()`: Customer lookup methods - `getAllAccounts()`, `getAllSavingsAccounts()`, `getAllCheckingAccounts()`: Account access methods - `deposit()`, `withdraw()`, `transfer()`: Transaction operations - `generateGlobalTransactionReport()`, `generateCustomerReport()`, `generateAccountReport()`: Reporting methods - `getTotalBalance()`, `getTotalCustomerCount()`, `getTotalAccountCount()`: Summary methods #### BankUI **Attributes:** - `bankSystem` (shared_ptr): Reference to the bank system **Methods:** - `run()`: Main program loop - Menu methods: `showMainMenu()`, `registerNewCustomer()`, `accessCustomerAccounts()`, etc. - Account operation methods: `depositToAccount()`, `withdrawFromAccount()`, `transferFromAccount()`, etc. - Helper methods: `displayTransactions()`, `waitForEnter()` ### Design Decisions 1. **Interface Design**: Used the abstract base class `Account` to define an interface that all account types must implement, enforcing consistent behavior. 2. **Memory Management**: Used smart pointers (`std::shared_ptr`) to manage object lifetimes and prevent memory leaks. 3. **Encapsulation**: All class data members are private and accessed through public interfaces, enhancing data security and abstraction. 4. **Inheritance and Polymorphism**: Used inheritance and virtual functions to implement polymorphic behavior, allowing account types to have different behaviors. 5. **Separation of Concerns**: Separated UI layer from business logic, making the system more maintainable and extensible. 6. **Transaction Recording**: All financial operations create Transaction objects that are stored both at the account level and globally. 7. **Account Restrictions**: Implemented the required restrictions - savings accounts can only transfer to the same customer's checking account, and only checking accounts can deposit/withdraw. 8. **Public API Design**: Made `findAccountById` public to allow the UI layer to access account information directly when needed for operations and displays. ## Compilation and Execution ### Compilation Command ```bash g++ -std=c++11 main.cpp BankUI.cpp BankSystem.cpp Customer.cpp Account.cpp Transaction.cpp -o bank ``` Or simply use the provided Makefile: ```bash make ``` ### Execution Command ```bash ./bank ``` ## System Features 1. Customer Registration - Creates a new customer with both savings and checking accounts - Generates unique Chinese-style account numbers 2. Customer Account Access - View account information - Access specific accounts for transactions - View transaction history - Generate reports 3. Account Operations - Deposit funds (checking accounts only) - Withdraw funds (checking accounts only) - Transfer funds between accounts (with restrictions) 4. Banking Summary - Display all accounts in the system - View total balances and customer counts 5. Reporting - Generate global transaction reports - Generate customer-specific reports - Generate account-specific reports ## Account Restrictions - Savings accounts cannot directly deposit or withdraw - Savings accounts can only transfer to the same customer's checking account - Checking accounts can deposit, withdraw, and transfer to any account