Write a program that opens a file, reads records into a container of data structures, and prints out the sum in order.
You can use Vectors to contain the data structures.
- Create a data structure to represent the record (struct cost in cost.h)
- Write a function called parse_account that parses one (string) record from a file, and populates a data structure with that data.
- Write a function called sum_accounts that, when passed a container of structures, returns a double representing the sum of the amounts in those structures.
- Create a main program
a) Create an appropriate container of data structures
b) Open the accounts file (costfile.txt)
c) While you can read a line from the file without error
Call parse_account, which returns a data structure.
Add the returned data structure to the container (using, pushToV)
d) Call sum_accounts to determine the amount of money represented
e) Print a message and the result.
Try this with some sample data, such as the following lines in costfile.dat
You may add or create your own data file to test the program with:
Pass_Go 200.0 135
Reading_RR -50.0 136
Connecticut -120.0 137
Chance 25.0 138