Separate speaker notes to accompany structureprog2 which is the presentation on structured programming that goes with chapter #2 in the text Programming Logic and Design by Joyce Farrell.
This presentation will show the programs that could be written to accompany some of the flowcharts and pseudocode in chapter #2 of Programming Logic and Design by Joyce Farrell. I will show her flowcharts and then show my code.
Flowchart and pseudocode from page 41 called Functional, structured flowchart and pseudocode with some minor changes made by me.
This shows a simple COBOL program written to implement the logic shown on the previous slide. COBOL is one of the original structured languages and is used heavily in business. According to statistics I have seen, close to half of the programs in use today world wide were written in COBOL.
Data that you are using is stored in what is called the WORKING-STORAGE SECTION of the DATA DIVISION. This section is usually broken down into categories which have an 01 in front of them and actual places to store data that have an 05 in front of them. For now we will just use those two numbers.
The size of the data clause and the type of data is given in the PIC clause. PIC stands for picture meaning a picture of the data. If the field is numeric, you use 9 to tell the computer what type it is. If the field is character/string you use X to tell the computer what type it is. Note that the length is given with repetition of the 9 or X. If you code 999 that means it is a 3 character numeric field. If you code X that means it is a 1 character string field. Note that 999 can also be written as 9(3).
Note also that there is a FILE SECTION in the DATA DIVISION. We would use this section if we were reading or writing files. I could have eliminated that line from the code. I left it in to make the point that there are two kinds of data: data that is associated with files and data that are used as work areas.
The next slide will talk about the PROCEDURE DIVISION where the actual commands are given.
This slide shows what I call the initializing read (your book calls it the priming read). This is reading or taking in data that the user enters. The user can only enter 2 characters and they must be numeric. This is because the storage area that is going to receive the user input is set up as PIC 99 meaning it can only hold two numeric characters.
The next slide will analyze the procedure division line by line matching the pseudocode.
If you match the colors in the pseudocode with the colors in the code, you can see how the pseudocode has been turned into computer code.
All of the variable names used in the code have been defined in the DATA DIVISION (specifically in the WORKING-STORAGE SECTION) part of the DATA DIVISION.
Again note that the code has FILE SECTION in here but it is not used since I am not reading data from a file. This line could have been eliminated.
This shows processing using an input file that contains data as opposed to user entry. Notice that the READ statement is used instead of DISPLAY/ACCEPT and that when the READ is not successful it says an EOF-IND that is defined as a variable to Y. Notice also that the PERFORM statement says do this loop over and over again until the EOF-IND is equal to Y.
This shows the output - I took a picture when the screen was filled and then took another picture when it was done. As you can see there were only a few more so you can see a lot of what was on the first picture in the second picture.
When end of file is reached, the Run message box is displayed. When I click OK, the program ends.
This shows a program running in Visual Basic (VB).
Note that when the user is done, they click on the End button and the program ends.
With event driven programming you are counting on the user controlling the program as they enter data.
After explaining this code, I will use a file and then we will see a loop that is closer to the flowchart and pseudocode we have seen in this presentation.
This slide shows the Visual Basic environment, the form and the code. I will discuss the code on the next slide.
This shows the code for this very basic Visual Basic program. Note that the variable to hold the answer when the number is doubled is set up and named wkDoubleNum.
The processing is done when a button is clicked. The processing is user controlled and there is no loop. The user enters a number and clicks to process. Then the user enters another number and clicks to process.
The stop is also a click event. The user clicks the End button to stop processing.
This shows the environment including the code and form for a visual basic program that reads a file and displays the information. The program as it runs and the file are shown on the next slide.
In VB we can see the data on individual lines - the default when you make a file for Visual Basic is one line for a record.
Note that there is a difference in the Pseudocode that I am using for VB. Here I did not use the initializing read and the read at the bottom of the loop. Instead I used the get input at the top of the loop. The reason for this is that VB checks ahead and knows whether the next attempt to get a record would mean end of file. Therefore, if the next record does not exist, it does not even enter the loop to try and read it. It only enters the loop when there is input to be gotten.