Monday, January 13, 2020

33209: School -- Shoe Sizes, Flowcharting, and Pseudo-code

Chapter 3.3: School -- Shoe Sizes and Pascal

Chapter 3.4: School -- Shoe Sizes, Flowcharting, and Psuedo-code

Back in the classroom, Professor Crane passed out copies of the simple version of the BASIC program.

"Mmm. Fresh Ditto. Smells good!" Dirk sniffed the paper.

"Is ditto fluid addicting?" Lisa asked no one in particular.

"Spirit duplicator fluid could be addictive and intoxicating if you do too much copying in a closed space, but I don't think there's enough left on these pages to do any real damage." I picked my page up and sniffed.

"Thank you for your analysis, Mr. Genius." Lisa grinned to show she was just teasing.

I ducked my head and grinned back.

"Okay, let's look at this and turn it into a flowchart." Professor Crane picked up a marker from the whiteboard tray. "Becky, you wanna do the artwork today?" 

(This was a different Becky from the student who had accompanied me on the piano at the first recital.)

"Uhm, okay." Becky stood up hesitatingly and went to the front of the room. 

Professor Crane handed her the marker, and she stood, waiting.

"What's the first thing we do here?" Professor Crane looked around at the students. "Theo?"

"Print the program title?" Theo responded.

"Okay."

Becky turned to the board and started drawing.

After about five minutes, we had produced the following flowchart as a class:

"What do we have to change on this flowchart if we use the second program?" Professor Crane asked.

George raised his hand. "Print converted size becomes a subroutine call, is all, isn't it?"

"Becky? What do ya think?"

Becky nodded. "So I add double side lines to the print converted size box like this?" She added the lines in the way our classes were being instructed to indicate subroutine calls.

"And then we add a short flowchart to show what that does," Mike pointed out.

It took another five minutes of discussion to produce the following flowchart of the subroutine:

"Is everyone pretty comfortable with these flowcharts?" Professor Crane looked around the class again.

Alex raised her hand. "Should we expand other parts?"

I responded, "Depends on how much detail you want in the flowchart, right?"

Professor Crane nodded. "That brings up something I need to explain. I mentioned before, I think, that different people use different symbols in flowcharts."

We all agreed.

"Some people use the parallel lines to merely mean that there is a logical module there. It might be a subroutine call or it might be something called a macro, which I'll have to explain sometime, or it might be many lines of code that they want to describe as a single functional block."

Mike responded, "You said that before."

"I did. Well, there is a symbol you might want to use to show this is really a subroutine call. Becky, may I?" He held out his hand, and Becky gave him the marker. 

"Thank you. You can take a break now."

Becky grinned a "Yay!" and sat down.

"It looks sort of like a punched card." He drew the following on an empty spot on the board:

I think most of us took that down in our notes somewhere. I just adjusted my flowchart.

Pat asked, "I've been using macros at work. I'm not really sure what they are."

"Mmm," Professor Crane looked at the clock. "I want to talk about pseudo-code before we break up for today. Can we do that tomorrow?"

"Yeah, I guess."

Professor Crane turned on the overhead projector, directed the projected image to the side of the flowchart, and took out a slide and a marker. "Pseudo-code is something like a programming language and something like natural language." He looked around at us. "Like English." He wrote: 

Shoe Size Conversion Table 

Show title.

Get conversion direction.

Get start and end. 

For shoe sizes from start to end,

print conversion line,

George  commented, "You're almost just copying the contents of the flowchart and making it more like English." 

"Pretty much. As you see, it uses indentation something like the Pascal source code we just saw a little bit ago, but it's a bit freer in form and allows more descriptive. It's often fairly easy to convert a clean flowchart to pseudo-code, or back-and-forth between pseudo-code and a language like Pascal. Some people find pseudo-code easier to use than flowcharts."

"Are you going to expand every line of that?" I asked.

"That depends on you, and on the group you're working for. For some groups, any further conversion of the above should be directly to code. For others, more detail is wanted."

Mike asked, "If 'print-conversion-line' is the name of the subroutine, you could pseudo-code the subroutine, right?"

"You and Joe," Professor Crane grumbled jokingly. "Exactly right." And he proceeded to do so:

Print conversion line

Take integer part of converted size.

Take fractional part.

If fractional part is 3/4 or more, 

increment integer part and clear fractional part;

else if fractional part is less than 1/4,

clear fractional part.

Print integer part.

If fractional part is non-zero, 

print "1/2".

He handed out ditto copies of the Pascal source code for us to compare.

I looked over at Pat, and she looked up at me. 

"Maybe macros are just some way to pull the actual source code in-line into the program instead of calling it like a subroutine?" I suggested. 

She looked puzzled.

"I've seen them mentioned in the microprocessor documentation my brother gave me, and the assembly listings actually show the macro lines as if they were part of the source."

"That might make sense."

I looked up and noticed Professor Crane standing beside my desk. 

He was shaking his head. "Maybe I should just let you and Mike take over for me, and I'll just kick back and put my feet up in the back of the room."

"Sorry."

"No problem." He grinned broadly. "You really don't need a copy of the Pascal, do you?"

He handed me my copy.

"Yeah, thanks. I think I need it." I grinned back.

The bell rang.

He announced from where he was, "We'll talk more about pseudo-code, Pascal, and macros next time. In the meantime, I want to see the flowcharts you've each drawn up, and I want you to try writing a quick program in BASIC to let the user type in a conversion direction and a shoe size, and print out the conversion. It should be easy, and it'll let me see whether you were listening today. Turn your listings and flowcharts in at my office."

The class broke up with the usual grumbling and jesting.

TOC

[Current backup at https://joel-rees-economics.blogspot.com/2020/01/bk-33209-school-shoe-sizes-flowcharting-and-pseudo-code.html.
Developed February and March 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

33209: Discovering the 6800 -- Parents and Polygamy

A Look at the 8080/TOC "Whoa, Merry, look who's here!" Jim said, sotto voce. He, Roderick, and I were at our lab table ...