0% found this document useful (0 votes)
26 views4 pages

Assignment 2 - My Expense Buddy

The assignment involves creating a program called 'My Expense Buddy' to help track weekly expenses against a budget. It requires the use of conditional statements, looping constructs, and file I/O in C++ to input, validate, and analyze daily expenses. The program will provide insights based on the user's spending patterns and budget comparisons.

Uploaded by

maazbindawood131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Assignment 2 - My Expense Buddy

The assignment involves creating a program called 'My Expense Buddy' to help track weekly expenses against a budget. It requires the use of conditional statements, looping constructs, and file I/O in C++ to input, validate, and analyze daily expenses. The program will provide insights based on the user's spending patterns and budget comparisons.

Uploaded by

maazbindawood131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 2

Programming Fundamentals

Due Date: 11-Apr-2025

Total Marks: 40

🧾 Assignment: My Expense Buddy – Personal Weekly Expense


Analyzer

You are building a weekly expense analyzer for yourself, a student who wants
to keep track of daily spending. You often find it difficult to remember how
much you’ve spent throughout the week and whether you’ve stayed within
your budget. So, you're developing a simple program called “My Expense
Buddy” to track your weekly expenses, compare them with your set budget,
and display insights.

🎯 Assignment Objectives

 Practice using conditional statements (if, if-else, conditional


operator).

 Apply looping constructs (while, for, or do-while).

 Use file I/O in C++ (ofstream, ifstream) to read and write data
persistently.

 Develop good program structure using step-wise logic.

Program Requirements

Your program should perform the following tasks, step-by-step:

🔹 Step 1: Input Weekly Budget

 Ask the user to input their weekly budget (a double value).

 Save this value in a file named budget.txt.

 Use ofstream to write to the file.

🔹 Step 2: Input Daily Expenses


 Ask the user to enter their daily expenses for 7 days, one by one.

 Use a loop to take each day's input.

 Validate input: If a user enters a negative expense, ask them to re-


enter it until a valid (non-negative) value is given.

 Store each valid expense in a file named expenses.txt, using ofstream.

🔹 Step 3: Process Expense Data

 Open and read data from expenses.txt using ifstream.

 In the same loop, compute:

o Total expense for the week

o Maximum and minimum expense

 After the loop, compute the average daily expense by dividing total
by 7.

🔹 Step 4: Read and Compare Budget

 Read the budget value from budget.txt using ifstream.

 Compare the total expense to the budget and provide feedback:

o If expense > budget → "You exceeded your budget by X amount."

o If expense == budget → "You used exactly your budget. Well


planned!"

o If expense < budget → "You saved X amount this week. Great


job!"

🔹 Step 5: Generate Insightful Messages

 If any daily expense is greater than 2000, display:

"You had at least one large expense day (>2000)."

 If average daily expense < 1000, display:

"Good job keeping your expenses low on average!"


📤 Program Output

At the end, your program should display:

 Daily expenses (re-read from file)

 Total, average, maximum, and minimum expense

 Budget comparison message

 Any other insights based on user spending pattern

📋 Sample Program Output


============================================
Welcome to My Expense Buddy
============================================

Enter your weekly budget: 9500

Enter expense for Day 1: 1000


Enter expense for Day 2: 1200
Enter expense for Day 3: 2500
Enter expense for Day 4: -300
Expense cannot be negative. Re-enter: 900
Enter expense for Day 5: 1600
Enter expense for Day 6: 800
Enter expense for Day 7: 2000

Reading expenses from file...

Day 1 expense: 1000


Day 2 expense: 1200
Day 3 expense: 2500
Day 4 expense: 900
Day 5 expense: 1600
Day 6 expense: 800
Day 7 expense: 2000
========= Weekly Expense Summary =========
Total Expense: 10000
Average Daily Expense: 1428.571429
Maximum Expense: 2500
Minimum Expense: 800

========== Budget Feedback ==========


You exceeded your budget by 500 units.

========== Insights ==========


You had at least one large expense day (>2000).
Good job keeping your expenses low on average!

============================================
Thank you for using My Expense Buddy!
============================================

You might also like