Chapter 3.1: School -- First Recital
Chapter 3.2: School -- Shoe Sizes and BASIC
Professor Crane walked in the door and the pre-class chatter dropped slightly in
volume.
"Good morning guys. I've got a question for all y'all."
He had all our attention for a moment.
"Using BASIC as a calculator, how'd ya convert an American shoe size of eight and a half to a metric shoe size?"
"Oh, is that all?" Lisa turned back to continue talking to Dirk, and about half of the class followed her example.
Professor Crane gave her a wry grin. "This is a serious question."
Lisa shook her head. "Dead simple." She stood up, went to the whiteboard, and picked up a marker.
PRINT 8.5 * 2.54
"Done!" She put the marker down and turned to sit down.
"But who's gonna go to the trouble of typing that on a punched card?" Don asked.
Lisa rolled her eyes.
"Or," Dirk raised his eyebrows meaningfully at Lisa, "who's going to bother plugging in her Apple just to type that in?"
Lisa had an Apple II at home, and was using it for some of her homework.
"How about listing the conversions from size five to thirteen?" I asked. "I
could maybe see plugging in a microcomputer for that."
Lisa grumbled and turned back to the whiteboard.
10 FOR I = 5 TO 13 20 PRINT I*2.54 30 NEXT I
Professor Crane chuckled. "Sometimes I think Joe sneaks peeks at my lesson plans. So, let's say we want to provide the sales guys with something they can plug a range into. And they want half sizes, going both directions. And they don't want to learn BASIC."
Mike leaned back. "I think our professor just gave us our next assignment."
Professor Crane shook his head. "Not yet. This is just background. And we need to watch this in action. Since Joe and Lisa didn't bring their computers to class today, let's all go to Professor Bright's office."
"There's action in the prof's office?"
"If we're going to play computer, we can do that here."
Playing computer is a technique for working through what a computer when
executing program steps. We had done that as a class when Professor Crane
introduced program loops.
There was a bit of jesting and complaint, but the fourteen of us followed Professor Crane out the door and down the hall to Professor Bright's office.
Theo was first through the door. "There's a computer on your desk, Professor Bright," he announced.
Professor Bright was seated at his desk, hands on the keyboard, waiting for
us. He opened his mouth to answer.
"Computer terminal, I think," George commented as he filed in.
Professor Bright closed his mouth with a patient smile.
Pat nodded in agreement as she followed George. "Dumb terminal for the
Univac."
Lisa and I were last, hanging behind in the doorway behind Dirk and Andrea, giving the other students room.
"RS-232 cables," I observed. "One goes to the printer --"
"That's a printer?" Daren asked. "It looks like a typewriter without a keyboard."
"Yeah, it's a printer," Professor Crane said. "Although typewriter without keyboard is also a good description. And?"
Daren remained bemused.
"And," I continued, "the other cable goes to the wall, where the Univac is on the other side. So I think it's a good bet it's hooked to the Univac. But I think it's an intelligent terminal, judging from what's on the screen."
The screen showed tags for the keyboard function keys along the bottom,
showing several data I/O frames of the sort we now call windows, according to
the Xerox PARC (and, later, Apple Macintosh) terminology.
Professor Bright nodded. "That's right, the brains are in the computer room on the other side of that wall. This is just a terminal -- although actually a terminal with intelligent functionality, as Joe has surmised." He pressed a key, and the screen blanked, to change to a login screen.
Professor Crane explained from behind most of us, "We have been able to obtain several of these terminals on the cheap from the same company that gave us the good price on the used Univac. There won't be enough terminals for everyone to have their own, so we'll have to schedule use, but I think we'll find them more convenient than punched cards. BASIC, in particular, has a different feel when used interactively. But, of course, those who prefer punched cards ..."
"I don't think I prefer punched cards."
"I'll be happy to give up my time on the card punch!"
"I think I can live without punched.cards."
"Hey, consider the poor card punch's feelings!"
"And the cards'!"
"Consider my feelings!"
"Card punches don't have feelings."
"How do you know? Have you ever asked one?"
Both professors were chuckling well before this point.
"You haven't even tried these terminals yet," Professor Crane cautioned. "For all you know, they may be too arcane."
"No way!"
"We can handle some arcane!"
"Arcade? These things play Invaders?" Lisa laughed at her own joke.
Both professors groaned as most of the students again erupted in jokes and
conjecture.
"Actually, I'll bet they could be programmed to play a game like Pac Man."
All the students turned towards me.
"Not that I would try it," I continued, glancing back at Professor Crane, "without permission."
"Enough of that. Time's a-wasting." Professor Bright called our attention back to the terminal screen. "Pat, since you work as a night operator at your dad's company, how about if you take the driver's seat?"
Professor Bright stood up and other students complained teasingly as they made
way for Pat to move to the desk and sit down.
Professor Bright explained how to use the temporary passwords to log in to the
interactive accounts that had been activated for us, and Pat followed his
instructions while we watched. She loaded the BASIC interpreter and started it
in interactive mode, then, without instruction, typed in the formula line that
Lisa had written on the whiteboard and hit the RETURN key.
PRINT 8.5 * 2.54 21.59 OK _
The underscore cursor blinked on the line beneath.
Professor Crane nodded his approval. "Any questions so far?"
There were none, and Pat proceeded to type in Lisa's three-liner, again, without waiting for instructions:
10 FOR I = 8 TO 13 20 PRINT I*2.54 30 NEXT I RUN 20.32 22.86 25.4 27.94 30.48 33.02 OK _
"Skipped 8.5," Dirk pointed out.
”BASIC can't do fractional steps in a FOR loop," Mike commented. "Have to use GOTO, or maybe double the steps and divide by two?"
"Very good, Mike." Professor Bright put a memo slip in front of Pat. "We have a short program to do exactly according to your second suggestion. Can you load that for us, Pat?"
Pat read the filespec on the memo and typed in the commands to load the program and list it on the screen:
10 PRINT "Shoe Sizes" 20 PRINT "Type E for English to Metric." 30 INPUT "Type M for Metric to English: ", C$ 40 IF C$ <> "E" AND C$ <> "M" THEN GOTO 10 90 REM 100 INPUT "Start: ", B 110 INPUT "End: ", E 120 IF C$ = "E" THEN PRINT "ENGLISH => METRIC" 130 IF C$ = "M" THEN PRINT "METRIC => ENGLISH" 180 REM 190 REM STEP BY HALVES 200 FOR I = B*2 to E*2 210 PRINT I/2, "=>"; 220 IF C$ = "E" THEN T=I*2.54 230 IF C$ = "M" THEN T=I/2.54 240 S=T/2 250 PRINT S 400 NEXT I 500 END
(This program can be run in many BASIC dialects, including, for example, the
bwbasic available in many Linux OS distributions.)
Then she issued the run command with the following results (including her keyboard input where the computer prompted for the direction to convert and for the start and end values):
Shoe Sizes Type E for English to Metric. Type M for Metric to English: M Start: 13 End: 35 METRIC => ENGLISH 13 => 5.1181102 13.5 => 5.3149606 14 => 5.511811 14.5 => 5.7086614 15 => 5.9055118 15.5 => 6.1023622 16 => 6.2992126 16.5 => 6.4960630 17 => 6.6929134 17.5 => 6.8897638 18 => 7.0866142 18.5 => 7.2834646 19 => 7.4803150 19.5 => 7.6771654 20 => 7.8740157 20.5 => 8.0708661 21 => 8.2677165 21.5 => 8.4645669 22 => 8.6614173 22.5 => 8.8582677 23 => 9.0551181 23.5 => 9.2519685 24 => 9.4488189 24.5 => 9.6456693 25 => 9.8425197 25.5 => 10.03937 26 => 10.2362205 26.5 => 10.4330709 27 => 10.6299213 27.5 => 10.8267717 28 => 11.023622 28.5 => 11.2204724 29 => 11.4173228 29.5 => 11.6141732 30 => 11.8110236 30.5 => 12.007874 31 => 12.2047244 31.5 => 12.4015748 32 => 12.5984252 32.5 => 12.7952756 33 => 12.9921260 33.5 => 13.1889764 34 => 13.3858268 34.5 => 13.5826772 35 => 13.7795276
"That's a lot of decimal points," Alex muttered.
Most of the students nodded in agreement.
"We're glad you noticed. We have a way to fix that." Professor Bright put
another slip of paper in front of Pat, and she ended the session she was
working in, started a new session, and loaded the program from the filespec
shown on the new memo:
5 REM PRINT SHOE SIZE TABLE WITH HALVES BY RUSTY CRANE 10 PRINT "Shoe Sizes" 20 PRINT "Type E for English to Metric." 30 INPUT "Type M for Metric to English: ", C$ 40 IF C$ <> "E" AND C$ <> "M" THEN GOTO 10 90 REM 100 INPUT "Start: ", B 110 INPUT "End: ", E 120 IF C$ = "E" THEN PRINT "ENGLISH => METRIC" 130 IF C$ = "M" THEN PRINT "METRIC => ENGLISH" 180 REM 190 REM STEP BY HALVES 200 FOR I = B*2 to E*2 210 PRINT I/2; CHR$(9); "=>"; 220 IF C$ = "E" THEN T=I*2.54 230 IF C$ = "M" THEN T=I/2.54 240 S=T/2 250 PRINT S; ":"; CHR$(9); 260 GOSUB 1100 400 NEXT I 500 END 1100 REM PRINT HALVES 1110 T=INT(S) 1120 H=INT((S-T+.25)*2) 1130 IF H<2 THEN GOTO 1160 1140 H=0 1150 T=T+1 1160 PRINT T; 1170 IF H > 0 THEN PRINT " "; H; "/2"; 1180 PRINT 1190 RETURN
Running this one produced the following:
Shoe Sizes Type E for English to Metric. Type M for Metric to English: M Start: 13 End: 35 METRIC => ENGLISH 13 => 5.1181102: 5 13.5 => 5.3149606: 5 1/2 14 => 5.511811: 5 1/2 14.5 => 5.7086614: 5 1/2 15 => 5.9055118: 6 15.5 => 6.1023622: 6 16 => 6.2992126: 6 1/2 16.5 => 6.4960630: 6 1/2 17 => 6.6929134: 6 1/2 17.5 => 6.8897638: 7 18 => 7.0866142: 7 18.5 => 7.2834646: 7 1/2 19 => 7.4803150: 7 1/2 19.5 => 7.6771654: 7 1/2 20 => 7.8740157: 8 20.5 => 8.0708661: 8 21 => 8.2677165: 8 1/2 21.5 => 8.4645669: 8 1/2 22 => 8.6614173: 8 1/2 22.5 => 8.8582677: 9 23 => 9.0551181: 9 23.5 => 9.2519685: 9 1/2 24 => 9.4488189: 9 1/2 24.5 => 9.6456693: 9 1/2 25 => 9.8425197: 10 25.5 => 10.03937: 10 26 => 10.2362205: 10 26.5 => 10.4330709: 10 1/2 27 => 10.6299213: 10 1/2 27.5 => 10.8267717: 11 28 => 11.023622: 11 28.5 => 11.2204724: 11 29 => 11.4173228: 11 1/2 29.5 => 11.6141732: 11 1/2 30 => 11.8110236: 12 30.5 => 12.007874: 12 31 => 12.2047244: 12 31.5 => 12.4015748: 12 1/2 32 => 12.5984252: 12 1/2 32.5 => 12.7952756: 13 33 => 12.9921260: 13 33.5 => 13.1889764: 13 34 => 13.3858268: 13 1/2 34.5 => 13.5826772: 13 1/2 35 => 13.7795276: 14
"What's different about this program?" Professor Crane asked.
Nobody was brave enough to state the obvious but me, so, after a bit of waiting I said, "You've put the output in a subroutine, so that you can focus on more complicated output that includes the approximation to halves."
Professor Bright frowned and tilted his head.
Professor Crane scratched the back of his neck. "Everybody see what Joe says about approximations?"
General nods and murmurs of agreement.
"And do you see where the subroutine is?"
"I see a GOSUB," volunteered Daren. "Is the subroutine from line 1110 to the end?"
"Or 1100 to the end?" asked Alex.
"That's it," replied Professor Crane.
For a minute or so, we discussed where the subroutine actually started, how the semicolon in the PRINT statement held output on the same line, how the decision was made to print the half or not, and other details of the program.
[Current backup at https://joel-rees-economics.blogspot.com/2021/04/bk-33209-school-shoe-sizes-and-basic.html.
Developed January and February 2021, notes at
https://joel-rees-economics.blogspot.com/2020/01/notes-33209-school-basic-vs-pascal-vs.html.
Extracted and expanded from
https://joel-rees-economics.blogspot.com/2020/01/bk01-33209-school.html.
Earlier backup at
https://joel-rees-economics.blogspot.com/2020/01/bk-33209-school.html.]
No comments:
Post a Comment