Sharp logo

MZ-800 course Chapter 7 
7. Graphical applications


7.4 Business applications

With pie, normal bar, and 3-d bar charts, certain numbers can be visualised in a comprehensible way. In this part of Chapter 7 we show how numbers
can be plotted in a graph. Using these programs, you can write a program for yourself.

Program 1: Normal 2-d bar chart

With this program, you can plot data in a bar chart. You can input a maximum of 50 data points. Each input has a maximum of 197 and a minimum of 0. The expansion-ICs are not needed for this program.

10 DIM A(50):INIT "CRT:M2":PAL 0,1
20 INPUT "HOW MANY DATA POINTS DO YOU WANT TO PROVIDE? (1-50)";D
30 IF D<1 OR D>50 THEN 20
40 CLS:FOR T=1 TO D
50 PRINT "GIVEN";T;:INPUT":";A(T)
60 IF A(T)<0 OR A(T)>197 THEN 190
70 NEXT T
80 PAL 2,5:PAL 0,7
90 CLS:FOR Y=-1 TO 199 STEP 10:LINE [1]0,Y,319,Y :NEXT Y
100 S=0:S$="0":FOR A=192 TO 2 STEP -10>:SYMBOL [1]2,A,S$,1,1
110 S=S+10:S$=STR$(S):NEXT A
120 G=1:K=1:FOR T=30 TO 315 STEP 286/D:BOX [1]T,199,T+286/D,199-A(K),G:K=K+1
:G=G+1:IF G=16 THEN G=1
130 NEXT T
140 GET A$:IF A$="" THEN 140 ELSE RUN

Program 2: 3-d bar chart

Data can be plotted in a 3-d bar chart as well. Of course this will make the program a bit more complicated. In this program, the data is already present, you do not have to give input. Of course, you can modify the data. It can be that the graphs are not constructed properly anymore, this is because the front and back graphs are partly overlapping. This program works on every MZ-800.

10 INIT "CTR:M1":PAL 0,7 :PAL 3,0:PAL 1,8 :PAL 2,14
20 SYMBOL 0,0,"Number of inhabitants (x 1000)",1,1
30 FOR A=10 TO 109 STEP 10
40 BOX 20,A,200,A+10
50 SYMBOL 5,A-3,STR$(110,A),1,1
60 LINE 200,A,200+SIN(1/3*p)*100,A+COS(1/3*p)*100
70 NEXT A
80 LINE 200,110,200+SIN(1/3*p)*100,110+COS(1/3*p)*100
90 LINE 20,110,20+SIN(1/3*p)*100,110+COS(1/3*p)*100
100 LINE 200+SIN(1/3*p)*100,10+COS(1/3*p)*100,200+SIN(1/3*p)*100,110+COS(1/3*p)*100
110 LINE 20+SIN(1/3*p)*100,110+COS(1/3*p)*100,200+SIN(1/3*p)*100,110+COS(1/3*p)*100
120 FOR J=1960 TO 1980 STEP 10
130 SYMBOL 115+(J-1960)*6,162,STR$(J),1,1
140 NEXT J
150 DATA COMPUVILLE,50,65,77,DISKTOWN,76,87,83
160 DIM X(3):DIM Y(3)
170 READ S1$,X(1),X(2),X(3),S2$,Y(1),Y(2),Y(3)
180 CURSOR 14,22:PRINT [3]CHR$(200);" -";S1$
190 CURSOR 14,24 :PRINT [2]CHR$(200);:PRINT " -";S2$;
200 S1=SIN(1/3*p)
210 FOR T=0 TO 2:COLOR 1
220 C1=30+T*60+S1*70:C2=30+T*60+S1*90:C3=50+T*60+S1*90 :C4=50+T*60+S1*70
230 LINE C1,145,C2,155,C3,155
240 LINE C1,145-Y(T+1),C2,155-Y(T+1),C3,155-Y(T+1),C4,145-Y(T+1),C1,145-Y(T+1)
250 LINE C1,145,C1,145-Y(T+1):LINE C2,155,C2,155-Y(T+1) :LINE C3,155,C3,155-Y(T+1)
260 COLOR 2:PAINT C1+1,145,1:PAINT C2+2,154,1:PAINT C1+3,146-Y(T+1),1
270 NEXT T
280 FOR T=0 TO 2
290 COLOR 2:C1=30+T*60+S1*10:C2=30+T*60+S1*30:C3=50+T*60+S1*30:C4=50+T*60+S1*10
300 LINE C1,115,C2,125,C3,125
310 LINE C1,115-X(T+1),C2,125-X(T+1),C3,125-X(T+1),C4,115-X(T+1),C1,115-X(T+1)
320 LINE C1,115,C1,115-X(T+1):LINE C2,125,C2,125-X(T+1):LINE C3,125,C3,125-X(T+1)
330 COLOR 3
340 PAINT C1+1,117-X(T+1),2
350 PAINT C2+2,126-X(T+1),2
360 PAINT C1+3,116-X(T+1),2
370 NEXT T
380 GET F$:IF F$="" THEN 380

