COMPUTER STUDIES

ZONE PRINTING AND TABULATION

ZONE PRINTING

The output of information can be divided into zones across the screen or page by using commas between variable names and / or literals. The width of each zone is the same across the screen or page, however, zone width vary according to the position of the dialect of BASIC being used. Between 8 and 21 character positions are common widths giving between 4 and 5 print zones depending upon width of the output medium being used.

The format of the PRINT statement to allow zone printing is

PRINT {Literal -1/data-name-1}, [ {Literal -2/ data-name-2}]……..

It is possible to suppress zone printing if the comma, used for the zone separation, in a PRINT statement is replaced by a semi – colon (;) then the variables and / or literals listed in a PRINT statement will be printed one after another.

 

TABULATION

It allows specifying the position and spacing of the printed output on screen or page. The use of TAB(n) will prevent printing to start n columns from the left hand margin of the screen or page. It should be noted that n can be a numeric constant, numeric variable or the result of an arithmetic expression.

The format for a combined PRINT and TAB statement is:

PRINT TAB(n1) [; {Literal -1/data-name-1}] [;TAB(n2)][; {Literal -2/data-name-2}]………

Each item of the PRINT statement is separated by a semi- colon. This ensures that each value is printed in the specified TAB position and departs from zone spacing.

 

ZONE SPACING AND TABULATION

Both zone spacing and tabulation can be mixed within a single PRINT statement. If the printed output continues across a zone, then the next item to be printed will appear in the next zone if comma separation between the two items in PRINT statement exists.

 

WORKED EXAMPLES

1) Write a BASIC program to output the odd integers between 1 and 49.

 

Solution

 

10 REM TO OUTPUT THE ODD INTEGER BETWEEN 1 AND 49

20 FOR P = 1 TO 49 STEP 2

30 PRINT P

40 NEXT P

50 STOP

 

 

2) Write a BASIC program to output the squares of even number between 2 and 50

 

Solution

 

10 REM SQUARE OF EVEN NUMBER BETWEEN 2 AND 50

20 FOR K = 2 TO 50 STEP 2

30 LET S =K*K

40 PRINT K, S

50 NEXT K

60 STOP

 

 

3) Write a BASIC program to calculate and output the circumference and area of a circle. 

 

Solution

 

10 REM CIRCUMFERENCE AND AREA OF A CIRCLE

20 READ R

30 DATA 10

40 LET C=2*3.142*R

50 LET A=3.142*R*R

60 PRINT “CIRCUMFERENCE”,C

70 PRINT “AREA”,A

80 END

 

 

4) Write a BASIC program to output the sum of the cubes of odd integers between 11 and 29.

 

Solution

 

10 REM SUM OF THE CUBES OF ODD INTEGERS BETWEEN

20 REM 11 AND 29

30 LET S = 0

40 FOR I = 11 TO 29 STEP 2

50 LET S = S + I^3

60 NEXT I

70 PRINT “SUM OF CUBES”, S

80 STOP

 

 

5) Write a BASIC program to find the of largest number from a list of ten numbers in and then print the largest number.

 

Solution

 

10 REM………………………………………………..

20 REM N NUMBER

30 REM L LARGEST NUMBER

40 REM C COUNTER

50 INPUT “NUMBER”,N

60 C = 1

70 L = N

80 IF C = 10 THEN 130

90 INPUT “NUMBER”, N

100 C = C+1

110 IF N > L THEN L = N

120 GOTO 80

130 PRINT “LARGEST”, L

140 STOP

 

 

6. Write a BASIC program to calculate and output the circumference and area of a circle using input statement. 

 

Solution

 

10 REM CIRCUMFERENCE AND AREA OF A CIRCLE

20 INPUT R

30 LET C=2*3.142*R

40 LETA=3.142*R*R

50 PRINT “CIRCUMFERENCE”,C

60 PRINT “AREA”,A

70 END

 

 

