Starting from:

$24.99

NYU-CS Homework 15-Linked Lists & File Reading Solution

Imagine a group of friends went out to dinner together. When the bill comes they all give different amounts to contribute to the total, but after wish to balance everything out equally so that each person pays the same amount. Knowing how much each person is supposed to pay is simple enough, just add up all the amounts paid and divide by the number of people; but that doesn’t tell anyone how to go about distributing the payments, who should give what amount to whom?
Write a program that will print out a step by step list of instructions of how to reimburse everyone given the name of the person and amount of money they paid. This program should prompt the user to enter a file name associated with the info, which will then be read in. All information from the external file should be read into a linked list. An example is provided below:
Input: Output:

A few things to note:
- You should design your own linked list and node classes for this. The node class would essentially be representing people, and you can choose whatever attributes you like for it, but might be helpful to store name and amount paid (from the input file), as well amount owed, which can be initialized to 0 and then altered later upon calculating the balances
- You must be able to read in full names, accounting for both 2 and 3 part names
- The information should be read into a linked list, but after that you can handle it in whatever format you find convenient
- Don’t worry about rounding to two decimal places for $ amounts
- You can assume the data file will have at least 2 names/amounts on it, we will not test it with empty files
- The program should not alter anything in the input file, you simply are reading it in
If you are confused about how to calculate who pays whom what amount, a good way to start is to calculate the target value for everyone (total sum of what everyone paid / # of people), and see who owes money, and who is owed money (whether their “paid” attribute is above or below the target value).

More products