Program 3: Pie chart

With pie charts, the possibility also exists to visualise it in two or thee dimensions. Of course, a part of the pie can be removed as well and there are many more options.
In this program, we confine ourselves to a 2-d pie chart with the old fashioned example of apples and pears.
This program works on every MZ-800.

10 DATA APPLES,PEARS,BANANAS,ORANGES
20 INIT "CRT:M1":PAL 0,7:PAL 3,0
30 DIM AT(4):TT=0:FOR A=1 TO 4
40 READ A$:PRINT "HOW MANY ";A$;" DO YOU HAVE?":INPUT AT(A)
50 TT=TT+AT(A):NEXT A
60 CLS
70 PRINT "YOU HAVE ";TT;" PIECES OF FRUIT IN TOTAL." :PRINT
80 RESTORE "FOR A=1 TO 4:READ A$
90 PRINT "OF WHICH ";:PRINT USING "##.##";AT(A)/TT*100;:PRINT
"% CONSISTS OF ";A$
100 PRINT:NEXT A
110 PRINT:PRINT "PRESS ANY KEY TO SHOW THE PIE CHART."
120 GET F$:IF F$="" THEN 120
130 CLS:CIRCLE 100,100,90
140 LINE 100,100,100,10
150 R=p:FOR A=1 TO 4
160 R=R+AT(A)/TT*p*2
170 LINE 100,100,SIN(R)*90+100,COS(R)*90+100
180 PAINT [A-1]SIN(R-.02)*85+100,COS(R-.02)*85+100,3
190 NEXT A
200 CURSOR 22,2:PRINT "WHITE - APPLES"
210 CURSOR 24,4:PRINT [1]CHR$(200)+" - PEARS" 
220 CURSOR 24,6:PRINT [2]CHR$(200)+" - BANANAS"
230 CURSOR 24,8:PRINT [3]CHR$(200)+" - ORANGES"
240 CURSOR 0,0

Program 4: Line chart

A line chart is best viewed in 2-d, so that is exactly what we will do.
In this program you have to provide the input yourself. The program plots the revenue of the past ten years against the costs. The area in between therefore is profit, or loss. This area will be shaded. Profit and loss will be given different colours and will be easy to separate.
This program only works with the extra ICs.

