Over the past several weeks I’ve been in the process of coding a payroll console program in the high level programming language C++. To facilitate this activity I’ve been using the Dev-C++ compiler.
Progress has been a bit slow and painful, but that’s to be expected. Much like learning a foreign language it would be foolish to think you can learn the intricate details of any programming language over night. C++ is no exception to that rule. Still I have made progress, and the program has continued to evolve.
I thought I’d post a quick update to reveal some of what I’ve accomplished, a few of the hard lessons I’ve had to learn, and point out a little of what may be coming in the future.
Previous Work On Project
- Coded a simple program capable of accepting accounting data entry from the user and providing output containing the following; gross pay, tax amount, net pay.
- Revised program to read data from a text file, and executed program using redirection from a command prompt.
- Revised program once more to include the fstream library, read data from an input file, and echo the data to the display using a console window.
- Added logic for the program to identify the marital status of employees, and adjust the amount of tax withheld accordingly.
- Gave the program the ability to calculate overtime hours, overtime pay, and display the information with total net pay.
In its present state the program appears as follows:
Most of the lessons I learned were simple in nature; with a bit more attentiveness I may have avoided the errors that led to them, which would have saved me a lot of time and frustration.
- If you create a new project, and borrow the code from it’s previous version, remember to update the name of any data files that may be hard coded in the source code.
- Also, related to item number 1, if you direct a program towards an input file make sure the input file is actually present within the correct directory.
- When using a while loop, and attempting to get a program to detect and display a variety of characters (in the char data type), it helped to use two equal signs as the logical operator (as in ms == ‘ms’;). Dual equal signs represent a true equality in C++. Without them the program assigned a marital status of S (for Single) for each of the employees despite what was indicated in the input file.
In general, I’m happy with how this project is coming along. However, in the near future I think the output could use a bit cleaner presentation. For example a header, maybe some names for the employees, and vertical alignment of the amounts shown. Future post will describe my progress on this project. Thanks for reading.