# cadian **Repository Path**: nhandhn/cadian ## Basic Information - **Project Name**: cadian - **Description**: No description available - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-10 - **Last Updated**: 2025-05-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Mini Banking System ## Student Information - **Chinese Name**: 柏寒晖 - **Student ID**: 2023902792 - **English Name**: Cadian ## Project Overview This is a C++ console application simulating a banking system, developed as a course project to demonstrate object-oriented programming principles, multi-file organization, and modern C++ features. The system supports customer and account management, transactions (deposit, withdrawal, transfer), and transaction reporting, with a menu-driven interface. It is built using CMake for cross-platform compatibility and integrated with VS Code for development. ## Classes The project is organized into the following classes, each with specific responsibilities: - **Transaction** (`transaction.h`, `transaction.cpp`): - **Attributes**: - `transaction_id_`: Unique transaction ID (e.g., "T001"). - `amount_`: Transaction amount. - `source_account_`: Source account ID. - `dest_account_`: Destination account ID (empty for deposit/withdrawal). - `type_`: Transaction type (Deposit, Withdrawal, Transfer Out, Transfer In). - `note_`: Optional transaction note. - `timestamp_`: Transaction time. - **Methods**: - Getters for all attributes. - Constructor to initialize a transaction. - **Account** (`account.h`, `account.cpp`): - **Abstract base class** for bank accounts. - **Attributes**: - `account_id_`: Unique Chinese-style account ID (e.g., `6221-XXXX-XXXX-XXXX`). - `owner_name_`: Account holder's name. - `balance_`: Current balance. - `transactions_`: List of transactions. - **Methods**: - Pure virtual methods: `deposit`, `withdraw`, `transfer`. - Getters for attributes. - `add_transaction`: Records a transaction. - **SavingsAccount** (`account.h`, `account.cpp`): - **Inherits from Account**. - **Restrictions**: - No deposit or withdrawal operations. - Can only transfer to the same customer's checking account. - **Methods**: - Overrides `deposit`, `withdraw`, `transfer` to enforce restrictions. - **CheckingAccount** (`account.h`, `account.cpp`): - **Inherits from Account**. - **Features**: - Supports deposit, withdrawal, and transfers to any account. - **Methods**: - Overrides `deposit`, `withdraw`, `transfer` to allow all operations. - **Customer** (`customer.h`, `customer.cpp`): - **Attributes**: - `name_`: Customer name. - `savings_account_`: Unique pointer to a SavingsAccount. - `checking_account_`: Unique pointer to a CheckingAccount. - **Methods**: - Getters for name and accounts. - Constructor to initialize accounts. - **Bank** (`bank.h`, `bank.cpp`): - **Attributes**: - `customers_`: List of customers. - `used_account_ids_`: Tracks unique account IDs. - **Methods**: - `register_customer`: Creates a customer with savings and checking accounts. - `find_customer`, `find_account`: Locates customers or accounts by name or ID. - `display_all_accounts`: Shows all accounts. - `generate_global_transaction_report`, `generate_customer_report`, `generate_account_report`: Creates transaction reports. ## Architecture The project follows a layered architecture to ensure modularity and maintainability: - **Core Domain Layer**: `Transaction` and `Account` classes handle business logic (transactions and account operations). - **Entity Management Layer**: `Customer` class aggregates a savings and checking account pair. - **System Management Layer**: `Bank` class coordinates customer and account management, including report generation. - **User Interface Layer**: `main.cpp` provides a menu-driven console interface with input validation. ## Key Design Decisions - **Memory Management**: Used `std::unique_ptr` for `Customer` and `Account` objects to ensure automatic resource cleanup and prevent memory leaks. - **Unique Account IDs**: Implemented a random generator for Chinese-style account IDs (`62XX-YYYY-ZZZZ-AAAA`) with uniqueness verification. - **Polymorphism**: Used an abstract `Account` class with virtual methods (`deposit`, `withdraw`, `transfer`) to support different account types (SavingsAccount, CheckingAccount). - **File Organization**: Separated code into `include` (headers) and `src` (implementations), with header guards to prevent multiple inclusions. - **Report Generation**: Reused a single `generate_report` function to create global, customer, and account reports, reducing code duplication. - **CMake Integration**: Adopted CMake for cross-platform builds, with output to `build/bin` for a clean directory structure. ## File Structure