Programming Logic and Design: An Overview of Computers and Programming
Programming Logic and Design: An Overview of Computers and Programming
Icebreaker Activity
The class will be broken up into pairs of students.
Each student will create three questions to ask their partner:
- One True/False question;
- One question that can be answered with a number;
- One question that requires a short answer.Partners will take turns asking the questions they’ve prepared.
Each student will then introduce their partner to the class using the information they’ve learned.
Chapter Objectives
Upon completing this chapter, you will be able to:
- 01.01 Describe the components of computer systems
- 01.02 Develop simple program logic
- 01.03 List the steps involved in the program development cycle
- 01.04 Write pseudocode statements and draw flowchart symbols
- 01.05 Use a sentinel value to end a program
- 01.06 Describe programming and user environments
- 01.07 Describe the evolution of programming models
Understanding Computer Systems
Definition and Components
Computer System: A combination of all components required to process and store data using a computer.
Hardware: Equipment associated with a computer (physical components).
Software: Computer instructions that tell the hardware what to do.
Software Components
Programs: A set of computer instructions written by programmers.
Programming: The act of writing software instructions.
Logic of a Computer Program: The complete sequence of tasks that lead to the solution of a problem.
Types of Software
Application Software: Includes word-processing programs, spreadsheets, payroll, inventory programs, and games.
System Software: Includes operating systems such as Windows, Linux, and UNIX for larger computers, and Google Android and Apple iOS for smartphones.
Major Operations in Programs
Input: Data items such as text, numbers, and other raw material that are entered into and processed by a computer.
Processing: Organizing or sorting data, checking for accuracy, or performing calculations using the Central Processing Unit (CPU).
Output: The resulting information after data processing sent to output devices such as printers, monitors, or storage devices.
Cloud Computing
The Cloud: Refers to devices at remote locations accessed through the Internet.
Programming Languages
Definition: Used to write computer instructions (program code).
Coding: The act of writing instructions.
Examples: Visual Basic, C#, C++, or Java.
Syntax and Errors
Syntax: Rules governing word usage and punctuation in programming languages.
Syntax Errors: Mistakes in language usage. These errors prevent the code from being fully translated and executed.
Computer Memory: The computer's temporary internal storage where program instructions are stored.
- Random Access Memory (RAM): A form of internal, volatile memory; contents are lost when the computer is turned off.Permanent Storage Devices: Non-volatile memory that retains data even when powered off.
Compilers and Interpreters
Compiler: Translates entire program source code into machine language (object code) before execution. Checks for syntax errors prior to execution.
Interpreter: Translates and executes each instruction just prior to execution, does not require complete translation of the program before running it.
Program Execution
When instructions are executed, a program runs—input is accepted, processing occurs, and results are output.
Knowledge Check Activity
What does the cloud refer to?
- Answer: Devices at remote locations accessed through the Internet.
Understanding Simple Program Logic
Programs with syntax errors cannot be translated, hence cannot be executed.
Programs without syntax errors might have logical errors, resulting in incorrect outputs.
Example Program Logic: Doubling a Number
- Input:myNumber
- Processing:myAnswer = myNumber * 2
- Output:myAnswer
Operations in the Number-Doubling Process
Input Operation:
input myNumberProcessing Operation:
myAnswer = myNumber * 2Output Operation:
output myAnswer
Understanding the Program Development Cycle
Stages of the Program Development Cycle
Understand the Problem: Identifying user needs.
Plan the Logic: Outlining steps and order of operations.
Code the Program: Writing the actual code based on the plan.
Use Software (Compiler/Interpreter): Translate the program into machine language.
Test the Program: Check for correctness and functionality.
Put the Program into Production: Production rollout to users.
Maintain the Program: Making necessary updates and fixes post-deployment.
Documentation
All supporting paperwork provided to programmers to help understand the problem is known as documentation, which is crucial.
Planning the Logic
Tools for Planning
Flowcharts: Visual representation of the logic.
Pseudocode: English-like representation outlining logical steps.
Algorithm: A sequence of steps or rules to solve a problem.
Desk-Checking: Manually reviewing program logic on paper to anticipate data variation scenarios.
Coding the Program
Hundreds of programming languages available, chosen based on specific needs.
While some programmers may combine logic planning and coding in one step, coding typically follows the logic planning phase.
Using Software to Translate the Program
Compilers/Interpreters ascertain syntax errors by providing error messages, prompting programming corrections.
Debugging: The process of identifying and correcting errors in a program.
Testing the Program
Logical Errors: Result from syntactically correct statements that yield incorrect outcomes.
After debugging, programmers test the program with sample data to confirm output accuracy.
Putting the Program into Production
The process varies based on program purpose and may require months to transition.
Conversion: The entire set of actions required for organizations to switch to a new program/system.
Maintaining the Program
Continuous changes and updates post-production require programmers to revisit the development cycle.
Pseudocode Statements and Flowcharts
Definition of Pseudocode
Pseudocode offers a straightforward, logical way to describe algorithms primarily using structured statements resembling natural language.
Writing Pseudocode Example
For Number-Doubling Problem:
start input myNumber myAnswer = myNumber * 2 output myAnswer stop
Standards for Writing Pseudocode
Always begin with
startand end withstopaligned, indent statements, and ensure logical clarity.
Drawing Flowcharts
Process Symbols: Use geometric shapes to represent steps, connected by arrows.
Input Symbol: Parallelogram shape indicating an input operation.
Processing Symbol: A rectangle containing processing statements.
Output Symbol: Similar to input, often a parallelogram.
Flowlines: Arrows demonstrating the order of operations.
Terminal Symbol: Indicates program start/stop.
Standard Flowchart Shapes
Input: Parallelogram
Processing: Rectangle
Output: Parallelogram
Terminal: Lozenge/Racetrack shape
Continuing Structures: Looping and Sentinel Values
Loops
Loop: A mechanism for repeating a block of code, essential to avoid repetition and increase efficiency.
Infinite Loop: A loop that continues indefinitely without terminating.
Sentinel Value in Programming
Decision Symbol: Diamond shape indicating the evaluation of a condition in flowcharts.
Dummy Value or Sentinel Value: A preselected value used to halt a program's execution and does not represent actual data nor real input.
**EOF (