CIS
Contents:
(I) Homework #8
(II) Getting your hands on QBASIC
(III) Essential BASIC instructions
|
Hrs |
40 |
40 |
35 |
40 |
30 |
35 |
40 |
50 |
60 |
8 |
|
Rate |
12.25 |
10 |
15 |
15 |
12.25 |
18 |
11 |
20 |
10 |
150 |
Calculate Gross pay as in class. The program must detect overtime (>40 hrs/week) and pay double the rate for hours beyond 40.; Withholding: 10% when Gross pay is £ $600 and 15% if >$600; Net pay: Gross less Withholding. Program prints a report with suitable columns headings for
Hours, Rate, Gross, Withholding, and Net -- one line per employee
(b) How would you modify the program to handle any number of employees?
(c) How would you modify the program to handle employee names?
(d) Write the simple payroll procedure, discussed in class, as a Word macro...
....here, you may want to use InputBox rather than READ, see VB instructions under (III), below
Problem 2. Write a BASIC program to simulate a calculator. The program will ask the user for an operation code (A, S, M, and D representing Add, Subtract, Multiply, and Divide) and for two numbers and will display the result. In the following illustration the computer speaks in blue and the user in red:
Operation?M
(II) In Windows 95, you may invoke QBASIC by simply typing qbasic in the RUN dialog box of the Start menu. Should this not work for you, use any other BASIC system you can get hold of. Older computers may have GWBASIC or BASICA. You may also be able to get a copy of QBASIC at the lab (basement of Levin Hall). Ask the consultant and be sure to bring a diskette for the QBASIC program and its help files (will occupy half of a 1.44MB floppy).
(III) A list of some useful BASIC instructions follows. Required keywords are shown in boldface. Variable names (e.g. HOURS) & constants (e.g. 90, 10, etc) are arbitrary. Variables like HOURS are allotted a few bytes of RAM.Strings of text characters can be placed in String variables (e.g. NAME$) or between quotes (in Visual BASIC (VB), '$' not needed). In all cases, string values can be converted to numerical values with the Val(string) function. Conversely, numbers may be converted to strings with the Str$(number) function
|
Input |
READ HOURS, RATEINPUT "Prompt"; HOURS, RATE INPUT#1 HOURS, RATE S = InputBox("prompt","label") ....(VB) |
Read data from DATA statement |
|
Output |
PRINT "Hrs=";HOURS, "Rate=";RATE LPRINT HOURS, RATE, GROSS MsgBox (S) ....(VB) |
Print to the screen (a heading) |
|
Branching |
GOTO 90IF N=10 THEN GOTO 90 |
( Unconditional) "90" is a label(Conditional) N=10 is the "condition" |
|
Calculation |
LET GROSS = HOURS*RATEIF A>=0 THEN B=100+C |
"Let" optional; * multiplication operator |
|
Counting |
LET N = N+1 |
N is the counting variable |
|
Summing |
LET SUM = SUM+X |
SUM is the summing variable |
|
Looping |
FOR N=1 TO 20 [STEP 3]NEXT N |
Start of loop; [STEP x, optional] |
|
Data |
DATA 40, 12.25 |
Can be anywhere in prog. |
|
Subscripted variables |
DIM X[12] |
Dimension: X is an array of 12 variables |
|
File management |
OPEN "filename" FOR INPUT AS #1CLOSE #1 |
"filename" is a previously created fileSimilarly, ...FOR OUTPUT AS #2 |
|
String Variables |
e.g. NAME$, ZIP$ |
For non numeric (text) data |
|
Functions |
Val (string)Str$(number) Rnd Int(number) |
convert strings to numbers |