Problem Statement: File Handling in C/C++
On the basis of the given scenario create a file Expenses.txt, Open the file and copy into another Expenses2.txt, Also show output on screen
A college has announced the total budget of 50,000Rs.for each game. Games are done four times in a year. Take expenses as an input from user.
Calculate the average expenses for a game:

1. If the expenses greater than 80% show as” Very Expensive”.
2. If the expenses are greater than 60% and less than 80% than show “Expensive ”
3. If the expenses are greater than 50% and less than 60% than show “Less Expensive ”
4. If the expenses are greater than 40% and less than 50% than show “Not Costly”.
5. If the expenses are less than 40% than show “Best”.

Recommended Answers

All 2 Replies

1. Create an ifstream object.
2. Create an ofstream object.
3. Attempt to open Expenses.txt using your ifstream object.
4. Perform error checking to see if Expenses.txt actually exists.
5. If file open successful, load file into a storage container of your choice (string, array of strings, or a vector of strings seem to be the most popular choices.)
6. Close your ifstream object in efforts to save valuable system resources
7. Display the loaded file to the screen.
8. Use your ofstream object to open/create Expenses2.txt
9. Perform error checking to see if file opening/creation was successful
10. If successful, write to the Expenses2.txt from your storage data type.
11. close your ofstream object.
12. Start a loop
13. Prompt the user for an expense
14. Save user input into an array of doubles
15. Prompt if wish to enter another expense
16. If yes, Loop
17. Else calculate expense average.
18. Display average to screen
19. use if/else logic to test expense average and display desired ouput as per your assignement requirement.
20. return 0;

The is probably the best help you'll ever get without any effort or code from your part. I suggest you don't come back until you have something to show us.

Well help will only be provided if u could show your code ... we cannot do ur home work from scratch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.