Wednesday, November 20, 2013

Simpleton Geek Teaches Computer Programming Book 2 Chapter 6B


6.2 CLS, PRINT, LOCATE, CSRX,CSRY
The students were all going through the steps in operating their Nintendo and Petit Computer app. The teacher went on to describe the operation and the care of Nintendo device. The students were warned to not drop their device into the water, for example.
Then the teacher showed how to use Petit Computer. He pointed out that there is a HELP button on the lower left on the screen, and that they should use it whenever they get stuck.
“Here's a trick that you may want to use. It's really optional, but I found that it'll cut down the amount of computer programming I need to do: Go through the menu, and write down on a piece of scrap paper all the commands grouped by function. Then go through the alphabetical listing of commands, and write down what's listed there. One groupings per page! Then, instead of having to open up the help menu every time you need to refer to a command, you have it all lined up in your journal. You may find it easier to practice and memorize them this way, too.”
The students don't feel like doing it. It sounds like double the work, but as they don't want to incur the wrath of the teacher, they simply kept quite. Only Peter, the hard-working student, put a note in the journal “To Do: Summarize Command by Group.”
“So, let me show you the structure of the top screen. You see a single top screen. However, it is actually composed of many different screens, each layered one upon another. The first is the background color screen. Then there's a character graphic layer screen. Then another character graphic layer on top of it. Then bit-map graphic layer. Another layer for hardware sprite layer, and finally a character text layer.
“The most important thing to understand is, just because you're seeing something on screen, does not mean that you know which layer is which. So, you have to keep track of which layer you're using. It can be confusing sometimes, but you'll just have to suffer through it!
“Since you're just a beginner, we're going through the layer one by one, in chronological order. So, we're going to start with the character text layer. As the name implies, character text deals with alphabet. There's a character chart on the help page, which will be your homework. You need to reproduce that on your notebook. I want to see the character code (a number), and its graphic representation.”
The students wrote this on their journal. They will have to look through the Help menu to see which screen they have to copy.
“I should warn you that the character list is NOT ASCII! ASCII stands for American Standard Code for Information Interchange. It represents the first 127 characters of various functions. This is not ASCII. ASCII does not have alien characters in their code, for examples.”
The student laughed at this info.
“Another warning is that the character for blank (code #0) is NOT the same as the character for space (code #32). You represent space character with a slashed lower case 'b'.
“Finally, let's get started. Two commands you want to use: CLear Screen (CLS) command, and PRINT command. Now. I want you to search through the help menu and look those over, and I want you to turn in a program that predicts the weather with at least 51% accuracy before the class is over.”
All the students gasped in shock and surprised. A weather predicting program? In half-hour? Impossible!
Once the student went over the shock of the impossible task, they began reading the help file in vain attempt to find some kind of hints regarding the task of weather programming. Doesn't the weather needs some numbers? Some kind of calculations? The students furiously read the help screen materials in order to write the weather predicting program.
“Teacher!” asked a student, “What is the difference between CLS, GCLS, and ACLS?”
“CLS will clear the text screen. That's the standard command since old, early computers. GCLS clears the graphic screens, instead of the text screen. They are two different screens, remember? Just because they are superimposed over each other doesn't mean they're the same screen. ACLS clears both screens at once.”
“Are we using anything other CLS forms? GCLS, or ACLS, I mean.”
“You can certainly use ACLS. I don't see a problem with that. However, I don't see why you want to use GCLS since we're not into computer graphic, yet.”
The student then goes back to work. What is required to write a weather predicting program? One that is right more often than not? The students are absolutely clueless. It takes a lot to learn from the help file.
“Teacher, why is the PRINT command always goes to the next line?” asked another student.
“You mean the cursor will go to the next line. The printed text is where you want it, right?”
“I mean, if you do two PRINT commands, they each got printed at separate lines.”
“Oh, that's right. If you want to print words that is next to each other, use a semi-colon at the end.
PRINT “WORD 1”
PRINT “WORD 2”
PRINT “WORD 3”;
PRINT “WORD 4”
“Notice that WORD 1 and WORD 2 are printed on separate lines, while WORD 3 and WORD 4 are printed together. You can also combine the two strings in one line, either with semi-colon or comma. Using a comma is equivalent to using a TAB character, which will line it up to a line.”
PRINT “HELLO”;”WORLD”
PRINT “HI”,”THERE”
“One more thing,” the teacher added, “You can use the question mark as a shorthand for PRINT. Simply replace the word PRINT with a question mark.”
PRINT “HELLO WORLD”
?”HELLO SAILOR”
“When in doubt, just try it out and see.” the teacher concluded. “By the way, you have 5 minutes left. Better hurry up with that weather predicting program! How come nobody has finished it by now? It's not a hard program at all!”
The students all threw up their arms in frustration. Writing a weather predicting program is easy? They couldn't believe it! They certainly couldn't believe it when Peter brought along a piece of paper to the teacher.
“How's this?” asked Peter, showing his finished program to the teacher.
“I'd say that is an excellent effort, worthy of being scored 100%!” said the teacher.
Peter walked back to his seat, smiling all the way.
The rest of the students are just stunned. “Teacher!” said a student, “This is absolutely impossible!”
“Of course, it's not impossible.” replied the teacher. “There's a paper scored with 100 on it, right here.” he was waving Peter's solution around. The rest of the students just don't know what to say.
“Time's up! If you have something to show, better turn in your paper to me, now. Otherwise, you get zero!”
Although a few students ventured to turn in their paper, the teacher just tossed them out to waste basket after a quick scan of them. “Just a bunch of zeros. Why can't you get it right?”
“But it's impossible!” said a student.
“Peter got 100. The rest of you losers get zero.” Then the teacher went to the board. “This is the answer I'm looking for.”
CLS
PRINT “TOMORROW'S WEATHER WILL BE SUNNY!”
“And that's it! Considering that the weather is sunny most of the time, I'd say you can easily have 80% plus accuracy! Why is that so difficult?”
The students are stunned into speechlessness. It simply hasn't occurred to them to pick the most common weather pattern and stick to it. “Is that what Peter wrote?” asked a student.
“No.” said Peter.
“This is what he wrote.” answered the teacher.
CLS
?”Hang a rock in the garden.”
?
?”If it's dry, it's sunny.”
?”If it's wet, it's rainy.”
?”If it's white, it's snowing.”
?”If it's moving, it's windy.”
?”If it's dark, it's cloudy.”
?”If it's all white, it's foggy.”
“And that's the program.” said the teacher. “Obviously, he didn't have to do that much, but a weather prediction program is just as good as any other. The requirement is that it is right more often than not, and this certainly qualifies!”
The bell rang, and before the students can say anything, the teacher left, laughing away.
The next day, the teacher arrived, looking at a bunch of gloomy faces. Obviously, the students are all disappointed at the event the day before. The teacher thought about this for a while. Then he asked, “So, does anybody want to tell me what's wrong?”
“Teacher,” Nancy said, “We're so helpless, we don't think we're fit to be computer programmers!”
“Is that so?” said the teacher, “Then what good are you?” The students have no answer to that. “The journey of 10,000 steps begins with the first one. If you failed to do even that, then you are indeed a bunch of losers.”
“But we don't think we're smart enough for that!”
“Well, that maybe true. Of course, it hasn't stopped some people from being computer programmers!”
“Really?”
“Sure. You may have to work much harder at it than smart people, but if you do it long enough, and hard enough, you'll get it eventually. The way it is now, I can't tell whether or not you have talent for computer programming because we haven't even started yet!”
The student couldn't believe it! It has been several weeks into the semester and they haven't started computer programming? What have they been learning all these time?
“It is clear that your problem solving skill in non-existent, but what I can tell you is that we're going to take it slow. In fact, if you're having trouble doing something, take it as a sign that you're doing it wrong!”
“Really, teacher? If we're having trouble, then we're doing it wrong?”
“Of course. This is a school, after all, not real life. Trust me that I will not put anything that is outside your capability.”
Having scored near zeros on the test and quizzes, the students are not convinced.
“Listen, imagine a bonsai tree. You see them, and they're beautiful. But trees don't grown that way. You see, they're shaped to grow that way. So, when the tree was growing, they put wires on the branches to let the tree grow a certain way. In the end, you have a beautiful bonsai tree for the showing.
“Now imagine if you did not put wires on the tree while it was growing. Now the trees are in the wrong shape. What are you going to do? If you then try to bend the tree into a pleasing shape, you will not succeed. The branches will break, and you have no tree.
“That is why, it is important to let you guys grow into a certain shape. It's not going to be pleasant, but in the end, you guys will grow into beautiful bonsai trees everybody can be so proud of.”
The students thought about this for a while. “So, we're being shape into beautiful shapes?” asked Nancy.
“Well, the truth is, you have all grown up already. So, in your case, more like breaking branches and glue them together. Sorry to be the bearer of bad news, but there it is.”
The students all wailed in frustration.
“Smarter students will have an easier time doing it. They can adapt to situations better. So, why not be smart about it?”
“We can be smart?”
“Of course.” said the teacher.
“Are we smart already?”
“We can find out. One of the fastest way to see if you're smart is via introspection. This is the way it goes...”
All the students sat up straight in anticipation.
“If you think you're smart, you're wrong.” The teacher said. “If you think you're stupid, you're right!” The teacher concluded.
“What? But then, it's impossible to be smart!”
“Of course, it's possible. You just don't know it yet.”
“How can we be smart?”
“Why don't you think about it for a while? Let's make that your homework since I don't think you're capable of working computer science homework just yet.”
The students just look at each other. What kind of homework is that? How can they be smart?
“Oh, another homework.” said the teacher. “I want you to take your journal and divide it into 32 by 24 squares. And I want you to write a message into the squares, and I want to see text all the way to the end border.
“It can be anything. Grandma's rule. House rules. Words of Wisdom. Quotation. Anything that will fit into 32 by 24. Bonus points will be given if you include fancy characters.
“Can it be anything? Even random?” asked Peter.
“Sure. Feel free to make it ASCII Art if you want to. The only requirement is that you fill the screen. That's it.”

No comments:

Post a Comment