7) A student studying computer science at a college is examined by coursework and written examination. Both components of the assessment carry a maximum of 50 marks. The following rules are used by the examiners in order to pass or fail students. 

  • A student must score a total of 40% or more in order to pass.
  • A total mark of 39% is moderated to 40%. However, each component must be passed with a minimum mark of 15.
  • If a student scores 40% or more but does not achieve the minimum mark in one component, he is given a technical fail of 39%. (This mark is not moderated to 40%).

Design and write a program to input the marks for each component and print the final mark. 

 

Solution

 

10 REM PROGRAM ON STUDENT ASSESSMENT

20 INPUT “COURSEWORK MARK”, C

30 INPUT “EXAMINATION MARK”, E

40 LET S = C+E

50 IF S < 39 THEN 130

60 IF C < 15 THEN 120

70 IF E < 15 THEN 100

80 IF S = 39 THEN LET S = 40

90 GOTO 130

100 LET S = 39

110 GOTO 130

120 LET S = 39

130 PRINT “TOTAL MARK =”, S

140 STOP

 

 

8) The cost of a standard size trophy is determined by the type of material from which it is made. The following table gives a list of costs.

 

Design and write a program to input the type of material and print the cost of the trophy.

 

Solution

 

10 REM PRINTING THE MATERIAL AND COST OF TROPHY

20 INPUT “MATERIAL OF TROPHY”, M$

30 IF M$ <> “GOLD” THEN 60

40 PRINT “N50000”

50 GOTO 190

60 IF M$ <> “SILVER” THEN 90

70 PRINT “N21000”

80 GOTO 190

90 IF M$ <> “STAINLESS STEEL” THEN 120

100 PRINT “N10000”

110 GOTO 190

120 IF M$ <> “BRONZE” THEN 150

130 PRINT “N3000”

140 GOTO 90

150 IF M$ <> “PEWTER” THEN 180

160 PRINT “N2000”

170 GOTO 190

180 PRINT “TROPHY NOT MADE OF”, M$

190 STOP

 

 

9) Write a program to print a simple PHCN bill. Your program should input:

  • Name of Customer
  • Address
  • Meter Number
  • Previous meter reading
  • Current meter reading

 

The number of units used in a month is the difference between the current meter reading and previous meter readings. Assuming the cost of a unit is N12:30K. The program should calculate the cost of using electricity and include a fixed charge of N500:00 per month to give a subtotal. Value added tax is charged at 5% on the sub-total. The sum of the sub – total and added tax gives the total amount due.

 

Solution

 

10 REM PREPARING PHCN BILL

20 INPUT “PRICE PER UNIT”, U

30 INPUT “FIXED CHARGE”, F

40 INPUT “VAT RATE”, V1

50 INPUT “NAME OF SUBSCRIBER”, N$

60 INPUT “ADDRESS – STREET”, S$

70 INPUT “TOWN”, T$

80 INPUT “POSTCODE”, P$

90 INPUT “METER NUMBER”, D$

100 INPUT “PREVIOUS METER READING”, P1.

110 INPUT “PRESENT METER READING”, P2

120 LET N=P2 – P1: C= U*N: T= C+F: V2= V1*T: A=T+V2

130 PRINT TAB(20); “PHCN BILL”

140 PRINT TAB(20); “_”

150 PRINT

160 PRINT “NAME:”;N$;TAB(33);”ADDRESS:”,S$

170 PRINT TAB(42); T$

180 PRINT “METER NUMBER:”,D$;TAB(42); P$

190 PRINT

200 PRINT “PREVIOUS METER READING:”;P1

210 PRINT “CURRENT METER READING:”;P2

220 PRINT

230 PRINT “CHARGES”

240 PRINT “_”

250 PRINT “CONSUMPTION @”U; “P PER UNIT ON”;N;”UNITS”TAB(47);C

260 PRINT “FIXED CHARGE”;TAB(46); T

270 PRINT

280 PRINT “SUB-TOTAL”; TAB(46); T

290 PRINT “VAT @”; V1; “%”; TAB(47); V2

300 PRINT

310 PRINT “TOTAL AMOUNT DUE”; TAB(46); A

320 END

Leave a Reply

Your email address will not be published. Required fields are marked *

Useful reference for domestic helper. Simple, privacy focused and free ad network for websites in need of new visitors.
Blogarama - Blog Directory