- Meeting 4 – Writing a Complete Program

Slides:



Advertisements
Similar presentations
Chapter 3: Modules, Hierarchy Charts, and Documentation
Advertisements

Chapter 3: Modularization
Chapter 2: Modularization
Programming Logic and Design Eighth Edition
Repetition There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is.
Repetition Control Structures
Modules, Hierarchy Charts, and Documentation
Programming Logic and Design Sixth Edition
Programming Logic and Design Fourth Edition, Introductory
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Programming Logic and Design, Second Edition, Comprehensive
Programming Logic and Design, Third Edition Comprehensive
Programming Logic and Design Fourth Edition, Introductory
ITEC113 Algorithms and Programming Techniques
Objectives In this chapter, you will learn about:
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Writing a Complete Program
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
Modules, Hierarchy Charts, and Documentation
Understanding the Mainline Logical Flow Through a Program (continued)
Guide To UNIX Using Linux Third Edition
Chapter 1 Program Design
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 3 Planning Your Solution
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Simple Program Design Third Edition A Step-by-Step Approach
Programming Logic and Design, Second Edition, Comprehensive
Programming Logic and Design Fifth Edition, Comprehensive
Programming Logic and Design, Second Edition, Comprehensive
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Programming Logic and Design Fifth Edition, Comprehensive
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
ITEC113 Algorithms and Programming Techniques
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
What is Programming? A program is a list of instructions that is executed by a computer to accomplish a particular task. Creating those instructions is.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
10 Chapter 101 Using Menus and Validating Input Programming Logic and Design, Second Edition, Comprehensive 10.
Chapter 11: Sequential File Merging, Matching, and Updating Programming Logic and Design, Third Edition Comprehensive.
11 Chapter 111 Sequential File Merging, Matching, and Updating Programming Logic and Design, Second Edition, Comprehensive 11.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Computer Programming 12 Lesson 4 - Computer Programming Structure By Dan Lunney.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Programming Logic and Design Fourth Edition, Comprehensive
Control Structures - Repetition
Designing and Debugging Batch and Interactive COBOL Programs
User Defined Functions
Topics Introduction to File Input and Output
Iteration: Beyond the Basic PERFORM
CHAPTER 17 The Report Writer Module
Data Groupings: File File: a group of related records
Writing a Complete Program
Modules Programmers break programming problems down into smaller, reasonable units called modules, subroutines, procedures, functions, or methods When.
Topics Introduction to Functions Defining and Calling a Function
Topics Introduction to File Input and Output
Chapter 4: Writing and Designing a Complete Program
Programming Logic and Design Eighth Edition
Presentation transcript:

- Meeting 4 – Writing a Complete Program 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 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

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.

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

Sample Case : Housekeeping

Sample Case : Housekeeping

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

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

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, and invQuantity, you do not provide them with any initial value

Sample Case : Housekeeping The report illustrated in previous contains 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

Sample Case : Housekeeping

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

Sample Case : Housekeeping

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

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

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 eof was encountered Not reading the first record within the housekeeping() module is a mistake

Sample Case : Housekeeping

Sample Case : Housekeeping

Sample Case : Housekeeping

Sample Case : Housekeeping

Sample Case : Housekeeping The main loop of a program, controlled by the eof decision, 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

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

Sample Case : Housekeeping

Sample Case : Housekeeping

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

Sample Case : Housekeeping

Sample Case : Housekeeping