The Purpose of This Programming Assignment Is To

The Purpose of This Programming Assignment Is To

CSC 110 Introduction to ProgrammingDATE 11/3/2018

CODING ASSIGNMENT #3 Data File Handling

Name______1

Problem: Hourly Payroll

Check List

Create Task List and define flowchart symbols
Draw flowchart and add pseudocode
Draw the user interface, place the names on the form-use the names in the problem
Fill out object property sheet
Code problem
Print code
Comments: Be sure to add as many as you think will make the code easy to update
Program Disk

The purpose of this programming assignment is to:

  • give you experience with variable and accumulators;
  • give you experience with readingand writing to a data files;
  • let you practice the elements of good coding style, including commenting, proper indentation, and descriptive variable naming.
  • give you some experience with selection structures

Lets Begin:

  1. Create a Windows project with the name Payroll.
  2. Accept the name property of the default form form1.
  3. Change the text property of the form to “Hourly Payroll” to display in the title.
  4. Add label controls to your form and change the contents of the text property as follows (see image below, use the correct prefixes, points will be taken off if not used):
  5. Employee Name
  6. Payroll Date
  7. Hours Worked
  8. Rate of Pay
  9. Payroll Details
  10. Gross Pay
  11. FWT
  12. FICA
  13. SWT
  14. Retirement
  15. Net Pay
  1. Add the following text boxes (INPUT) next to their corresponding labels (see image). Change the name property as indicated, change the text property to empty string, change the font to bold, and the forecolor to blue. Change the text alignment to right align for the txtHours and txtWage text boxes only.
  2. txtName
  3. txtDate
  4. txtHours
  5. txtWage
  1. Add the following label controls to be use as OUTPUT for payroll calculations. Be sure to change the name property as indicated below, clear the text property to empty the label, change the backcolor to white, change the forecolor to red, change the font to bold, change the borderstyle to Fixed3D, and change the textalign to MiddleCenter.
  2. lblGross
  3. lblFederal
  4. lblFICA
  5. lblState
  6. lblRetire
  7. lblNet
  1. Add a command button and change the name to btnWrite. In the text property enter Write Record. Write code to write the four pieces of data in your text box to a text data file that you will down load to the bin folder of this assignment called payroll.txt. (file is located in the O:\CSMP\CSC110\Programming Assignments\Coding Problem Assignment 3 folder)
  2. Declare the StreamWrite variables

Dim sw As IO.StreamWriter

  • Create a button call btnOpenWrite, double click the button and add the open statement inside this procedure

sw = IO.File.AppendText(“Payroll.txt”)

This will open the file in Append mode and add your records to the bottom of the existing data file. (see pages 406 of your book)

  • Each time you press the Write button it should write all the data for a new employee. Example you will need four write statement in your procedure, one for each of these data; Name, Date, Hours, and Wage.
  • Use writeline statements to write the data like the following

With sw

.WriteLine(txtEmployeeName.text)

.WriteLine(txtPayrollDate.Text)

End With

*look at the data in the file and make sure you write the data for your new employee in the same order. (name, date, hours, rate)

  • Use the following data to create 3 new records in the payroll.txt file.

Name / Date / Hours / Rate
Will Smith / 02/18/2005 / 40 / 25.00
Rodger Rabbit / 02/18/2005 / 45 / 5.75
Dedra Hall / 02/18/2005 / 15 / 75.00
  1. When you are through writing your records you must close your data file before you can open to read for the next section.
  2. Create a button name btnCloseFile in the text property enter the words “Close the file”
  3. Double click the button and enter the following code to close your file

sr.close()

sw.close()

* this will close both IO variable and allow the file to be reopened in the appropriate mode.

  1. Add a command button and change the name to btnRead. In the text property enter Read Record. Write code to read data from the payroll.txt data file.
  2. Declare the StreamReader variables

Dim sr As StreamReader

  • Add a button named btnOpenReadand open the file to the OpenText mode. (see pages 109-113 of your book)

sr = IO.File.OpenText(“Payroll.txt”)

  • Each time you press the read button it should read all the data for a new employee. The data should be displayed in the textboxes at the top of your form. Example you will need four read statement in your procedure, one for each of these data; Name, Date, Hours, and Wage.
  • Use assignment statements to display the data like the following

txtName.text = sr.Readline()

txtWage.text = sr.Readline()

  • How many payroll records are in the data file Payroll.txt? ______
  • What happens when you read all the records and then press the btnReaddata again? ______
  1. Add a command button and change the name property btnCompute, in the text property enter Compute. Write code in that object’s Click event to compute the payroll results and display them appropriately in the labels on your form.
  2. Use assignment statements and assign the results of your calculation to modular variable.
  3. The gross pay is equal to the hours * wage.

dblGross = Cdbl(txtHours.text) * Cdbl(txtWage.text)

  1. The taxes are equal to the gross pay * taxes percentage.
  2. Below are the percentages for the tax deductions. Be sure to declare all arguments modularly and initialize their values. (You could use constants)

Federal / 20 %
FICA / 8 %
State / 5 %
Retirement / 10 %
  • Display your results in the Labels that you placed on your form

Example for Gross pay would look like this.

LblGross.text = FormatCurrency(dblGross, 2)

  1. Test your work and compare to the results on the following page.

  1. Change your calculation for the Gross pay so that employees earn time and ½ for any hours worked over 40 (i.e. if a person works 41 hours, 40 hours would be at the regular wage and the additional 1 hour would be at 1 ½ times the regular wage). Below is a sample with a person working 48 hours. Use the appropriate condition statement for your calculation.

  1. Add code that checks to make sure data is read prior to performing the payroll computation (i.e. either check for string text in the Name or Date textboxes OR test for numeric values in the Hours Worked or Hourly Wage textboxes). If the boxes are empty, display an appropriate message box to the user and do not perform the computation.
  2. Try this IF-Then statement for error checking in your btnCompute event procedure

If txtName.text > “” then

‘Place your Calculations here

else

Msgbox(“No data to process”)

End if

  1. Place the same type of error checking in your btnWrite event procedure. This will ensure that you do not write blank lines into your data file.
  2. Add a reset button named btnClear that clears all user input and payroll calculations when clicked.
  3. Add an Exit button named btnExit that will close the window.
  4. The final form should look something like the following:

Scoring:

This assignment is worth 25 points.

10 points for all planning documents (Task list, User Interface, Property sheet)

5 points for coding style and proper use of variables, constants and object names

10 points for correct execution of all calculations, and formatted displays.