#include <iostream> #include <cstring> class Person { private: std::string firstName; std::string lastName; public: Person(const std::string& fName, const std::string& lName) : firstName(fName), lastName(lName) {} std::string getName() const { return firstName + " " + lastName; } }; class BankAccount { private: std::string creationDate; double balance; Person owner; struct Operation { std::string name; std::string date; double amount; } operations[10]; int numOperations; public: BankAccount(const std::string& cDate, double initialBalance, const Person& accountOwner) : creationDate(cDate), balance(initialBalance), owner(accountOwner), numOperations(0) {} void deposit(double amount, const std::string& date, const std::string& operationName) { if (amount <= 0) { std::cout << "Invalid amount.\n"; return; } if (numOperations == 10) { // shift the operations array to make room for the new operation for (int i = 0; i < 9; ++i) { operations[i] = operations[i+1]; } numOperations--; } balance += amount; operations[numOperations++] = { operationName, date, amount }; } void withdraw(double amount, const std::string& date, const std::string& operationName) { if (amount <= 0) { std::cout << "Invalid amount.\n"; return; } if (balance < amount) { std::cout << "Insufficient funds.\n"; return; } if (numOperations == 10) { // shift the operations array to make room for the new operation for (int i = 0; i < 9; ++i) { operations[i] = operations[i+1]; } numOperations--; } balance -= amount; operations[numOperations++] = { operationName, date, -amount }; } void printOperations() const { std::cout << "Last 10 operations:\n"; for (int i = numOperations-1; i >= 0; --i) { const Operation& op = operations[i]; std::cout << op.date << " " << op.name << " " << op.amount << "\n"; } } void printBalance() const { std::cout << "Current balance: " << balance << "\n"; } }; int main() { Person p("John", "Doe"); BankAccount b("2022-01-01", 1000, p); b.deposit(500, "2022-01-02", "Salary"); b.deposit(200, "2022-01-03", "Bonus"); b.withdraw(300, "2022-01-04", "Rent"); b.printBalance(); b.printOperations(); return 0; }