Lauretta J. Fox
Areas of rectangles can be found very quickly by using a computer. Programs to calculate the area of a rectangle can be written in a computer language called BASIC. A basic program is a group of statements that give instructions to the computer. Each statement is written on one line, and each line must be numbered. Any number between 1 and 9999 may be used to number a line. The computer executes each line of the program beginning with the lowest numbered statement and proceeds in ascending order to the highest numbered statement. After all calculations have been made, the computer prints the desired results.
Programs to calculate the area of a rectangle are illustrated below:
-
Program 1
|
is written in a very elementary and straight-forward way. It demonstrates how the statements of a program are to be listed.
|
10 REM FIND THE AREA OF A RECTANGLE
15 LET B =40
20 LET H =25
30 LET A = B*H
40 PRINT “BASE = “ B, “ALTITUDE =” H, “AREA= “ A
50 END
Result: BASE = 40 ALTITUDE = 25 AREA = 1000
Explanation
of
Program
1:
|
Line 10
|
“REM” is an abbreviation for “REMARK”. A REM statement may appear in any line of the program before the end statement. It does not affect the execution of the program, but it provides the programmer with an explanation if he wishes to review the program at a future date. If the REM statement takes more than one line, each line must be given a different number.
|
-
Lines 15,20 assign values to the base and altitude of the rectangle
Line 30
|
gives a formula to find the area of the rectangle. Notice that the symbol * is used to indicate multiplication.
|
Line 40
|
indicates what information is to be printed. Each character inside the quotation marks will be printed as shown. The values assigned to the variables outside the quotation marks will be printed. The commas separating the quantities to be printed tell the computer how to space the printed items. Groups of fifteen spaces are allowed for each quantity to be printed output line. The first space in each group is reserved for any required positive or negative The second quantity to be printed starts in the sixteenth space of the line. The third quantity starts in the thirty-first space, and so on. There can be no more than five groups of fifteen spaces each on any one line.
|
Line 50
|
END tells the computer that the program is now complete. The word RUN typed in the line immediately following the END statement of a program commands the computer to begin execution of the program.
|
Program 2
|
may be used to find the area of any number of rectangles. The number 16 was chosen arbitrarily. Three new concepts are introduced. They are: (1) printing results in tabular form under specified headings, (2) reading information from a data statement, (3) stopping the program as shown in line 19.
|
-
10 REM FIND THE AREA OF SIXTEEN RECTANGLES
11 PRINT “BASE”, “ALTITUDE”, “AREA”
15 PRINT
18 READ B, H
19 IF B = 0 THEN 70
30 LET A = B*H
40 PRINT B, H, A
45 GO TO 18
60 DATA 72,85,94,117,36,55,67,41,15,22,98,74
62 DATA 15,25,13,8,12.8,9.6,122,89,76,45,17
64 DATA 9,24,6,32,28,144,126,57,63,0,0
70 END
Result
:
|
BASE
|
ALTITUDE
|
AREA
|
|
72
|
85
|
6120
|
|
94
|
117
|
10998
|
|
36
|
55
|
1980
|
|
67
|
41
|
2747
|
|
15
|
22
|
330
|
|
98
|
74
|
7252
|
|
15
|
25
|
375
|
|
13
|
8
|
104
|
|
12.8
|
9.6
|
122.88
|
|
122
|
89
|
10858
|
|
76
|
45
|
3420
|
|
17
|
9
|
153
|
|
24
|
6
|
144
|
|
32
|
28
|
896
|
|
144
|
126
|
18144
|
|
57
|
63
|
3591
|
Explanation of Program 2
:
Line 11
|
tells the computer to print the words base, altitude and area as headings of columns in which the answers will appear. This command is placed at the beginning of the program so that it will be executed only once.
|
Line 15
|
is a “dummy” print line. It causes the computer to skip a line between the heading of the column and the first item in the column.
|
Line 18
|
tells the computer to the values assigned to the variables from the data statement.
|
Line 19
|
tells the computer to stop running the program if B =0. If B = O this command is ignored and the computer proceeds to the next line of the program.
|
Line 30
|
provides the formula needed to solve the problem.
|
Line 40
|
instructs the computer to print the values of B, H, and A. This will be done in tabular form under the headings from line 11.
|
Line 45
|
reroutes the computer back to line 18 to obtain a new set of values for B and H. The next three lines of the program will be executed with these new values. The process will continue in this loop until B -0. At this point the execution of the program will end.
|
Lines 60
|
are the values to be assigned to the variables.
|
62
|
The values of the variables are printed in
|
64
|
alternate positions on the line. For example, B =72, H= 85, B= 94, H = 117, etc. The last value assigned to B must be O to stop the execution of the program. Since the data did not fit on one line it was necessary to use additional data lines starting with new numbers.
|