Sure, here are the initial instructions:
Create a program that allows a user to store expenses in different categories such as restaurants, groceries, transportation, and entertainment. The program should allow the user to add, view, update, and delete expenses for each category. Additionally, the program should allow the user to calculate the total amount spent in each category and display a list of the top 5 most frequent categories based on the amount spent.
The program should be built using C++11. You may assume that the user will enter data in the following format:
Category:AMOUNT
For example, to add an expense for a restaurant, the user would enter:
restaurant:10.99
To add an expense for groceries, the user would enter:
groceries:34.50
You may assume that the user will add expenses for each category in a separate line until the user chooses to display the list of expenses. The program should also allow the user to select a category and display all the expenses for that category.
When displaying a list of expenses for a category, the program should display the category name, the amount spent, and the number of expenses for that category.
To calculate the total amount spent in each category, the program should maintain a separate data structure for each category that stores the sum of all expenses for that category.
To determine the top 5 most frequent categories based on the amount spent, the program should sort the list of categories by the amount spent in descending order, and return the first 5 elements of that list.
Your program should include the following functions:
- newExpense: This function allows the user to add a new expense for a specific category. It should store the category, amount, and current date in a data structure and update the total amount spent for that category accordingly.
- displayExpenses: This function should display a list of all expenses for a specific category. It should display the category name, the amount spent, and the number of expenses for that category.
- updateExpense: This function should allow the user to update an existing expense in a specific category. It should prompt the user to enter the new amount, compare it with the current amount, and only accept the new amount if it is greater than the current amount.
- deleteExpense: This function should allow the user to delete an existing expense for a specific category.
- displayTotalAmountSpent: This function should display the total amount spent in each category.
- displayTopCategories: This function should display the top 5 most frequent categories based on the amount spent, sorted in descending order by the amount spent.
- exitProgram: This function should terminate the program and return control to the operating system.
You may assume that the user will enter valid category names and amounts. Additionally, you may assume that the user will enter data in a reasonable format. If the user enters data that is not valid, or in an unreasonable format, you should provide an error message and allow the user to correct the input.