Download presentation
Presentation is loading. Please wait.
Published byBridget Flynn Modified over 8 years ago
1
Chapter 2: Input, Processing, and Output Starting Out with Programming Logic & Design by Tony Gaddis (with instructor modifications) 1-1
2
1-2 Chapter Topics 2.1 Designing a Program STEPS OF THE PROGRAM DEVELOPMENT CYCLE 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types 2.5 Named Constants 2.6 Hand Tracing a Program (‘Desk Checking’) 2.7 Documenting a Program
3
1-3 The PROGRAM DEVELOPMENT CYCLE: 1.“UNDERSTAND THE PURPOSE” OF THE PROGRAM ---- THE ‘REAL’ FIRST STEP! 2.“DESIGN THE LOGIC” - The 2 nd step includes Hierarchy Charts and Flowcharts. 3.CODE or “Write the Code” in a High Level Language 4.TRANSLATE Code – thru Compile/Interpreting – also finds syntax errors 5.TEST Code - After the executable is created, this checks for logic errors 6.Debug – when logic errors exist, the program must be “debugged”. 7.DOCUMENTATION Actually first AND final step! KNOW THESE 7 STEPS!
4
The PROGRAM DEVELOPMENT CYCLE – in more detail…. 1. Understand the Problem Analyze Specifications (Programmer documentation) Record Layout (file layouts) Printer Spacing Chart Description IPO 2. Design the Logic Design Hierarchy and Logic using: Hierarchy/Structure Chart & Flowcharting/Pseudocode 3. Write the Code Write the code - Key the program - Save it! 4. Translate Program into Machine Language to correct Syntax Errors Converts code to machine language Interpret - translates one line at a time Compile - translates the whole program at once producing an Object List from your Source code –Debug - Fix your Syntax errors 5. Test the Program Execute/Run -The computer follows your instructions – only after syntax errors are fixed Ask Yourself: Is the OUTPUT what you want ? If not, fix your Logic Errors! 6.Debug the Code Fix any logic and look errors you may have 7. Documentation Documentation is continuous throughout the PDC – beginning when Specifications are created. Internal and External Documentation The next slides introduce you further into the details of the ANALYZE step….
5
Programming Specifications… Step 1 – Understand the Problem Analyze the Output using the “Printer Spacing Chart” – form used to define the “OUTPUT” layout (Part 1) –This shows how each line is to print on a report by providing…: Identification of the information to print and it’s format Location of the information on the page –Horizontally – including blank spaces –Vertically – including blank lines »For Heading Lines (constants/literal words) »For Detail Lines (the record processed from the file) »For Total/Summary Lines Sales Commission Report Emp Number Sales Person Sales Commission XXXXXXXXX XXXXXXXXXXXXXXXXXXXX $Z,ZZZ.99 ZZZ.99 End Of Report
6
How to Build the Printer Spacing Chart… X – for alphanumeric 9 – for numbers –Z = Zero Suppression -“Editing” with $ and. 1 – identify output 2 – determine order (left to right) 3 – determine width & format 4 – space data within report width(usually 80 character positions) 5 – determine & place headings-meaningful abbreviations are ok! 6 – when totals are to be output - label and space them also! ie: Total Sales $ZZ,ZZZ.99 Sales Commission Report Emp Number Sales Person Sales Commission XXXXXXXXX XXXXXXXXXXXXXXXXXXXX $ZZZZ.99 ZZZ.99 End Of Report
7
Programming Specifications… PDC-S tep 1 – Understand the Problem (part 2) Analyze “File Description (File/Record Layout)” Form - this defines “INPUT ” –indicates how each data field is laid out for each record in the file – all records in a file have the same layout –Defines: Field Description/purpose Location (chronologically) = Size Type (Alphanumeric or Numeric) Decimal Positions, for numeric data …of each field Description Position Type Dec Emp # 1 - 9 Char(A) NAME 10 – 24 Char(A) SALES 25 – 30 Num(N) 2 - or - Emp No (A) 1 9 Sales Person Name (A) 10 24 Sales Amount (N) 25 28 29 30
8
Programming Specifications… PDC - S tep 1– Understand the Problem (part 3) Description – to get from “Input” to “Processing” to “Output” –Defines calculations and special processing steps required. –Often describes input and output also For Example: Introduction: This assignment is to design and code a program to produce a Sales Commission Report for all Salespeople at our company. Input: Employee Number, Salesperson’s name, and Sales Amount Processing: Calculate the Commission for each salesperson based on a fixed commission rate of 3%. Output Produce the report shown on the following printer spacing chart showing the input fields along with the Commission Amount
9
the IPO – to help you understand… (see pg 239-240 of Gaddis Text!) List Output Fields List Input Fields Determine how/where each output field comes from InputProcessingOutputTot al Emp # (EmpNumber) EmpNumber Employee Name (Name) Name Sales Amount (SalesAmount) Sales Sales * Commission Rate (.03) Commission Amount
10
1-10 2.1 Designing a Program Two steps in designing a program 1.Understand the tasks that the program is to perform. OK – this IS Step #1 – using what you just read… What does the customer want. 2.Determine the steps that must be taken to perform the task. Create an algorithm, or step-by-step logical directions to solve the problem. Use flowcharts (and/or pseudocode) to solve.
11
1-11 2.1 Designing a Program Pseudocode ‘Fake’/English code used as a model for programs No firm “standardized” syntax rules Well written pseudocode can be easily translated to actual code; but harder to write…need to know how to code first Display “Enter the number of hours” Input hours Display “Enter the hourly pay rate” Input payRate Set grossPay = hours * payRate Display “The gross pay is $”, grossPay
12
1-12 2.1 Designing a Program Flowcharts A diagram that graphically depicts the steps that take place in a program. We will learn this and how it fits into structured program design Terminator used for start and stop “Terminal” Symbol Parallelogram used for input and output “Input/Output” Rectangle used for processes “Process” symbol Simple, Unstructured Flowchart for the pay calculating program
13
1-13 2.2 Output, Input, and Variables Output – data that is generated and displayed – “meaningful” to the person who receives it who needs the “Information” Input – data that a program receives typically “un-meaningful” - from a data file or user input Variables – storage locations in memory for data Computer programs typically follow 3 steps IPO 1.Input is received 2.Some Process is performed on the input, using variables 3.Output is produced
14
1-14 2.2 Output, Input, and Variables Console.WriteLine( )is the keywords we’ll use to show output to the screen - for some languages. (‘display’ is used in some languages, Print in some…etc…) Sequence – lines execute in the order they appear String Literals – a sequence of characters, enclosed in quotations Output of Program 2-1 The statements execute in order
15
1-15 2.2 Output, Input, and Variables Input is the keyword to take values from the user (after a display ‘Prompt’) or ‘Input’ from a data file. The values input, “Data” is stored in named memory locations called: variables
16
1-16 2.2 Rules of Variable Naming…. Programmers define variable names & names must following certain rules –Must be one word (from the computers point of view) which means…no spaces –Generally, special characters are avoided –Generally, the first character cannot be a number –Name a variable something that indicates what may be stored in it – Be “meaningful” camelCase is popular naming convention or PascalCase (see the difference?) - this is the one we will be using!
17
1-17 2.3 Variable Assignment & Calculations Assigning data to a Variable does not always have to come from user input, it can also be set through an “assignment” statement. (later we’ll learn that it can also come from a ‘data file’) Notes: ‘Set’ is not needed - just write: Price = 20 Often use ; vs, to output literals & variables on 1 line
18
1-18 2.3 Variable Assignment & Calculations Calculations are performed using math operators The values are typically stored in variables, although ‘numeric literals’ can be used in the expression. sale = price – discount Common math operators
19
1-19 2.4 Variable Declarations & Data Types A variable declaration includes a variable’s name and a variable’s data type Data Type – defines the type of data you will store in a variable –Integer – stores only whole numbers –Decimal – stores values with decimal positions –String – any series of characters In Visual Basic we will use some, but not all, data types available An example of a declaration: –Private GrossPayDecimal as Decimal (Numeric variable) –Private NameString as String (Alphanumberic variable )
20
1-20 2.4 Variable Declarations & Data Types To avoid logic errors, ‘sometimes’ variables used in calculations are initialized to 0 or some other value, like a test score…. Accumulated Totals MUST BE Initialized to Zero Notes: We Declare all variables. Initializing requires that the ‘types’ must match…. You assign a “string” to a string and integer to integer etc…. NumberInteger = 12 WordString = “String” Private Test1Integer as Integer = 90 Private Test2Integer as Integer = 70 Private AverageDecimal as Decimal AverageDecimal = (Test1Integer + Test2Integer) / 2 Console.WriteLine(“The average of “ & Test1Integer & “ and ” & Test2Integer & “ is “ & AverageDecimal) would output: The Average of 90 and 70 is 80
21
1-21 2.5 Named Constants A named “constant” is a special variable that represents a value that cannot be changed – It’s value stays ‘constant’ for the execution of the program… –This makes programs more self explanatory –If a change to the value occurs, it only has to be modified in one place –Make the constants name ALL.CAPS ie: Private CONST INTEREST_RATE _DECIMAL = 0.069
22
1-22 2.7 Documenting a Program External documentation describes the program for the user, sometimes written by a technical writer – includes: specifications, IPO, flowchart, code, test data, run time instructions Internal documentation explains purpose of the program for the programmer – inside the program. Also known as comments/remarks We will use an‘ (apostrophe) to denote comments within our programs for each line we wish to comment Note: Comments can be at the end of a line of code
23
Other Programmer documentation… The Data Dictionary Contains information about each data field… it’s –Name –Size –Data type –Description –There are some applications which actually create the Data Dictionary automatically…. Ours does not … so…I’ll have you describe your data fields as part of your program documentation (when we get to that…)
24
Final Documentation Type - “User” Documentation All manuals and instructional materials Typically: Non Technical & Includes: –How to prepare input –Who gets the output and how –How to interpret ‘normal’ output –How to read and fix error messages –When the program is scheduled to run Additional Documentation for Operational Personnel Includes: ◦ Backup and recovery procedures ◦ Run time instructions ◦ Security concerns
25
Next ….. Chapter 3 continues with Modules & Structure Charts then we’ll flowchart followed by a complete design and coding example… Structure charts are the first step of the Design requirement (#2) of the Program Development Cycle: 1 – Analyze Specifications to understand the problem 2 – Design the Logic Structure Charts (aka: Hierarchy Charts) Flowcharting 3 – Code the program in a high level language 4 – Translate program to machine language 5 – Test the Program 6 – Debug 7 – Documentation ( which is what you begin with also)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.