Coders Packet

Finance Tracker Using C++

By Abhishek Gupta

This program provides a simple and interactive way for users to record and manage their financial transactions.

This code represents a finance tracker application, facilitating users to manage their monetary transactions. 

Here’s a detailed explanation:

1. Header Files & Namespace:
- The program includes three headers: for input-output operations, for dynamic array handling, and for managing string data types.
- The line using namespace std; is a directive to use the standard namespace, which avoids the need to write std:: before standard library types and functions.

2. Transaction Struct:
- Defines the blueprint of a monetary transaction.
- Description: A string describing the transaction.
- amount: A double representing the monetary value of the transaction.
- date: A string denoting the date of the transaction.
- type: A string indicating whether the transaction is an "Income" or an "Expense".

3. Finance_track Class:

- Private Member:
- Transactions: A vector storing all the transactions of type Transaction.

- Public Methods:
- addTransaction(): Accepts a Transaction object by reference and adds it to the transactions vector.
- DisplayTransactions (): Iterates over the transactions vector, displaying details of each transaction to the console.
- getTotalBalance(): Calculates the total sum of amounts from all transactions in the transactions vector and returns it.

4. Main Function:
- An instance of the Finance_track class named tracker is created.
- A menu is repeatedly presented to the user offering four options: adding a transaction, displaying all transactions, viewing the total balance, and exiting the program.

- The user's menu choice is captured in the variable choice.

- The switch statement handles the user's choice:
1. Add Transaction:
- A temporary Transaction object named transaction is created.
The user is prompted to provide details of the transaction (description, amount, date, and type).
- cin. ignore() ensures any leftover newline characters from previous inputs are discarded, ensuring getline works correctly.
- The filled transaction object is passed to addTransaction() to add it to the transactions vector.
2. Display All Transactions:
- Calls displayTransactions() to show all recorded transactions.
3. Display Total Balance:
- Calls getTotalBalance() to calculate and display the total balance.
4. Exit:
- Prints an exit message and exits the loop.
- Any other number results in a message indicating an invalid choice.

 

5. Looping:
- The do-while loop keeps the program running, continuously displaying the menu until the user chooses to exit (by entering 4).

6. Program Termination:
- The program finishes by returning 0, which signifies successful completion.

output

Overall, this program provides a simple and interactive way for users to record and manage their financial transactions.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Abhishek Gupta (abhishekgupta02)

Download packets of source code on Coders Packet