1 / 28

- Meeting 4 – W riting a Complete Progra m

- Meeting 4 – W riting a Complete Progra m. By: Felix Valentin, MBA. Today Topic:. Understanding the Mainline Logical Flow Through a Program Sample Case : Housekeeping. Understanding the Mainline Logical Flow Through a Program.

schuyler
Download Presentation

- Meeting 4 – W riting a Complete Progra m

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. - Meeting 4 –Writing a Complete Program By: Felix Valentin, MBA

  2. Today Topic: • Understanding the Mainline Logical Flow Through a Program • Sample Case : Housekeeping

  3. Understanding the Mainline Logical Flow Through a Program • You can write a program that reads from an input file and produces a printed report as a procedural program—that is, a program in which one procedure follows another from the beginning until the end • You write the entire set of instructions for a procedural program, and when the program executes, each instruction takes place one at a time following your program’s logic

  4. Understanding the Mainline Logical Flow Through a Program • The overall or mainline logic of almost every procedural computer program can follow a general structure that consists of three distinct parts: • Initialization tasks. • Performing the main loop within the program. • Performing the end-of-job routine.

  5. Understanding the Mainline Logical Flow Through a Program • You can write any procedural program as one long series of program language statements, but most programmers prefer to break their programs into several parts • The module or subroutine names, of course, are entirely up to the programmer

  6. Sample Case : Housekeeping

  7. Sample Case : Housekeeping

  8. Sample Case : Housekeeping • Housekeeping tasks include all the steps that must take place at the beginning of a program • Very often, this includes four major tasks: • You declare variables • You open files • You perform any one-time-only tasks, such as printing headings at the beginning of a report • You read the first input record

  9. Sample Case : Housekeeping • Your first task in writing any program is to declare variables • Declaring a variable involves selecting a name and a type

  10. Sample Case : Housekeeping • Some programming languages do provide you with an automatic starting value; for example in BASIC or RPG, all numeric variables automatically begin with the value zero • Be especially careful to make sure all variables you use in calculations have initial values • When you declare the variables invItemName, invPrice, invCost, andinvQuantity, you do not provide them with any initial value

  11. Sample Case : Housekeeping • The report illustrated in previouscontains three individual heading lines • You are not required to create variables for your headings • Using variable names is usually more convenient than spelling out the heading’s contents, especially if you will use the headings in multiple locations within your program • Notice that the three heading variables defined are not indented under invRecord like the invRecord fields are

  12. Sample Case : Housekeeping

  13. Sample Case : Housekeeping • If a program will use input files, you must tell the computer where the input is coming from • This process is known as opening a file • The program also needs to know the name of the file being opened • In many languages if no input file is opened, input is accepted from a default or standard input device, most often the keyboard • Again, if no file is opened, a default or standard output device, usually the monitor is used

  14. Sample Case : Housekeeping

  15. Sample Case : Housekeeping • A common housekeeping task involves printing headings at the top of a report • In the inventory report example, three lines of headings appear at the beginning of the report • In this example, printing the heading lines is straightforward: print mainHeading print columnHead1 print columnHead2

  16. Sample Case : Housekeeping • The last task you execute in the housekeeping()module of most computer programs is to read the first data record in memory • When you read the four data fields for the inventory file data, you can write read invItemName, invPrice, invCost, invQuantity, but if you have declared a group name such as invRecord, it is simpler to write read invRecord Chapter 4

  17. Sample Case : Housekeeping • When the last task within housekeeping() reads the first invRecord, the first task following housekeeping() is to check for eof on the file that contains the inventory records • Immediately after reading from a file, the next step always should determine whether eofwas encountered • Not reading the first record within the housekeeping() module is a mistake

  18. Sample Case : Housekeeping

  19. Sample Case : Housekeeping

  20. Sample Case : Housekeeping

  21. Sample Case : Housekeeping

  22. Sample Case : Housekeeping • The main loop of a program, controlled by theeofdecision, is the program’s “workhorse” • Each data record will pass once through the main loop where calculations are performed with the data and the results printed Chapter 4

  23. Sample Case : Housekeeping • For the inventory report program to work, the mainLoop()module must include three steps: • Calculate the profit for an item • Print the item information on the report • Read the next inventory record Chapter 4

  24. Sample Case : Housekeeping

  25. Sample Case : Housekeeping

  26. Sample Case : Housekeeping • Within any program, the end-of-job routine holds the steps you must take at the end of the program after all input records are processed • Some end-of-job modules print summaries or grand totals at the end of a report • The end-of-job module for the inventory report program is very simple Chapter 4

  27. Sample Case : Housekeeping

  28. Sample Case : Housekeeping

More Related