Chapter 2: General Problem Solving Concepts

Slides:



Advertisements
Similar presentations
CS 240 Computer Programming 1
Advertisements

PROBLEM SOLVING TECHNIQUES
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
UNIT 2. Introduction to Computer Programming
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Algorithms and flow charts
INTRODUCTION TO PROGRAMMING
 Control structures  Algorithm & flowchart  If statements  While statements.
Al-Karma Language School Computer Department Prep. 3.
Chapter 2- Visual Basic Schneider
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Algorithm Design CS105. Problem Solving Algorithm: set of unambiguous instructions to solve a problem – Breaking down a problem into a set of sub- problems.
Structured Program Development in C
Chapter 2: Algorithm Discovery and Design
CHAPTER 4: ALGORITHM 4.1 Introduction stages identified in the program development process: 1. Problem analysis and specification 2. Data organization.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
PRE-PROGRAMMING PHASE
Algorithms and flow charts
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Algorithm & Flowchart.
Chapter 1 Pseudocode & Flowcharts
The University of Texas – Pan American
Chapter 2: Problem Solving
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
C Lecture Notes 1 Structured Program Development.
Definition of Terms Software/Programs Programs that directs the operation of a computer system Set of instructions Codes Programming Process of planning,
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
Chapter 1 Pseudocode & Flowcharts
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Program Planning and Design Important stages before actual program is written.
Structured Programming (4 Credits)
The Hashemite University Computer Engineering Department
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Program design Program Design Process has 2 phases:
GC101 Introduction to computers and programs
Unit 3: ALGORITHMS AND FLOWCHARTS
Chapter One Problem Solving
Algorithm & Programming
Chapter 2- Visual Basic Schneider
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithm – part 1
Programming Fundamentals
Structured Program
Chapter 3 - Structured Program Development
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 3 - Structured Program Development
Chapter 2- Visual Basic Schneider
Flowcharts and Pseudo Code
Introduction to Programming
Basic Concepts of Algorithm
WJEC GCSE Computer Science
Presentation transcript:

Chapter 2: General Problem Solving Concepts Computer Programming Skills-2 4800153-3 1435/1436 Place photo here Chapter 2: General Problem Solving Concepts Department of Computer Science Foundation Year Program Umm Alqura University, Makkah

The Objectives and the outcomes To be able to understand the problem. To be able to analyze the problem. To be able to produce an algorithm that solves the problem. The Outcomes: Students should be able to understand the problem. Student should be able to analyze the problem. Students should learn how to solve the problem.

Introduction to Programming and Programming language Programming language is an artificial language that specifies instruction to be executed on a computer. There are two types of programming languages : Low level languages High level languages

Introduction Computer Languages: There are many types of computer languages, which can be categorized into the following four types: Low-Level Languages (1st & 2nd Generation Languages) High-Level Languages (3rd Generation Languages) User-Friendly Languages (4th Generation Languages) Object-Oriented Languages (5th Generation Languages)

introduction Main Operations of High Level Language Program Input operations: Like input, read Output operations: Like write, print Arithmetic operations: Like adding, subtracting, multiplying etc.... Control transferring operations: Like “GO TO”, conditional, non-conditional, etc.... Looping: Like repeat, do while, for, etc...

introduction Analyze the problem Identify the variables involved Main Steps in Developing a Program: Analyze the problem Identify the variables involved Design the solution Write the program Enter the program into a computer Compile the program and correct errors Correct the logical errors if any Test and debug program with data Document the program

An Algorithm: A sequence of precise instructions, which leads to a solution, is called an algorithm. Examples: Steps (algorithm) to solve a first degree equation. Steps (algorithm) to solve a second degree equation using delta. In other words, algorithm is a method of representing the step-by-step logical procedure for solving a problem.

According to D.E. Knuth, an algorithm must possess the following properties: Finiteness: An algorithm must terminated. Definiteness: Each step of the algorithm must be precisely and unambiguously stated. Effectiveness: Each step must be effective, Generality: The algorithm must be complete in itself Input/output: Each algorithm must take zero, one or more quantities as input data produce one or more output values.

Example: Find the algorithm for solving a first degree equation, in the form Ax=B. Sol. Read the values A, B Check if A=0 (if yes there is no equation) therefore no equation to be solved (end processing). Check if B=0 (if yes X=0 and end processing). Calculate the value of X= B/A Print the value of: X

Algorithm Representation There are many techniques in which we may represent an algorithm when thinking of writing a computer program. The techniques that are to be studied are: Flowchart: The flowchart represents a graphical representation of the steps required for an algorithm or program. Pseudocode: It is an informal high level description of the operating principle of a computer program or other algorithm.

Pseudocode: It is an informal high level description of the operating principle of a computer program or other algorithm. Example 1: Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Set the class average to the total divided by ten Print the class average.

Example 2: Initialize passes to zero Initialize failures to zero Initialize student to one While student counter is less than or equal to ten Input the next exam result If the student passed Add one to passes Else Add one to failures Add one to student counter Print the number of passes Print the number of failures If eight or more students passed Print "raise tuition"

Flowchart: The flowchart represents a graphical representation of the steps required for an algorithm or program. The flowchart is characterized by: Clarifying the program logic Identifying alternative processing methods Serving as guide for program coding Serving as documentation There are some principals that should be followed up when putting the Flowchart, such as: Simplicity Organization Planning

Flowchart: General Concepts: Flow chart must be characterized by: The major element of the project. Elements are clearly labeled. Sequence of elements must be clear. No gap or dead ends. Sequence of elements must be in logical form. Flowchart must be used correctly.

Flowchart: General Concept Levels of Program Flowchart: Simple sequential flowchart: Branched flowchart. Simple-loop flowchart. Multi-loop flowchart.

Flowchart: Simple sequential flowchart: It is simplest level which contain the sequence of steps without loops or branch and the flowchart comes in straight line from the beginning to the end.

Flowchart: Branched flowchart: It is branched flowchart, when there is a condition statement in the program.

Flowchart: Simple-loop flowchart: It is a flowchart, which contain iteration or repetitions. It is usually called loop flowcharts. In this type we need to repeat some operation several times using the same set of operation.

Flowchart: Multi-loop flowchart: Looping is used to manage a loop to fulfill a repetition under a definite condition. It takes the following special symbol.

Table 2.1 represents the symbols that are used to draw the flow chart.

Examples

Example1: Algorithm for reading student name

Example2: Algorithm for calculating the area of circle

Example 3: Draw flow chart for evaluating the following functions: F(x) = x if x>=0 F(x) = -x if x<0

Example 3: Draw flow chart for evaluating the following functions: F(x) = x if x>=0 F(x) = -x if x<0

Example 4: Write an algorithm and draw the flow chart to find the circumference of circle.

Example 5: Write an algorithm and draw a flowchart to print 10 integers starting from 1.