Okay i need some help doing a payroll system using master/transaction files in C++. I have done the pseudocode (we will use text files to simulate tapes)

can anyone see any probs with my pseudocode?
how would i do it in c++?

========================

get payroll transaction file for $month (id, hours_worked_this_month)
get master file for $year (id,name,payrate,total_hours_this_year)

where transaction.id = master.id then
	total_hours_this_year = total_hours_this_year + hours_worked_this_month
	COPY TO NEW MASTER FILE
NEXT transaction.ID

UNTIL EOF (end of file)

COPY ALL (UNMODIFIED) RECORDS TO NEW MASTER FILE TOO

END

========================

[B]e.g?[/B]

[B]transaction file sample for DECEMBER:[/B]

id = 1, hours_worked_this_month = 29
id = 3, hours_worked_this_month = 54
id = 4, hours_worked_this_month = 48
id = 9, hours_worked_this_month = 12

[B]master file sample for 2007:[/B]

id = 1, name = james, payrate = £5.70, total_hours_this_year = 1028
id = 2, name = bob, payrate = £3.70, total_hours_this_year = 5021
id = 3, name = jane, payrate = £2.75, total_hours_this_year = 2022
id = 4, name = alex, payrate = £5.00, total_hours_this_year = 1128
id = 5, name = mike, payrate = £3.50, total_hours_this_year = 1121
id = 6, name = steve, payrate = £8.80, total_hours_this_year = 1017
id = 7, name = alan, payrate = £9.78, total_hours_this_year = 2078
id = 8, name = jeff, payrate = £23.75, total_hours_this_year = 3328
id = 9, name = mary, payrate = £32.70, total_hours_this_year = 4628
id = 10, name = kris, payrate = £15.00, total_hours_this_year = 5228

[B]Okay, now these recirds will be merged into the new master file where the IDs match:[/B]

id = 1, hours_worked_this_month = 29 
++++++++++
id = 1, name = james, payrate = £5.70, total_hours_this_year = 1028

id = 3, hours_worked_this_month = 54
++++++++++
id = 3, name = jane, payrate = £2.75, total_hours_this_year = 2022

id = 4, hours_worked_this_month = 48 
++++++++++
id = 4, name = alex, payrate = £5.00, total_hours_this_year = 1128

id = 9, hours_worked_this_month = 12
++++++++++
id = 9, name = mary, payrate = £32.70, total_hours_this_year = 4628

[B]to make a new master file (the hours for that month are added onto the total)[/B]

id = 1, name = james, payrate = £5.70, total_hours_this_year = 1057
id = 3, name = jane, payrate = £2.75, total_hours_this_year = 2076
id = 4, name = alex, payrate = £5.00, total_hours_this_year = 1173
id = 9, name = mary, payrate = £32.70, total_hours_this_year = 4640

[B]then the unedited files are merged into the new master file[/B]

id = 1, name = james, payrate = £5.70, total_hours_this_year = 1057
id = 3, name = jane, payrate = £2.75, total_hours_this_year = 2076
id = 4, name = alex, payrate = £5.00, total_hours_this_year = 1173
id = 9, name = mary, payrate = £32.70, total_hours_this_year = 4640
id = 2, name = bob, payrate = £3.70, total_hours_this_year = 5021
id = 5, name = mike, payrate = £3.50, total_hours_this_year = 1121
id = 6, name = steve, payrate = £8.80, total_hours_this_year = 1017
id = 7, name = alan, payrate = £9.78, total_hours_this_year = 2078
id = 8, name = jeff, payrate = £23.75, total_hours_this_year = 3328
id = 10, name = kris, payrate = £15.00, total_hours_this_year = 5228

[B]IGNORE THE IDS BEING IN ORDER, THEY WONT  BE AN DONT HAVE TO BE BECAUSE WE GO TO THE END OF THE FILE??? - I MADE A MISTAKE[/B]

There's probably at least a couple ways to do it.
1) read the entire master file into an array of structures or classes, then for each row in the transaction file search the array for the master record. If the master record is found then update it. If no master record then add one. When all done reading the transaction file write the master file array back to file.

2) similar to above but the master file is assumed to be too large to fit in memory all at one time. Afterall there could be thousands of employees. First, create a binary version of the master file -- read each record in the original text file into a fixed-length structure and write it out to a temp file in binary form. This will give you a file with fixed length records which can be updated without rewriting the entire file. When that is done start reading the transaction file. For each record in the transaction file search the temp master file for the matching id. When found, update the master structure and rewrite the changes back to the temp file. After that is all done you can rewrite the original master file with the information from the temp binary file.

commented: :) +23

thanks!

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.