Programming Logic and Design: Input, Processing, and Output
Program Design
First step: Design (using flowcharts and pseudocode).
Steps: Understand tasks, determine steps (create algorithm).
Program Development Cycle: Design -> Code -> Clear syntax errors -> Create executable -> Check for logic errors -> Debug.
Pseudocode: "Fake code" model, no syntax rules; easily translated to actual code.
Flowcharts: Graphical depiction of program steps.
Connector Symbol: Breaks flowcharts into smaller, side-by-side ones.
Off-Page Connector Symbol: Links flowcharts across different pages.
Output, Input, and Variables (IPO)
Output: Data generated and displayed.
Input: Data a program receives.
Variables: Storage locations in memory.
Typical Program Sequence: Input received -> Process performed -> Output produced.
IPO Chart: Describes Input, Processing, Output of a program.
Keywords:
Displayfor output,Inputfor user values.Sequence: Lines execute in order.
String Literals: Sequence of characters.
Variable Naming Rules: One word (no spaces), avoid punctuation, first character usually not a number, indicative name,
camelCasepopular.
Variable Assignment & Calculations
Assignment: Setting a variable's value (e.g.,
Set price = 20) or through user input.Calculations: Performed using math operators.
+: Addition-: Subtraction*: Multiplication (Asterisk)/: Division (Quotient)MOD: Modulus (Remainder)^: Exponent (Caret)Expressions result stored in variables (e.g.,
Set sale = price - discount).
Variable Declarations & Data Types
Declaration: Includes variable name and data type (
Declare Real grossPay).Data Type: Defines data stored:
Integer: Whole numbers.Real: Whole or decimal numbers.String: Any series of characters.
Initialization: Variables should be initialized (e.g., to ) to prevent logic errors.
Named Constants
Definition: A name representing an unchangeable value.
Benefits: Self-explanatory programs, easy value modification in one place.
Example:
Constant Real INTEREST_RATE = 0.069.
Hand Tracing a Program
Purpose: Simple debugging process for hard-to-find errors.
Method: Create a chart with columns for each variable and rows for each line of code.
Documenting a Program
External Documentation: Describes program aspects for the user.
Internal Documentation (Comments): Explains how parts of the program work for programmers.
Syntax:
//for line comments,/* ... */for multiline comments.
Language Focus: Java
Program Structure:
public class ClassName { public static void main(String[] args) { /* code */ } }Output:
`System.out.println(