Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <ctime>
- #include <algorithm>
- #include <windows.h>
- using namespace std;
- struct Transaction {
- string category;
- double amount;
- };
- struct ExpenseCategory {
- string category;
- double totalAmount;
- };
- bool compareExpenses(const Transaction& a, const Transaction& b) {
- return a.amount > b.amount;
- }
- bool compareExpenseCategories(const ExpenseCategory& a, const ExpenseCategory& b) {
- return a.totalAmount > b.totalAmount;
- }
- class PersonalFinanceManager {
- private:
- vector<double> wallets;
- vector<Transaction> transactions;
- public:
- void addWallet(double initialAmount) {
- wallets.push_back(initialAmount);
- }
- void deposit(int walletIndex, double amount) {
- wallets[walletIndex] += amount;
- }
- void addExpense(const string& category, double amount) {
- Transaction transaction;
- transaction.category = category;
- transaction.amount = amount;
- transactions.push_back(transaction);
- }
- void generateReports() {
- time_t now = time(nullptr);
- tm* currentDate = localtime(&now);
- ofstream file;
- if (currentDate->tm_mday < 10 && (currentDate->tm_mon + 1) < 10 ) {
- string filename = "reports_" +
- to_string(currentDate->tm_mday) +
- to_string(currentDate->tm_mon + 1) +
- to_string(currentDate->tm_year + 1900) +
- ".txt";
- file.open(filename);
- }
- // Generate daily report
- file << "Отчёт за день (" << currentDate->tm_mday << "." << currentDate->tm_mon + 1 << "." << currentDate->tm_year + 1900 << "):\n";
- double totalExpenses = 0.0;
- for (const auto& transaction : transactions) {
- totalExpenses += transaction.amount;
- }
- file << "Всего затрат: " << totalExpenses << "\n\n";
- // Generate weekly report
- file << "Отчёт за неделю:\n";
- double totalExpensesWeek = 0.0;
- for (const auto& transaction : transactions) {
- totalExpensesWeek += transaction.amount;
- }
- file << "Всего затрат: " << totalExpensesWeek << "\n";
- // Top 3 expenses of the week
- sort(transactions.begin(), transactions.end(), compareExpenses);
- file << "Топ 3 затрат:\n";
- for (int i = 0; i < 3 && i < transactions.size(); ++i) {
- file << i + 1 << ". Категория: " << transactions[i].category << ", Сумма: " << transactions[i].amount << "\n";
- }
- file << "\n";
- // Top 3 expense categories of the week
- vector<ExpenseCategory> expenseCategories;
- for (const auto& transaction : transactions) {
- auto it = find_if(expenseCategories.begin(), expenseCategories.end(), [&](const ExpenseCategory& ec) {
- return ec.category == transaction.category;
- });
- if (it != expenseCategories.end()) {
- it->totalAmount += transaction.amount;
- } else {
- ExpenseCategory ec;
- ec.category = transaction.category;
- ec.totalAmount = transaction.amount;
- expenseCategories.push_back(ec);
- }
- }
- sort(expenseCategories.begin(), expenseCategories.end(), compareExpenseCategories);
- file << "Топ 3 затратных категорий:\n";
- for (int i = 0; i < 3 && i < expenseCategories.size(); ++i) {
- file << i + 1 << ". Категория: " << expenseCategories[i].category << ", Сумма: " << expenseCategories[i].totalAmount << "\n";
- }
- file << "\n";
- // Generate monthly report
- file << "Отчёт за месяц (" << currentDate->tm_mon + 1 << "." << currentDate->tm_year + 1900 << "):\n";
- double totalExpensesMonth = 0.0;
- for (const auto& transaction : transactions) {
- totalExpensesMonth += transaction.amount;
- }
- file << "Всего затрат: " << totalExpensesMonth << "\n\n";
- // Top 3 expenses of the month
- file << "Топ 3 затратных категорий за месяц:\n";
- sort(transactions.begin(), transactions.end(), compareExpenses);
- for (int i = 0; i < 3 && i < transactions.size(); ++i) {
- file << i + 1 << ". Категория: " << transactions[i].category << ", Сумма: " << transactions[i].amount << "\n";
- }
- file << "\n";
- // Top 3 expenses of the month
- file << "Топ 3 затрат за месяц:\n";
- for (int i = 0; i < 3 && i < transactions.size(); ++i) {
- file << i + 1 << ". Категория: " << transactions[i].category << ", Сумма: " << transactions[i].amount << "\n";
- }
- file << "\n";
- // Top 3 expense categories of the month
- file << "Топ 3 категорий за месяц:\n";
- sort(expenseCategories.begin(), expenseCategories.end(), compareExpenseCategories);
- for (int i = 0; i < 3 && i < expenseCategories.size(); ++i) {
- file << i + 1 << ". Категория: " << expenseCategories[i].category << ", Сумма: " << expenseCategories[i].totalAmount << "\n";
- }
- file << "\n";
- // Close the file
- file.close();
- }
- };
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- PersonalFinanceManager manager;
- // Add wallets
- manager.addWallet(1000.0);
- manager.addWallet(500.0);
- // Deposit into wallets
- manager.deposit(0, 200.0);
- manager.deposit(1, 100.0);
- // Add expenses
- manager.addExpense("Еда", 50.0);
- manager.addExpense("Транспорт", 20.0);
- manager.addExpense("Одежда", 100.0);
- manager.addExpense("Аренда", 500.0);
- manager.addExpense("Инструменты", 80.0);
- manager.addExpense("Развлечения", 60.0);
- manager.addExpense("Еда", 30.0);
- manager.addExpense("Одежда", 200.0);
- // Generate reports
- manager.generateReports();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement