CSE 110: Programming Language I Matin Saad Abdullah UB 404.

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
Advertisements

Introduction to Flowcharting
Introduction to Flowcharting
PSEUDOCODE & FLOW CHART
Flow Control Analysis & Design Tool: Flowcharts
UNIT 2. Introduction to Computer Programming
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Chapter 2- Visual Basic Schneider
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Developing logic (Examples on algorithm and flowchart)
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Chapter 3 Planning Your Solution
The Program Design Phases
Review Algorithm Analysis Problem Solving Space Complexity
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
PRE-PROGRAMMING PHASE
Algorithm & Flowchart.
Fundamentals of C programming
Chapter 1 Pseudocode & Flowcharts
ALGORITHMS AND FLOWCHARTS
CSC103: Introduction to Computer and Programming
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CSC141 Introduction to Computer Programming
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.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Software Life Cycle What Requirements Gathering, Problem definition
ENGR-25_Programming-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Registered Electrical.
Flowcharts.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
Algorithms & Flowchart
Program Planning and Design. What is Program Planning and Design? Program planning and design is simply knowing what you want to do and how you want to.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
Principles of Programming - NI July Chapter 2: Problem Solving In this chapter you will learn about: Introduction to Problem Solving Software development.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Chapter 7 Problem Solving with Loops
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
1 CS362 High Level Program Design Tool Structure Chart © 2011, Regis University.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
CSE 101 Lesson - 1 Number System & Program Design Sonia corraya (SOC)
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
 Problem Analysis  Coding  Debugging  Testing.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Algorithms and Flowcharts
(Courtesy: Dr. Amitabha Chakrabarty) Lesson - 2 Number System & Program Design CSE 101.
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Computer Programming.
Chapter 2- Visual Basic Schneider
Computer Programming Flowchart.
Lecture 2 Introduction to Programming
Introduction To Flowcharting
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
Chapter 2- Visual Basic Schneider
Introduction to Programming
Basic Concepts of Algorithm
Programming Logic and Design Eighth Edition
Introduction to Programming
Presentation transcript:

CSE 110: Programming Language I Matin Saad Abdullah UB 404

Problem Solving Start with a real-world problem that needs to be solved Convert the real-world problem into a computational problem Develop an algorithm and use it to solve the computational problem  An algorithm is a precise list of instructions that determine what operations to perform on what pieces of data, in what order

Algorithm Example Consider the problem of computing the sum of 2 numbers which are entered by the user at the keyboard: Possible algorithm to solve the problem:  Read (i.e. input) the first number and store it in the computer  Read the second number and store it in the computer  Add the first number to second number to produce a sum, SUM. Store SUM in the computer  Display (i.e. output) the value of SUM

Computer Programming  A computer is a machine that can compute  What does “compute” mean ?  Can represent & manipulate data  Programming is about finding a way to tell the machine what computational operations it must do on what data  A program is just an algorithm, expressed in a language the computer an understand

Programming Overview Program Design Process has 2 phases:  Problem Solving Phase  Creates an algorithm that solves the problem  Implementation (Coding) Phase  Translates the algorithm into a programming language

Flow Control Design Tool: Flowcharts Flowchart - a graphical way of writing algorithms  Rectangle is used for calculations  Parallelogram is used for input and output  Circle is used as connector  Diamond is used as decision  Symbols are connected by arrows to represent the order of the operations

Sequential Program Statements With sequential program statements, you execute one statement after another (like steps in a list)  After step X is completed, step X+1 will be performed, until the last statement has been executed. Every step in the list will be performed. Each step in the list will be performed once and only once.

Pseudocode Sequential Algorithm Example (1/2) Real World Problem:  Calculate two childrens’ allowances, based upon 75 cents per year old. Known Values  Rate = 75 cents per year Inputs  Ages of children Calculations  Allowance = Age x Rate Outputs  Allowances for each child

Allow1 = Age1 x Rate input Age1 start Print Allow1 stop prompt Age1 Allow2 = Age2 x Rate Print Allow2 input Age2 prompt Age2

Non-Sequential Program Statements Programs that execute only sequential program statements are pretty simplistic. Most programs need more flexibility in the order of statement execution. The order of statement execution is called the flow of control. Control statements allow the execution of statements based upon decisions.

Flow of Control Statements Conditional statements:  Decide whether or not to execute a particular statement or statements  Also called the selection statements or decision statements.

Pseudocode Selection Algorithm Example (1/2) Real World Problem:  Calculate one child’s allowance, based upon 75 cents per year old if s/he is under 10, and $1 per year if 10 or over. Known Values  YoungRate = 75 cents per year  OlderRate = 100 cents per year  BreakAge = 10 Inputs  Age of child Calculations  Allowance = Age x Rate Outputs  Allowance

Allow = Age x YoungRate start Print Allow stop prompt Age Allow = Age x OlderRate Age < 10 FALSETRUE input Age

Flow of Control Statements Loop statements:  Repeatedly execute the same statement(s) for a certain number of times or until a test condition is satisfied.

Pseudocode Looping Algorithm Example (1/2) Real World Problem:  Calculate the total allowance paid to each of three children at $1 per year old. Known Values  Rate = $1 per year  NumKids = 3 Inputs  Ages of children Calculations  Allowance = Age x Rate Outputs  Total Allowance paid

start Display Total stop Read Age Calc Allowance KidsPaid < 3 FALSETRUE KidsPaid = 0 Total = 0 Add Allowance to Total Increment KidsPaid Prompt Age

Flow Control Design Tool: Flowcharts Flowchart - a graphical way of writing algorithms  Rectangle is used for calculations  Parallelogram is used for input and output  Circle is used as connector  Diamond is used as decision  Symbols are connected by arrows to represent the order of the operations

High-Level Design Tool: Structure Charts So a flowchart:  Details exactly HOW your program will do each task In contrast, our next design tool, the structure chart:  Shows only WHAT tasks your program will do (not HOW it will complete them)

High-Level Design Tool: Structure Charts Structure charts are hierarchical diagrams  They diagram the overall program structure  They show the relationship between all the tasks in the program  They indicate which data is shared by the tasks

Creating a Structure Chart A large program design is first broken into tasks Tasks are repeatedly divided into even smaller subtasks  Rectangles are used to represent tasks/subtasks within the program  Lines are used to hierarchically connect the tasks/sutasks  Subtasks are diagrammed below the task that they are part of Task SubTask1SubTask2

Creating Structure Charts  An upward arrow indicates that the data value has been set inside the task and is being passed out for use by other tasks  A downward arrow indicates a data value previously set in some other task is now being passed into this task  Data may also be passed both into a task (downward arrow), modified, and passed back out again (upward arrow). Task SubTask1SubTask2 Data1 The passing of data between tasks is shown by arrows going up from or down to the task’s rectangle

Sample Structure Chart main Get_InputProcess_DataDisplay_Results Data Result Data Result Given a generic program that reads some data from the user, runs some calculations using that data, and displays results to the user, the structure chart could look like this:

Structure Chart for Sequential Program main Get_AgesCalculate_AllowancesDisplay_Allowances Age1, Age2 Allow1, Allow2 Age1, Age2 Allow1, Allow2 Using our previous sequential program design example (calculate your two childrens’ allowances, based upon 75 cents per year old), the structure chart might be:

Structure Chart for Selection Program main Get_AgeCalculate_AllowanceDisplay_Allowance AgeAllowanceAge Allowance Using our previous selection program design example (calculate one child’s allowance, based upon 75 cents per year old if s/he is under 10, and $1 per year if 10 or over), the structure chart might be:

Structure Chart for Selection Program main Get_AgeCalculate_AllowanceDisplay_Allowance AgeAllowanceAge Allowance Note that this SAME structure chart could also have been used for the sequential program (calculate your two childrens’ allowances, based upon 75 cents per year old). Each of the modules in the chart would be called by main TWICE.

Structure Chart for Looping Program main Get_Age Calc_Allowance_TotalDisplay_Total Age Total Calc_Allowance Allowance Age Using our previous looping program design example (calculate the total allowance paid to each of three children at $1 per year old), the structure chart might be: The Get_Age and Calc_Allowance modules would be called every time the program loops.

Summary of Structure Chart Creation Put name of program in rectangle root of an upside-down tree. Determine the main subtasks that must be performed by the program to solve the problem.  Put main subtasks in rectangles below the root, and draw a connecting line from the root to each subtask. Examine each subtask individually, and break them down into even smaller tasks.  Put subtasks in rectangles below the task that they are part of, and draw a connecting line from task to subtask. Repeat until the bottom tasks of the tree are very simple tasks to complete