NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <map>
#include <string>

// Enum for expense categories
enum class ExpenseCategory { GROCERIES, RENT, UTILITIES, ENTERTAINMENT, OTHER };

// Function to display expense categories
void displayExpenseCategories() {
std::cout << "Expense Categories:" << std::endl;
std::cout << "1. Groceries" << std::endl;
std::cout << "2. Rent" << std::endl;
std::cout << "3. Utilities" << std::endl;
std::cout << "4. Entertainment" << std::endl;
std::cout << "5. Other" << std::endl;
}

// Function to get expense category from user input
ExpenseCategory getExpenseCategory() {
int choice;
std::cout << "Enter the number of your expense category: ";
std::cin >> choice;

switch (choice) {
case 1:
return ExpenseCategory::GROCERIES;
case 2:
return ExpenseCategory::RENT;
case 3:
return ExpenseCategory::UTILITIES;
case 4:
return ExpenseCategory::ENTERTAINMENT;
case 5:
return ExpenseCategory::OTHER;
default:
std::cerr << "Invalid choice. Defaulting to OTHER." << std::endl;
return ExpenseCategory::OTHER;
}
}

// Struct to represent an expense
struct Expense {
std::string name;
ExpenseCategory category;
double amount;
};

// Function to get expense details from user input
Expense getExpenseDetails() {
Expense expense;
std::cout << "Enter expense name: ";
std::cin.ignore(); // Ignore newline character left in input buffer
std::getline(std::cin, expense.name);
displayExpenseCategories();
expense.category = getExpenseCategory();
std::cout << "Enter expense amount: ";
std::cin >> expense.amount;

return expense;
}

// Class to manage personal finances
class PersonalFinanceManager {
public:
// Constructor to initialize monthly income
PersonalFinanceManager(double monthlyIncome) : monthlyIncome(monthlyIncome) {}

// Function to add an expense
void addExpense() {
Expense expense = getExpenseDetails();
expenses[expense.category].push_back(expense);
}

// Function to display expenses
void displayExpenses() {
for (const auto &pair : expenses) {
std::cout << "Category: ";
switch (pair.first) {
case ExpenseCategory::GROCERIES:
std::cout << "Groceries" << std::endl;
break;
case ExpenseCategory::RENT:
std::cout << "Rent" << std::endl;
break;
case ExpenseCategory::UTILITIES:
std::cout << "Utilities" << std::endl;
break;
case ExpenseCategory::ENTERTAINMENT:
std::cout << "Entertainment" << std::endl;
break;
case ExpenseCategory::OTHER:
std::cout << "Other" << std::endl;
break;
}

for (const auto &expense : pair.second) {
std::cout << "Name: " << expense.name << ", Amount: " << expense.amount
<< std::endl;
}
}
}

// Function to display monthly income
void displayMonthlyIncome() {
std::cout << "Monthly Income: " << monthlyIncome << std::endl;
}

private:
double monthlyIncome;
std::map<ExpenseCategory, std::vector<Expense>> expenses;
};

int main() {
double monthlyIncome;
std::cout << "Enter your monthly income: ";
std::cin >> monthlyIncome;

PersonalFinanceManager financeManager(monthlyIncome);

while (true) {
std::cout << "Personal Finance Manager" << std::endl;
std::cout << "1. Add Expense" << std::endl;
std::cout << "2. Display Expenses" << std::endl;
std::cout << "3. Display Monthly Income" << std::endl;
std::cout << "4. Exit" << std::endl;

int choice;
std::cout << "Enter your choice: ";
std::cin >> choice;

switch (choice) {
case 1:
financeManager.addExpense();
break;
case 2:
financeManager.displayExpenses();
break;
case 3:
financeManager.displayMonthlyIncome();
break;
case 4:
return 0;
default:
std::cerr << "Invalid choice. Please try again." << std::endl;
}
}

return 0;
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.