INFO 0102 - Introduction to Problem Solving & Programming

INFO 0102 - Introduction to Problem Solving & Programming

Presented by: Denice Wiggins
Resource: Simple Program Design, A Step by Step Approach, 5th ed.


Page 1

Course Introduction

  • Overview of course content and expectations.


Page 2

Introduction

  • Icebreaker: Let’s Introduce ourselves.


Page 3

Agenda

  1. Course Introduction

    • Introduction

    • Presentation of course outline

    • Schedule and expectations

  2. Basic Concepts

    • Steps in Program Development

    • Program Design Methodologies

    • Program Data: Variables, Constants, Literals, and Elementary Data Types

    • Defining the problem using the IPO Model

    • Introducing Pseudocode

  3. Homework

    • Reference to Slide 18.


Page 4

Steps in Program Development

  • Computer programming is an art that requires creativity alongside technical skills.

  • Common misconceptions:

    • Requires strong mathematical skills.

    • Requires extensive memory for technical information.

  • With appropriate tools and steps, well-designed programs can be developed by anyone, making programming fulfilling and stimulating.

  • Definition of Programming:

    • Development of a solution to an identified problem and a related series of instructions for computer hardware to produce desired results.

    • Emphasis on problem definition which is often overlooked, leading to issues like errors that require extensive debugging time.

  • Experienced programmers first design a solution, perform desk checks on the solution, and then code in a programming language.


Page 5

Steps in Program Development Outline
  1. Define the Problem

  2. Outline the Solution

  3. Develop the outline into an algorithm

  4. Test the algorithm for correctness

  5. Code the algorithm into a specific programming language

  6. Run the program on the computer

  7. Document and maintain the program


Page 6

Step 1: Define the Problem

  • Initial analysis of the problem is crucial: read and reread it to understand fully.

  • Break into three components:

    1. Inputs: Data required for processing.

    2. Outputs: Desired results from the processing.

    3. Processing Steps: Steps to transform inputs into outputs.

  • Example:

    • Task: Calculate the cost of 3 packs of sugar

    • Inputs: Price of one pack of sugar, number of packs purchased

    • Processing: Multiply price by quantity

    • Outputs: Total cost.


Page 7

Step 2: Outline the Solution

  • Break down the problem into smaller tasks:

    • Major Processing Steps: Identify main actions needed (e.g., calculate totals).

    • Major Subtasks: Identify subtasks that comprise the main problem (e.g., calculating an average).

    • User Interface: Plan user interactions including screens, prompts, or forms.

    • Control Structures: Define logic controls like decisions (IF/ELSE) and repetition (loops).

    • Variables and Data Structures: Outline the main data used by the program.

    • Mainline Logic: Overall sequence of steps from program start to finish.


Page 8

Step 3: Develop the Outline into an Algorithm

  • Expand the solution outline into an algorithm detailing each task's specific steps.

  • Example:

    • Problem: Calculate total cost of items.

    • Pseudocode (Step-by-Step):

    1. Start

    2. Enter the price of the item

    3. Enter the quantity

    4. Multiply price by quantity

    5. Display the total cost

    6. End


Page 9

Step 4: Test the Algorithm for Correctness

  • Critical step in program development often overlooked.

  • Goal: Identify major logic errors early for easy corrections.

  • Walk through the logic of the algorithm with test data, tracking major variables on paper.


Page 10

Step 5: Code the Algorithm into a Specific Programming Language

  • Only start coding after fulfilling design considerations from previous steps.


Page 11

Step 6: Run the Program on the Computer

  • Utilize a compiler and designed test data to machine-test code for:

    • Syntax Errors: Detected at compile time.

    • Logic Errors: Detected at runtime.

  • Generally the rewarding step if prior designs have been effective.

  • Testing may require multiple iterations until satisfactory performance is achieved.


Page 12

Step 7: Document and Maintain the Program

  • Documentation is an ongoing task from the initial definition to final results.

  • It includes both:

    • External Documentation: Hierarchy charts, solution algorithms, test data results.

    • Internal Documentation: Annotations within code.

  • Program Maintenance: Refers to changes made to the program throughout its lifecycle, often by a different programmer.

  • Well-structured programs simplify maintenance due to self-documenting code.


Page 13

Program Design Methodologies


Page 14

Program Design Methodologies Overview

  • Fundamental principle: Programs accept inputs, process data, and deliver outputs.

  • Common approaches:

    1. Procedure-driven

    2. Event-driven

    3. Data-driven


Page 15

Procedure Driven Approach

  • Emphasizes the tasks the program must execute over data used.

  • Begins with identifying main tasks/functions, organized in logical order, then assesses data flow into/out of each task.

  • The organization of processes is prioritized before considering data structure details.


Page 16

Event Driven Approach

  • Centers on reactions to events occurring (user actions, system prompts).

  • The program changes states based on user interaction:

    • Starts waiting for an action (e.g., mouse click).

    • Transitions between states triggered by events.

  • Example sequence:

    • Program initializes → Wait

    • User clicks a button → Program responds

    • Another user action → Program responds again.


Page 17

Data Driven Approach

  • Focuses on data stability over processing methods.

  • Begins with analyzing data and relationships to define fundamental data structures.

  • After defining structures, examine required outputs to outline necessary processes converting inputs to outputs.

  • Skill Development: Regardless of the design method, practitioners must develop basic skills to design solution algorithms while adhering to the defined program development process outlined earlier.


Page 18

Procedural vs Object-Oriented Programming Approaches

  • Top-Down Design: Starts general and delves into finer details for complete solutions.

  • Modular Design: Organizes code into independent modules for task performance, aiding understanding and maintenance.

  • Object-Oriented Programming (OOP): Focuses on real-world objects, integrating data and actions, facilitating interactions between objects to solve problems.

Homework:

  1. Discuss how top-down helps in breaking large problems into manageable steps.

  2. State the importance of modular design for program clarity and maintenance.

  3. Differentiate between object-oriented and procedural programming methods in problem-solving.


Page 19

Program Data: Variables, Constants, Literals and Elementary Data Types


Page 20

Program Data Definitions

Term

Explanation

Example

Variable

A named storage location in memory whose data can change during program execution.

score = 10 (changes to score = 20)

Constant

A fixed value that remains unchanged throughout program execution.

MAX_MARK = 100

Literal

A value written directly in the program without a designated name.

100, 'A', `