Chapter 2: Input, Processing, and Output Starting Out with Programming Logic & Design by Tony Gaddis (with instructor modifications) 1-1.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 3: Modules, Hierarchy Charts, and Documentation
Chapter 2: Modularization
Introduction to Flowcharting
Programming Logic and Design Fourth Edition, Introductory
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Chapter 2- Visual Basic Schneider
COSC 120 Computer Programming
Chapter 2: Input, Processing, and Output
Modules, Hierarchy Charts, and Documentation
Understanding the Mainline Logical Flow Through a Program (continued)
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Chapter 1 Program Design
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 3 Planning Your Solution
Programming Logic and Design Fourth Edition, Introductory
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Structured COBOL Programming, Stern & Stern, 9th edition
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Simple Program Design Third Edition A Step-by-Step Approach
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Input, Output, and Processing
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Chapter 1 Introduction to Structured Design. Introduction  System  A combination of people, equipment, and procedures that work together to perform.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Introduction to Programming with RAPTOR
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
1 Program Planning and Design Important stages before actual program is written.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
The Hashemite University Computer Engineering Department
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Topics Designing a Program Input, Processing, and Output
Completing the Problem-Solving Process
Chapter 2: Input, Processing, and Output
Chapter 2- Visual Basic Schneider
The Selection Structure
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Chapter 2- Visual Basic Schneider
Chapter 2- Visual Basic Schneider
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition
Chapter 2: Input, Processing, and Output
Presentation transcript:

Chapter 2: Input, Processing, and Output Starting Out with Programming Logic & Design by Tony Gaddis (with instructor modifications) 1-1

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

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!

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….

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

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

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 # Char(A) NAME 10 – 24 Char(A) SALES 25 – 30 Num(N) 2 - or - Emp No (A) 1 9 Sales Person Name (A) Sales Amount (N)

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

the IPO – to help you understand… (see pg 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

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.

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

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

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

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

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

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!

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

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

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 )

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

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

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

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…)

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

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)