CIS105 - Programming Module
Lab Assignment 4 (turn in source code, sample output, and input file) - Points: _____
The objective of this assignment is to rewrite the program created in assignment 3 to read the data from an
external sequential file instead of from data statements. In addition, the output will be laid out better using
formatting options. The input data is a transaction file consisting of employees with pay rates and hours
worked that must be used to calculate the net pay.
An example of a similar program is attached as a reference.
Programming Environment: MS DOS QBASIC
Start > Classes > Structured Classes > CIS105 > QBASIC
Press ESCape to enter the editor
Enter the program you develop and save it on your floppy as A:PROG4.BAS.
File -> Save As -> A:PROG4.BAS
Run the program by pressing F5 or by selecting Start under Run.
Use the Alt + Print Screen keys to capture a copy of the screen, and then
paste it into a Word document for printing.
This document is the sample output that needs to be turned in.
From QBASIC, print a copy of the source code to turn in:
File > Print
Required Formulas:
IF hours > 40 THEN
gross = ((hours - 40) * rate * 1.5) + (rate * 40)
ELSE
gross = rate * hours
END IF
fed.tax = gross * .14
net.pay = gross - fed.tax
Required Output Report:
PROG4.BAS Payroll Report by Juan Marquez 11-18-1999
Name Rate Hours Gross Tax Net Pay
H. Johnson 4.95 41 205.42 28.76 176.67
B. Grant 6.00 39 234.00 32.76 201.24
R. Thomas 2.25 45 106.88 14.96 91.91
J. Lopez 5.54 36 199.44 27.92 171.52
M. Smith 8.95 37 331.15 46.36 284.79
Total Payroll 926.13
Press Alt & Print Screen to capture the screen, and
then press Enter to continue:
Required Input Data (a:prog4dat.txt):
"H. Johnson", 4.95, 41
"B. Grant", 6.00, 39
"R. Thomas", 2.25, 45
"J. Lopez", 5.54, 36
"M. Smith" 8.95, 37
The EOF record is not entered in the data file. The EOF(1) flag is used to test for EOF.
Use Notepad or the save as Text option in Word to create the input file (a:prog4dat.txt).
Assignment #4 Sample Source Code:
REM Prog4.bas (your name and class time goes here)
REM Program to create a Sales Report of action figures sold
REM *** Main Routine
GOSUB INIT.RTN
GOSUB PROCESS.RTN
GOSUB TOTAL.RTN
GOTO EOP
REM EOF is set to one when the last record is read
PROCESS.RTN:
DO WHILE NOT EOF(1)
GOSUB INPUT.RTN
GOSUB CALCULATE.RTN
GOSUB OUTPUT.RTN
LOOP
RETURN
INIT.RTN:
REM *** Initialize Routine ***
OPEN "A:PROG4DAT.TXT" FOR INPUT AS #1
LET TOTAL = 0
CLS
PRINT "PROG4.BAS Sales Report by Juan Marquez ", DATE$
PRINT " "
PRINT "Item Price Qty Cost Tax Order Amt"
PRINT " "
L$ = "\ \ ###.## ### ##,###.## ##,###.## ##,###.##"
T$ = "TOTAL SALES ##,###.##"
RETURN
INPUT.RTN:
REM *** Input Routine ***
INPUT #1, Item$, Price, QTY
RETURN
CALCULATE.RTN:
REM *** Processing Routine ***
REM *** 5% markup when Qty <= 40
IF Qty > 40 THEN
LET Cost = Price * Qty
ELSE
LET Cost = Price * Qty * 1.05
END IF
LET Tax = Cost * .06
LET Order = Cost + Tax
LET Total = Total + Order
RETURN
OUTPUT.RTN:
REM *** Output Routine ***
PRINT USING L$; Item$; Price; QTY; Cost; Tax; Order
RETURN
TOTAL.RTN:
REM *** Print Totals ***
CLOSE #1
PRINT " "
PRINT USING T$; TOTAL
PRINT " "
PRINT "Press Alt & Print Screen to capture the screen, and "
INPUT "then press Enter to continue: ", P
RETURN
EOP:
END
Assignment #4 Sample Output:
PROG4.BAS Sales Report by Juan Marquez 03-31-2000
Item Price Qty Cost Tax Order Amt
H. Johnson 4.95 41 202.95 12.18 215.13
B. Grant 6.00 39 245.70 14.74 260.44
R. Thomas 2.25 45 101.25 6.07 107.32
J. Lopez 5.54 36 209.41 12.56 221.98
M. Smith 8.95 37 347.71 20.86 368.57
TOTAL SALES 1,173.44
Press Alt & Print Screen to capture the screen, and
then press Enter to continue:
Assignment #4 Sample Data File (a:prog4dat.txt):
"H. Johnson", 4.95, 41
"B. Grant", 6, 39
"R. Thomas", 2.25, 45
"J. Lopez", 5.54, 36
"M. Smith", 8.95, 37
EOF record is not needed. The program checks the end of file function.
Revised: 7/30/2000 - www.mc.maricopa.edu/academic/business/cis105/basic/basic3_lab4.html