# LingcheChi **Repository Path**: chi-lingche/LingcheChi ## Basic Information - **Project Name**: LingcheChi - **Description**: Mini Banking System - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-02 - **Last Updated**: 2025-05-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Mini Banking System **Author**: 池泠澈 (Lingche Chi)\ **Student ID**: 2023901707\ **English Name**: Lingche Chi ## Overview The Mini Banking System is a C++17 console application that simulates a banking environment. It enables users to register customers, manage savings and checking accounts, perform transactions (deposits, withdrawals, and transfers), and generate transaction reports. The system enforces account-specific restrictions (e.g., no deposits or withdrawals for savings accounts) and provides a menu-driven interface with robust input validation. Built with object-oriented principles, the project emphasizes modularity, encapsulation, and clean code practices. ## Features - **Customer Management**: Register customers with unique names, each assigned a savings and checking account. - **Account Operations**: - Checking accounts support deposits, withdrawals, and transfers to any account. - Savings accounts are restricted to transfers to the same customer's checking account (no deposits or withdrawals). - **Transaction Recording**: Logs transactions with unique IDs, types (Deposit, Withdrawal, Transfer), amounts, account IDs, notes, and timestamps. - **Reports**: - **Global Transaction Report**: Exports all transactions to a file. - **Customer Report**: Exports transactions for a specific customer. - **Bank Account Report**: Exports transactions for a specific account. - **Account ID Management**: Uses predefined IDs from `account_ids.txt` or defaults (e.g., `6221-0000-0000-0000`) if the file is unavailable. - **User Interface**: Interactive menu with input validation for names (alphanumeric with spaces) and amounts. ## Compilation and Execution ### Prerequisites - A C++17-compatible compiler (e.g., `g++`). - Optional: Create `account_ids.txt` in the project directory with unique account IDs in the format `62XX-YYYY-ZZZZ-AAAA` (e.g., `6221-1234-5678-9012` for savings, `6222-1234-5678-9012` for checking). Example content: ``` 6221-1234-5678-9012 6222-1234-5678-9012 6221-9876-5432-1098 6222-9876-5432-1098 ``` If missing, the system uses default IDs, which may trigger duplicate ID warnings. ### Build Instructions 1. **Compile the Program**: Create a build directory and compile all source files: ```bash mkdir -p build g++ -std=c++17 BankingSystem.cpp Customer.cpp BankAccount.cpp Transaction.cpp -o build/banking_system ``` 2. **Run the Program**: - On Unix-like systems: ```bash ./build/banking_system ``` - On Windows: ```bash build\banking_system.exe ``` ## Class Descriptions ### `BankAccount` - **Purpose**: Manages a bank account with an ID and balance. - **Attributes**: - `accountId_` (std::string): Unique identifier (e.g., `6221-0000-0000-0000`). - `balance_` (double): Current balance. - **Methods**: - `BankAccount(const std::string& id)`: Constructor with a default ID. - `getAccountId()`: Returns the account ID. - `getBalance()`: Returns the balance. - `setAccountId(const std::string& id)`: Updates the account ID. - `deposit(double amount)`: Adds funds if positive. - `withdraw(double amount)`: Removes funds if sufficient balance exists. ### `Customer` - **Purpose**: Represents a customer with savings and checking accounts. - **Attributes**: - `name_` (std::string): Customer’s name. - `savingsAccount_` (BankAccount): Savings account instance. - `checkingAccount_` (BankAccount): Checking account instance. - **Methods**: - `Customer(const std::string& name)`: Initializes with default account IDs. - `getName()`: Returns the customer’s name. - `getSavingsAccount()`: Returns a reference to the savings account (const and non-const). - `getCheckingAccount()`: Returns a reference to the checking account (const and non-const). ### `Transaction` - **Purpose**: Records a financial transaction. - **Attributes**: - `transactionId_` (std::string): Unique ID (e.g., `T001`). - `type_` (std::string): Transaction type (Deposit, Withdrawal, Transfer). - `amount_` (double): Transaction amount. - `sourceAccountId_` (std::string): Source account ID. - `destinationAccountId_` (std::string): Destination account ID (empty for non-transfers). - `note_` (std::string): Optional note. - `timestamp_` (std::string): Transaction time. - **Methods**: - `Transaction(...)`: Initializes with all attributes. - `getTransactionId()`: Returns the transaction ID. - `getSourceAccountId()`: Returns the source account ID. - `getDestinationAccountId()`: Returns the destination account ID. - `operator<<`: Formats transaction details for output. ### `BankingSystem` - **Purpose**: Manages the banking system, including customers and transactions. - **Attributes**: - `customers_` (std::vector): List of customers. - `transactions_` (std::vector): List of transactions. - `availableIds_` (std::vectorstd::string): Pool of available account IDs. - **Methods**: - `run()`: Runs the main menu loop. - `registerCustomer()`: Registers a new customer with unique accounts. - `accessCustomer()`: Manages account operations and reports. - `displayAllAccounts()`: Lists all accounts. - `generateTransactionReport()`: Creates a global transaction report. - `findCustomer(string)`: Finds a customer by name. - `findAccount(string)`: Finds an account by ID. ## Architecture - **Modularity**: Classes are split into header (`.h`) and implementation (`.cpp`) files for maintainability. - **Encapsulation**: Private attributes are accessed via public methods, with const correctness. - **Namespace**: All code is within the `Banking` namespace. - **Data Management**: Uses `std::vector` for in-memory storage of customers and transactions. - **Error Handling**: Validates inputs and handles exceptions for critical errors. - **File Output**: Generates reports as `.txt` files with timestamps. ## Design Decisions - **Unified** `BankAccount` **Class**: Savings and checking accounts share the same class, with restrictions enforced in `BankingSystem` for simplicity. - **Centralized Transactions**: Stored in `BankingSystem` for easy reporting. - **Account ID Assignment**: Relies on `account_ids.txt` or defaults, avoiding random generation to ensure predictability. - **In-Memory Storage**: No persistence between runs, keeping the system lightweight. - **Report Filenames**: Sanitizes customer names (spaces to underscores, non-alphanumeric removed) for valid file names. ## Repository Hosted on Gitee: `https://gitee.com/chi-lingche/LingcheChi` . ## Notes - **Account Restrictions**: Enforced at the UI level; savings accounts are limited to transfers to the same customer’s checking account. - **Report Output**: Saved as `transactions__.txt` in the project directory. - **C++17 Features**: Uses modern C++ for string handling and I/O. - **Testing**: Tested for registration, transactions, and report generation with edge cases (e.g., invalid inputs). ## Troubleshooting - **Duplicate Errors**: Ensure unique customer names and a valid `account_ids.txt` with sufficient IDs. - **Missing** `account_ids.txt`: Create the file or expect default IDs with potential duplicate warnings. - **Compilation Issues**: Verify all `.cpp` and `.h` files are present and use a C++17 compiler. ## Contributing Fork the repository on Gitee, make improvements, and submit pull requests. Discuss major changes via issues first.