|
Post by oldatheart on Sept 14, 2023 21:17:12 GMT
I learned BASIC back in the stone age with an Apple2c and Commodore. I want to use Just BASIC to generate math worksheets for students that I do volunteer tutoring for. I can generate random numbers to perform arithmetic operations on, and I have figured out how to send the output to a printer to get a hard copy. But, is there any way I can format the text so I can show the math problems in vertical format so the place values align? I also want to arrange the problems in multiple columns across the printed page. Is this possible?
|
|
|
Post by tsh73 on Sept 14, 2023 21:37:26 GMT
Looks pretty possible to me. Could you post examlle picture of what are you want to get somewhere like posimages.org, and post a link to that picture here?
Also post some code you use for printing stuff There probably more then one way, so knowing which one will help.
|
|
|
Post by tsh73 on Sept 15, 2023 5:16:32 GMT
using monospaced font should help with it Like, Courier New or Andale Mono or Lucida Console
If your JB code aligns, then JB uses some monospaced font (my uses Courier New but I'm not sure it was default one) ordinary font (proportional) does not align, each character has own width ("i" is narrower then "4")
Monospaced font aligns - each letter has same width
iii 123
(though I hope in all fonts "digits" are of equal width. But, there is a numerical dot, and exponent "e", math operations...
so likely monospaced font still be better
12.3 +234 12-3 12e3 )
|
|
|
Post by tsh73 on Sept 15, 2023 8:11:47 GMT
in a mainwin, using "pad with spaces" user defined function I got this
default way
410 + 29763 -------- 30173
aligned way
410 + 29763 ------ 30173
masked aligned way
4_0 + 29_6_ ------ _0173
maxVal=1000 op1=int(rnd(0)*maxVal) op2=int(rnd(0)*maxVal*100) op$="+" res = op1+op2
print "default way" print print op1 print op$ print op2 print "--------" print res
'print string$("=", 8)
len1=len(str$(op1)) len2=len(str$(op2)) len3=len(str$(res))
maxLen=max(max(len1,len2),len3) 'and add 1 for operator maxLen=maxLen+1 print print print "aligned way" print print padl$(str$(op1),maxLen) print op$ print padl$(str$(op2),maxLen) print string$("-", maxLen) print padl$(str$(res),maxLen)
print print print "masked aligned way" print print mask$(padl$(str$(op1),maxLen)) print op$ print mask$(padl$(str$(op2),maxLen)) print string$("-", maxLen) print mask$(padl$(str$(res),maxLen))
'functions '--------------------------------------------- function mask$(a$) 'randomly mask some digitd with "_" mask$="" for i = 1 to len(a$) c$=mid$(a$,i,1) if instr("1234567890", c$)=0 then mask$=mask$+c$ else if rnd(0)<.2 then '20% mask mask$=mask$+"_" else mask$=mask$+c$ end if end if next end function
function string$(a$, n) string$="" for i = 1 to n string$=string$+a$ next end function
'adds spaces from the left until 'n' symbols 'if n<len(a$) returns left$(a$,n) function padl$(a$,n) padl$ = left$(space$(n-len(a$))+a$,n) end function
'adds spaces from the right until 'n' symbols 'if n<len(a$) returns left$(a$,n) function padr$(a$,n) padr$ = left$(a$+space$(n-len(a$)),n) end function
EDIT and of cource
SEND + MORE ------ MONEY
print print print "puzzle" print print padl$("SEND",maxLen) print op$ print padl$("MORE",maxLen) print string$("-", maxLen) print padl$("MONEY",maxLen)
|
|
|
Post by honky on Sept 15, 2023 8:39:25 GMT
Hello, A way to align columns Fixed hunting font required dd$() is data array contain 5 items by line #w.ent is texteditor 2nd item is a number with 2 digits
#w.ent, "!cls" for x=1 to n a$=word$(dd$(x),1): b$=word$(dd$(x),2): c$=word$(dd$(x),3): d$=word$(dd$(x),4) e$=word$(dd$(x),5) dd$(x)=a$+space$(23-len(a$))+b$+space$(5-len(b$))+c$+space$(30-len(c$))+_ d$+space$(20-len(d$))+e$ #w.ent, dd$(x): #w.ent, "!origin column row" next x wait
|
|
|
Post by oldatheart on Sept 15, 2023 20:14:07 GMT
I managed to get the problems spaced 8 across the screen/printed page using a combination of commas, semicolons and quotation marks with empty space between them. I've done problems that add 2 single digit numbers.
2 dim a(100) 3 dim b(100) 4 dim c(100)
5 for x = 1 to 100
10 a(x) = INT(RND(1) * 8) + 1 20 b(x) = INT(RND(1) * 8) + 1 25 c(x) = a(x) + b(x) 26 next x 28 for x = 1 to 96 step 8 30 lprint " "; a(x)," "; a(x+1)," "; a(x+2)," "; a(x+3)," "; a(x+4)," "; a(x+5)," "; a(x+6)," "; a(x+7) 35 lprint "+"; b(x),"+"; b(x+1),"+"; b(x+2),"+"; b(x+3),"+"; b(x+4),"+"; b(x+5),"+"; b(x+6),"+"; b(x+7) 40 lprint c(x),c(x+1),c(x+2),c(x+3),c(x+4),c(x+5),c(x+6),c(x+7) 45 lprint 60 next x
70 x = 97 80 lprint " "; a(x)," "; a(x+1)," "; a(x+2)," "; a(x+3) 85 lprint "+"; b(x),"+"; b(x+1),"+"; b(x+2),"+"; b(x+3) 90 lprint c(x),c(x+1),c(x+2),c(x+3) 95 lprint
I know that nobody uses line numbers anymore, but that's how I learned, and I am too arthritic to try to learn all the ins and outs of modern methods.
I do need to know if Just BASCIC has an underline feature.
|
|
|
Post by tsh73 on Sept 15, 2023 20:36:35 GMT
Have a look using using(format$, number) to align results right Using FOR loop by i instead of +1 +2 ...
Not in the maiwin. But if you switch to graphics it will allow draw any lines.
2 dim a(100) 3 dim b(100) 4 dim c(100)
5 for x = 1 to 100 10 a(x) = INT(RND(1) * 8) + 1 20 b(x) = INT(RND(1) * 8) + 1 25 c(x) = a(x) + b(x) 26 next x
'100 does not divide by 8 '8 does not fit to portrait A4 paper (for me, with printer font Courier New 9) 'so I use 5
'28 for x = 1 to 96 step 8 for x = 1 to 100 step 5 for i = 0 to 4 '0 to 4, 5 numbers print " "; a(x+i), next print
for i = 0 to 4 print "+"; b(x+i), next print
for i = 0 to 4 print using("##",c(x+i)), next print print next
Something along this (actually produces 20 sets of 5 tasks)
8 7 8 6 6 +2 +7 +3 +3 +5 10 14 11 9 11
5 2 7 6 8 +4 +5 +5 +2 +1 9 7 12 8 9
|
|
|
Post by oldatheart on Sept 15, 2023 23:18:32 GMT
Appreciate the help.
|
|
|
Post by tsh73 on Sept 16, 2023 11:08:28 GMT
I made a sub thad draws this like this (it uses hardcoded name #gr, sorry) fixed that, now it uses global gr$ for handle You first set font with font$ = "courier_new 12" call setFont font$ Next call drawFormula with top level corner and formula string formula string is space delimited, "op1 operator op2 eq_sign result" actually eq_sign is not used, left here for readability example is "SEND + MORE = MONEY" or call drawFormula 150, 200, "100500 + 9999900 = 10100400" Uncomment line '#gr "print SVGA" '800 pixels to A4 paper width to get real printing. nomainwin WindowTop = 1 WindowLeft = 1 WindowWidth = 800 WindowHeight = min(DisplayHeight,800*30/21) 'A4 proportions, 800*1143. Cur down to display size
global cw, ch, maxLen, gr$ 'character width and height. maxLen is global only for showing bounding box, once
open "test" for graphics as #main gr$ = "#main" #gr$ "trapclose [quit]" #gr$ "down; home; posxy cx cy"
'draw some examples
font$ = "courier_new 12" call setFont font$
x0=50 y0=50 formula$="send + more = money"
call drawFormula x0, y0,formula$
'show x0 y0 and bounding box, but it needs maxLen global (only for this) #gr$ "color red" #gr$ "place ";x0;" ";y0 #gr$ "circle 10" #gr$ "box ";x0+maxLen*cw;" ";y0+ch*4
#gr$ "color black" x0=150 y0=100 call drawFormula x0, y0, "SEND + MORE = MONEY"
'made the font smaller #gr$ "color blue" call setFont "courier_new 10" call drawFormula 50, 200, "SEND + MORE = MONEY"
'now real digits call drawFormula 150, 200, "100500 + 9999900 = 10100400"
#gr$ "color darkgreen" 'operator copuld be any symbol. Math could be wrong!! call drawFormula 200, 0, "10 * 200 = 3.1415" #gr$ "place ";120;" ";0+ch*4 #gr$ "\";"Math could be wrong!"
#gr$ "flush" 'uncomment to get hardcopy '#gr$ "print SVGA" '800 pixels to A4 paper width wait
[quit] close #gr$ end
'--------------------------------------------- sub setFont font$ ' font$ should be monospaced font, like '"courier_new 12"
#gr$ "font ";font$ #gr$ "place 0 0" #gr$ "\" #gr$ "posxy dummy ch" 'single character hight a$="0" #gr$ "stringwidth? a$ cw" 'single character width
'#gr$ "place 10 ";10+ch '#gr$ "\";"The character size is ";cw;" ";ch end sub
sub drawFormula x0, y0,formula$ 'space delimited, op1 operator op2 eq_sign result 'actually eq_sign is not used, left here for readability 'example is "SEND + MORE = MONEY"
op1$=word$(formula$,1) op$=word$(formula$,2) op2$=word$(formula$,3) res$=word$(formula$,5) '5, because (4) is eq_sign, not used!
'top left is x0 y0 'first column is for operator
maxLen=max(max(len(op1$),len(op2$)),len(res$)) 'and add 1 for operator maxLen=maxLen+1
#gr$ "place ";x0;" ";y0 #gr$ "\"; #gr$ "\";padl$(op1$,maxLen) #gr$ "\";padl$(op2$,maxLen) #gr$ "\";padl$(res$,maxLen) 'now overprint with operator #gr$ "place ";x0;" ";y0+ch*1.5 #gr$ "\";op$ 'and add line above result #gr$ "place ";x0;" ";y0+ch*2.25 'this is trial and error #gr$ "north; turn 90" #gr$ "go ";maxLen*cw end sub
'------------------- 'adds spaces from the left until 'n' symbols 'if n<len(a$) returns left$(a$,n) function padl$(a$,n) padl$ = left$(space$(n-len(a$))+a$,n) end function
|
|
|
Post by plus on Sept 16, 2023 15:14:40 GMT
oldatheart (wow what a horrible avatar name, sorry just my stupid opinion, I mean to me it looks like: Old at heart?) anyway do you know how to use Subs and Functions and freely write one up if code needs it? I suspect anyone still stuck doing line numbers might be better served with GoSubs as step up from GoTo's but not quite there with Subs or Functions. A good teacher needs to know their students knowledge and abilities. b = b + ...
|
|