# rick **Repository Path**: ye-zihao123/rick ## Basic Information - **Project Name**: rick - **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-04-24 - **Last Updated**: 2025-05-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 1.My Info - English Name: Rick - Chinese Name: 叶子豪 - id:2023901697 2.Class Info Class: Customer Attributes: - name: Stores the customer's name. - savingsAccount: Stores the customer's savings account object. - checkingAccount: Stores the customer's checking account object. Methods: - Customer(const std::string& customerName, const std::string& savingsID, const std::string& checkingID, double initialBalance_saving, double initialBalance_checking): Constructor to initialize the customer's name, savings account, and checking account. - std::string getName() const: Returns the customer's name. - SavingsAccount& getSavingsAccount(): Returns the customer's savings account object. - CheckingAccount& getCheckingAccount(): Returns the customer's checking account object. - void displayAccounts() const: Displays the customer's savings and checking account information. - void viewAllTransactions() const: Displays all transactions for the customer's savings and checking accounts. - void generateCustomerReport() const: Generates and saves a report of the customer's transactions. Class: BankingSystem Attributes: - customers: Stores a vector of all customers. Methods: - std::string generateUniqueAccountID(const std::string& accountType): Generates a unique account ID. - void registerCustomer(const std::string& name, double initialBalance_saving, double initialBalance_checking): Registers a new customer and creates savings and checking accounts. - void accessCustomerAccounts(const std::string& name): Accesses the accounts of a specified customer and provides account management options. - void displayAllAccounts() const: Displays information about all customer accounts. - void generateGlobalTransactionReport() const: Generates and saves a global transaction report for all customers. - int GetChoice(int Left, int Right): Gets the user's input choice and ensures it is within the specified range. - bool name_matches(const Customer& customer, const std::string& name): Compares whether the customer's name matches the specified name. - bool id_matches(Customer& customer, const std::string& targetID): Compares whether the account ID matches the specified target ID. - void Transfer_savings(Account& target, SavingsAccount& savings):Transfer operation for savings account. - void View_transaction_history_savings(SavingsAccount& savings):View transaction history for savings account. - void Generate_bank_account_report_savings(SavingsAccount& savings):Generate bank account report for savings account. - void Deposit(CheckingAccount& checking):Deposit operation for checking account. - void Withdraw(CheckingAccount& checking):Withdrawal operation for checking account. - void Transfer_checking(CheckingAccount& checking):Transfer operation for checking account. - void View_transaction_history_checking(CheckingAccount& checking):View transaction history for checking account. - void Generate_bank_account_report_checking(CheckingAccount& checking):Generate bank account report for checking account. Class: NameMatcher Attributes: - name_to_find: Stores the customer name to be matched. Methods: - NameMatcher(std::string name): Constructor to initialize the customer name to be matched. - bool operator()(const Customer& customer) const: Overloaded function call operator to compare whether the customer's name matches the specified name. Class: IDMatcher Attributes: - id_to_find: Stores the account ID to be matched. Methods: - IDMatcher(std::string targetID): Constructor to initialize the account ID to be matched. - bool operator()(Customer& customer) const: Overloaded function call operator to compare whether the account ID matches the specified target ID. Class: Transaction Attributes: - transactionType: Stores the transaction type. - transactionAmount: Stores the transaction amount. - transactionNote: Stores the transaction note. - transactionID: Stores the transaction ID. Methods: - Transaction(const std::string& type, double amount, const std::string& note): Constructor to initialize the transaction type, amount, and note, and generate a transaction ID. - std::string getType() const: Returns the transaction type. - double getAmount() const: Returns the transaction amount. - std::string getNote() const: Returns the transaction note. - std::string getTransactionID() const: Returns the transaction ID. - std::string generateTransactionID(): Generates a unique transaction ID. Class: Account Attributes: - accountID: Stores the account ID. - accountHolder: Stores the account holder's name. - balance: Stores the account balance. - transactions: Stores all transaction records for the account. Methods: - Account(const std::string& id, const std::string& holder, double initialBalance): Constructor to initialize the account ID, holder's name, and initial balance. - ~Account(): Destructor. - std::string getAccountID() const: Returns the account ID. - std::string getAccountHolder() const: Returns the account holder's name. - double getBalance() const: Returns the account balance. - const std::vector& getTransactions() const: Returns all transaction records for the account. - void deposit(double amount, const std::string& note): Deposit operation and records the transaction. - bool withdraw(double amount, const std::string& note): Withdrawal operation and records the transaction. - bool transfer(Account& target, double amount, const std::string& note): Transfer operation and records the transaction. - void displayInfo() const: Displays account information. - void generateReport(const std::string& filename) const: Generates and saves a report of the account's transactions. - Account& operator+=(double amount): Overloaded addition assignment operator for deposit operation. - Account& operator-=(double amount): Overloaded subtraction assignment operator for withdrawal operation. Class: SavingsAccount Attributes: - Inherits from Account class, thus includes all attributes of Account. Methods: - SavingsAccount(const std::string& id, const std::string& holder, double initialBalance): Constructor to initialize the account ID, holder's name, and initial balance. - bool transfer(Account& target, double amount, const std::string& note): Transfer operation, only allows transfers to the same customer's checking account. - void displayInfo() const: Displays savings account information. Class: CheckingAccount Attributes: - Inherits from Account class, thus includes all attributes of Account. Methods: - CheckingAccount(const std::string& id, const std::string& holder, double initialBalance): Constructor to initialize the account ID, holder's name, and initial balance. - void deposit(double amount, const std::string& note): Deposit operation. - bool withdraw(double amount, const std::string& note): Withdrawal operation. - bool transfer(Account& target, double amount, const std::string& note): Transfer operation. - void displayInfo() const: Displays checking account information. 3.System Architecture namespace MiniBank { class Transaction; class Account { class SavingsAccount; (inherits from Account) class CheckingAccount; (inherits from Account) }; class Customer; class BankingSystem; For function object: { class NameMatcher; class IDMatcher; } } In the MiniBank namespace, four main classes are defined: Transaction, Account, Customer, and BankingSystem: - The Account class is the base class for all account classes, including the SavingsAccount and CheckingAccount classes.It can be used to create and manage accounts, including deposit, withdraw, and transfer operations. - The Transaction class represents a transaction record, including the transaction type, amount, note, and ID. - The Customer class represents a bank customer, including the customer's name, savings account, and checking account. - The BankingSystem class represents the bank system, including a collection of all customers, account management functions, account query functions, and global transaction report functions.It is the key to the user interface and the overall functionality of the program. - The NameMatcher and IDMatcher classes are function objects used to match customer names and account IDs. 4.How to compile and run the program To compile the program, follow these steps: 1. Create a folder named .vscode at the same level as the include and sources folders. 2. Create a tasks.json file in the .vscode folder with the following content: ``` { "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "-g", "${workspaceFolder}/sources/*.cpp", "-I${workspaceFolder}/include", "-o", "${workspaceFolderBasename}.exe" ], "group": { "kind": "build", "isDefault": true } } ] } ``` 3. Press Ctrl+Shift+B to compile the program. 4. Run the program by entering ". / program_name.exe" in the command line window. 5. Follow the prompts to register new customers, access customer accounts, view transactions, and generate reports. 5.Description of key design decisions - Generate a unique bank card number randomly 1. std::find(usedIDs.begin(), usedIDs.end(), newID) != usedIDs.end() Use the find function to determine if there is a duplicate ID, preventing duplication 2. Generate a bank card number Randomly generate the last four digits of the bank card number using random_device as the random seed, mt19937 as the random number generator, and uniform_int_distribution as the random number distribution, with a range of 1000-9999. ``` static std::vector usedIDs; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1000, 9999); ``` - Create transaction report 1. Use std::ofstream file(filename) to write transaction records to a file using the ofstream class. 2. Use file.is_open() to check if the file opened successfully. If it did, write to the file. 3. Use time_t now = std::time(nullptr) to get the current time, and tm* localTime = std::localtime(&now) to convert the time to local time. - How does the banking system store customer information and their details 1. Use std::vector customers to store customer information. 2. Initialize customer information using a constructor, and create a savings account and a checking account for the customer. 3. Use get methods to retrieve customer information. - How to find the account requested by the user and transfer funds to the target account 1. Use std::find_if function to find the account requested by the user, with IDMatcher as the matching function. 2. Use Account::transfer function to transfer funds to the target account.