10 INIT "CRT:M2":DIM OZ(10):DIM KT(10)
20 FOR A=1980 TO 1989
30 PRINT "WHAT WAS THE REVENUE IN ";A;:INPUT OZ(A-1979)
40 IF (OZ(A-1979)<0 THEN BEEP:PRINT:
PRINT "TO PREVENT NEEDLESS DIFFICULTY, I ASK YOU TO KEEP THE REVENUE LARGER
THAN 0. THIS IS ONLY AN EXAMPLE ANYWAY":PRINT:GOTO 30
50 IF (OZ(A-1979)>250 THEN BEEP:PRINT
:PRINT "TO PREVENT NEEDLESS DIFFICULTY, I ASK YOU TO KEEP THE REVENUE SMALLER
THAN 255. THIS IS ONLY AN EXAMPLE ANYWAY":PRINT:GOTO 30
60 PRINT "WHAT WERE THE COSTS IN ";A;:INPUT KT(A-1979)
70 IF (KT(A-1979)<0 THEN BEEP:PRINT
:PRINT "TO PREVENT NEEDLESS DIFFICULTY, I ASK YOU TO KEEP THE COSTS LARGER
THAN 0. THIS IS ONLY AN EXAMPLE ANYWAY":PRINT :GOTO 60
80 IF (KT(A-1979)>250 THEN BEEP:PRINT
:PRINT "TO PREVENT NEEDLESS DIFFICULTY, I ASK YOU TO KEEP THE COSTS SMALLER
THAN 255. THIS IS ONLY AN EXAMPLE ANYWAY":PRINT:GOTO 60
90 OZ(A-1979)=OZ(A-1979)/2
100 KT(A-1979)=KT(A-1979)/2:NEXT A
110 CLS:PAL 0,7
120 FOR X=25 TO 277 STEP 28
130 FOR Y=0 TO 130 STEP 10
140 BOX [1]X,Y,X+28,Y+10
150 NEXT Y,X
160 FOR A=0 TO 260 STEP 20
170 SYMBOL [1]0,134-1/2,STR$(A),1,1:NEXT
180 A$="":C=80:FOR B=12 TO 264 STEP 28:D$=A$+STR$(C)
190 SYMBOL [9]B,143,D$,1,1
200 C=C+1:NEXT B
210 BOX 0,157,319,199,15
220 SYMBOL [4]0,160,"GREEN = PROFIT",1,1
230 SYMBOL [10]0,170,"RED = LOSS",1,1
240 SYMBOL [2]0,180,"RED LINE = REVENUE",1,1
250 SYMBOL [3]0,190,"BLACK LINE = COSTS",1,1
260 X=25:PAL 3,0
270 FOR T=1 TO 10
280 SYMBOL [2]X-4,137-OZ(T),"+",1,1
290 SYMBOL [3]X-3,136-KT(T),"x",1,1
300 IF T=10 THEN 320
310 LINE [2]X,140-OZ(T),X+28,140-OZ(T+1):LINE [3]X,140-KT(T),X+28,140-KT(T+1)
320 X=X+28:NEXT T
330 T=1:FOR X=25 TO 249 STEP 28:D=1
340 FOR X1=X+4 TO X+28 STEP 4
350 A=OZ(T+1)-OZ(T)
360 A=A/7*D+OZ(T)
370 B=KT(T+1)-KT(T)
380 B=B/7*D+KT(T)
390 IF A>B THEN LINE [5]X1,140-A,X1,140-B
400 IF A<B THEN LINE [10]X1,140-A,X1,140-B
410 D=D+1:NEXT X1:T=T+1:NEXT X
420 GET A$:IF A$="" THEN 420
430 CLS:END

Apart from business applications, there are lots of other applications that use graphs, like educational purposes, applications for home use and so on.
With the programs given here, we hope that you can develop a program for yourself.
If you can’t do this by yourself, we could write such a program for you, but you really have to need this program and of course we shall ask for a small fee.
We could also put real business programs in this book, but then the book would be full before you know it.
Finally, we give a small program for the fans that can’t get enough of it.

Program 5: Lifting a piece from the pie chart

Of course, not much can be gained from this program, but it will help you on your way and combined with program 3, you can write a very nice program using pie
charts where you can also lift a piece of the pie.

10 INT "CRT:M1" 
20 CIRCLE 90,100,90,,,1.5*p
30 CIRCLE 100,109,90,,1.5*p
40 LINE 0,100,90,100,90,10
50 LINE 90,190,90,100,180,100
60 LINE 100,199,100,109,190,109
70 PAINT [1]40,40,3:PAINT [2]20,130,3:PAINT [3]130,130,3
80 CURSOR 25,2:PRINT [1]CHR$(200);:PRINT " = KIND 1"
90 CURSOR 25,4:PRINT [2]CHR$(200);:PRINT " = KIND 2"
100 CURSOR 25,6:PRINT [3]CHR$(200);:PRINT " = KIND 3"
110 CURSOR 25,8:PRINT "BLACK = KIND 4"
120 GET A$:IF A$="" THEN 120
130 CLS:END

Previous page
Next page
Contents


Go to the top of this page Home

last updated February 4, 2008
Arjan Habing, Mark de Rover, Jeroen F. J. Laros, sharpmz@sharpmz.org