Chapter Two: Program Design Process and Logic

Size: px
Start display at page:

Download "Chapter Two: Program Design Process and Logic"

Transcription

1 Chapter Two: Program Design Process and Logic 2.1 Chapter objectives Describe the steps involved in the programming process Understand how to use flowchart symbols and pseudocode statements Use a sentinel, or dummy value, to end a program Use a connector symbol Assign values to variables 2.2 Introduction 2.3 Program development Lifecycle (PDLC) Program development Lifecycle (PDLC) refers to the steps programmers follow when building computer programs. There are six steps which include: Understand the problem Plan the logic Code the program Use software to translate the program to machine language Test the program Deploy the program into production Understand the problem/analyze the problem It s the most difficult phase in program design since the users may not able to articulate their needs pretty well. Users need keep on changing. The process may force the programmers to learn the user s functional tasks. The programmer is supposed to meet with the system analysts and the users with an aim of understanding what the problem is. The programmer should also identify the programs input, output and processing components. Failure to understand the problem is the major cause of most project failures Planning the logic During this stage, the programmer is supposed to plan the steps the program will take. At this stage, the program activities are grouped into modules. A solution algorithm for each phase is provided and tested. Programmers using some design tools which can be graphical or written description for each module. Tools such as algorithms, flowcharts and pseudocode are used to design the program logic. 16

2 2.2.3 Coding the program At this stage of program, the programmer selects the programming language based on the task at hand then writes instructions which implement the algorithms in step Translate the source code into machine language Programmers write instructions (source code) in English-like highlevel languages. This source codes have to be translated by translator program low-level machine language that can be executed. During the translation, syntax errors are indentified by the translator program Testing the program During this stage, the programmer executes the program with sample data and checks the results then compare them with the user s requirements. During this phase logic errors are indentified and corrected. When choosing the sample data make sure you are careful to exercise all branches of the logic Putting the program into production This is done after testing is complete and all errors in the programs have been corrected. It may require coordination with other related activities or software Maintain the program The last activity of the PDLC is maintaining the program. Maintaining the program involves a number of activities such as Identifying the errors Indentify any enhancements Modifying existing programs to improve their functionality 2.4 Programming design and logic tools There are basic three program design techniques that programmers can use while designing a program; algorithms, flowcharts and pseudocode. Some are visual tools while others are English like statements representing the logic 2.5 Algorithms The term algorithm originally referred to any computation performed via a set of rules applied to numbers written in decimal form. We can define an algorithm as a set or list for list of instructions for solving a particular problem. Ideally, an algorithm is a representation of a solution to a problem. The language used to describe an algorithm to other people will be quite different from that which is used by the computer; however the actual algorithm will in essence be the same 17

3 If a problem can be defined as a difference between a desired situation and the current situation in which one is, then a problem solution is a procedure, or method, for transforming the current situation to the desired one. Algorithms can be designed using either flow charts or pseudocode. Example Write an algorithm that calculates the pay of employees based on the hours worked and the rate per hour 1. Start 2. Get hours_worked 3. Get rate_per_hour 4. Pay=hours_worked times rate_per_hour 5. Output the pay 6. Stop 2.6 Flow charts A flowchart is a diagrammatic/graphical representation that illustrates the sequence of operations to be performed to get the solution of a problem. It s a logical diagram that describes each step that the program must perform in order to arrive at a solution. It s a popular logic tool used for showing an algorithm in form of graphics They are generally drawn in the early stages of formulating computer solutions before coding Purpose of flowcharting Introduction to Programming 18 An aid in developing the logic of a program. Verification that all possible conditions have been considered in a program. Provides means of communication with others about the program. A guide in coding the program. Documentation for the program Flowcharting Symbols There are 6 basic symbols commonly used in drawing flow chart diagrams; Terminal, Process, input/output, Decision, Connector and Predefined Process. This is not a complete list of all the possible flowcharting symbols, it is the ones used most often in the structure of Assembly language programming. Symbol Name Function Process Decision Indicates any type of internal operation inside the Processor or Memory Used to make a decision which requires a boolean

4 value Used to invoke a Predefined process subroutine or an interrupt program. Connector A circle with a number or letter to identify the matching transfer location. Off the page Contains page number and connector a number of letter to identify the matching transfer location Denotes start/end of a Terminal program, process, or interrupt program Preparation Used in declaring and initializing identifiers or variables that will be used in the programs. Flow lines Shows flow of data Input/output Used for any Input / Output operation. Indicates that the computer is to obtain data or output results Rules for flowcharting 1. All symbols of the flowchart are connected with Arrows. 2. Flowchart symbols have an entry point on the top of the symbol with no other entry points. The exit point for all flowchart symbols is on the bottom except for the Decision symbol. 3. The Decision symbol has two exit points; these can be on the sides or the bottom and one side. 4. Generally a flowchart will flow from top to bottom. However, an upward flow can be shown as long as it does not exceed 3 symbols. 5. Connectors are used to connect breaks in the flowchart. Examples are: From one page to another page. From the bottom of the page to the top of the same page. An upward flow of more than 3 symbols 19

5 6. All flow charts start with a Terminal or Predefined Process (for interrupt programs or subroutines) symbol. 7. All flowcharts end with a terminal or a contentious loop. Example Design an algorithm and the corresponding flowchart for finding the sum of four numbers. Write an algorithm that calculates the pay of employees based on the hours worked and the rate per hour 2.7 Pseudocode Flowcharts were the first design tool to be widely used, but unfortunately they do not very well reflect some of the concepts of structured programming. Pseudocode, on the other hand, is a newer tool and has features that make it more reflective of the structured concepts. Unfortunately, the narrative presentation is not as easy to understand and follow. Pseudocode is a generic way of describing an algorithm without use of any specific programming language syntax. They cannot be executed on a real computer, but it models and resembles real programming code, and is written at roughly the same level of detail. Introduction to Programming 20 A pseudocode is a detailed yet a readable description of what a computer program or algorithm must do expressed in a formallystyled natural language rather than in a programming language. It uses English word. It s sometimes used as a detailed step in the process of developing a program. It allows designers/programmers to express the design in great detail and provides programmers a detailed template for the next step of writing code in a specific programming language. Pseudocode language Keyword ` Accept/input Close/stop Compute Declare Display/print/output Entry/start Exit If Move Perform Function allow data terminating a program mathematical computation defining various identifiers displaying contents marking the beginning marking the end comparing contents to copy or moved data perform procedure

6 For example a pseudocode to get the square of a number would be written as follows Another example of a pseudo-code which input three numbers from the keyboard and output the result. start Use variables: sum, number1, number2, number3 of type integer Accept number1, number2, number3 Sum = number1 + number2 + number3 Print sum Use variables:number,square of type integer Start Get number Compute squareno * 2 Print Stop End program 2.8 Control Structures/Logical Structures The key to better algorithm design and thus to programming lies in limiting the control structure to only three constructs. These are illustrated below: The sequence structure This structure is the most elementary structure whereby algorithms are constructed in such a way that, no condition step is required. The sequence structure is the logical equivalent of a straight line. For example, suppose you are required to design an algorithm for finding the average of six numbers, and the sum of the numbers is given Decision Structure /Selection Structure This type of a case where the algorithm has to make a choice of two alternatives by making decision depending on a given condition. We can also refer to them as cases selection structures when there are two or more alternatives to choose from. This general structure can be illustrated in a flowchart as follows F Task a Cond ition Task b T 21

7 The corresponding in pseudocode form is as follows If condition=true then Do task b Do task a End if Making Choices There are many occasions in program when making choices is required. Sometimes you may need to take a given action based on the user choice. All computer programming languages provide a means of selection usually it is in the form of If statement. For example, the following statement combines if statement together with logical operators to test for true or false as depicted below. If a = b print a = b The statement a=b is only printed when the condition tests true. The table below summarizes the logical operators used in pseudocode are Logical operator purpose = is equal to > is greater than < is less than <> is not equal to <= is less than or equal >= is greater than or equal Example The following shows how the selection control structure is used in a program where a user chooses the options for multiplying, adding or subtracting the numbers The corresponding pseudocode is as follows Use variables: choice, of the type character ans, number1, number2, of type integer display choose one of the following display m for multiply display a for add display s for subtract accept choice display input two numbers you want to use accept number1, number2 if choice = m then ans= number1 * number2 if choice = a then ans= number1 + number2 if choice = s then ans= number1 - number2 22

8 display ans Compound Logical Operators There are many occasions when we need to extend the conditions that are to be tested. It s possible to link conditions. For example in everyday language we say things like If I had the time and the money I would go on holiday. The and means that both conditions must be true before we take an action. We might also say I am happy to go to the theatre or the cinema. The logical link this time is or. Conditions in if statements are linked in the same way. Conditions linked with and only result in an action when all conditions are true. On the other side, conditions linked with an or lead to an action when either or both are true. Example The program is to input an examination mark and test it for the award of a grade. The mark is a whole number between 1 and 100. Grades are awarded according to the following criteria: Student score Grade >= 70 and <=100 First class honours >= 60 and <=69 Second class honours >= 50 and <=59 Second lower class >= 40 and <=59 pass >=0 and <=39 Fail Required Write the appropriate pseudocode for the above program logic Use variable: score of type real Display input student score Accept score If score>=70 AND marks<=100 Display first class honours If score>=60 AND marks<=69 Display display second class honours If score>=50 AND marks<=59 Display display lower class If score>=40 AND marks<=49 Display pass If score>=0 AND marks<=39 Display pass Display invalid score End if 23

9 The case statement Repeating the if else statements a number of times can be somewhat confusing. An alternative method known as the case statement is usually provided in a number of languages statement. The following example program segment outputs a message to the monitor screen describing the insurance available according to a category input by the user. Use variables: category of type character Display input category Accept category If category = U Display insurance is not available If category = A then Display insurance is double If category = B then Display insurance is normal If category = M then Display insurance is medically dependent Display entry invalid This can be expressed in a case statement as follows: Use variables: category of type character Display input category Accept category DO case of category CASE category = U Display insurance not available CASE category = A Display insurance is double CASE category = B Display insurance is normal CASE category = M Display insurance is medically dependent OTHERWISE Display entry is invalid ENDCASE Instead of using the word otherwise, one can use else Repetition/Iteration Structure 24

10 This kind of structure causes certain steps to be executed repeatedly until a certain condition has been met. Iterative structure can be implemented in three ways namely Repeat Until Loop The While Loop The For Loop Any program instruction that repeats some statement or sequence of statements a number of times is called iteration or a loop. The commands used to create iterations or loops are all based on logical tests. There three constructs for iterations or loops in our pseudocode. The Repeat Until loop. Its syntax is as follows REPEAT A statement or block of statements UNTIL a true condition For example a survey has been carried out to discover the most popular sport. The results will be typed into the computer for analysis. Write a pseudocode to accomplish this. REPEAT DISPLAY Type in the letter chosen or Q to finish DISPLAY A: Athletics DISPLAY S: Swimming DISPLAY F: Football DISPLAY B: Badminton DISPLAY Enter data ACCEPT letter If letter = A then Athletics = athletics + 1 If letter = S then Swimming = Swimming + 1 If letter = F then Football = Football + 1 If letter = B then Badminton = Badminton + 1 UNTIL letter = Q DISLAY Athletics scored, athletics, votes DISLAY Swimming scored, swimming, votes DISLAY Football scored, football, votes DISLAY Badminton scored, Badminton, votes The WHILE loop 25

11 It s a conditional loop which test for the condition first before executing any set of instructions.no action is performed at all if the first test causes the terminating condition to evaluate as false. Its syntax is as follows WHILE(a condition is true) ENDWHILE Example A statement or block of statements Write a pseudocode for a program that will output the square root of any number input until the number input is zero. In some cases, a variable has to be initialised before execution of the loop as shown in the following example. Use variable: number, square of type real DISPLAY Type in a number or zero to stop ACCEPT number WHILE number <> 0 Square = number * number DISPLAY The square of the number is, square DISPLAY Type in a number or zero to stop ACCEPT number ENDWHILE Introduction to Programming The FOR Loop 26 Usually used to execute statatements repeatedly for a specified number of times. It s the simplest form, initializing the variable as a starting point, a stop condition depending on the value of the variable. The variable is incremented on each iteration until it reaches the required value. The pseudo-code syntax will be: FOR(starting state, stopping condition, increment) Statements ENDFOR Example 13. FOR (n = 1, n <= 4, n + 1) DISPLAY loop, n ENDFOR The fragment of code will produce the output In the example, n is usually referred as the loop variable, or counting variable, or index of the loop. The loop variable can be used in any statement of the loop. The variable should not be assigned a new value within the loop, which may change the behaviour of the loop. For example, write a pseudocode for a program to calculate the sum and average of a series of numbers.

12 Use variables: n, count of the type integer Sum, number, average of the type real DISPLAY How many numbers do you want to input ACCEPT count SUM = 0 FOR (n = 1, n <= count, n + 1) DISPLAY Input the number from your list ACCEPT number SUM = sum + number ENDFOR Average = sum / count DISPLAY The sum of the numbers is, sum DISPLAY Average of the numbers is, average time-and-a-half for all hours worked over 40. Pseudo-code the task of computing gross pay given pay rate and hours worked. 3. Design an algorithm and the corresponding flowchart for finding the sum of n numbers Chapter summary 2.10 Chapter exercise 1. Design an algorithm and the corresponding flowchart for adding the test scores as given below 30, 50, 39, Mr. Patel pays his employees salary on weekly basis. The gross pay depends on the pay rate and the number of hours worked per week. However, if you work more than 40 hours, you get paid 27

FLOW CHART AND PSEUDO CODE

FLOW CHART AND PSEUDO CODE FLOW CHART AND PSEUDO CODE Flowchart A Flowchart is a pictorial representation of an algorithm. The First flowchart is made by John Von Newman in 1945. It is a symbolic diagram of operation sequence, dataflow,

More information

SNS COLLEGE OF ENGINEERING

SNS COLLEGE OF ENGINEERING SNS COLLEGE OF ENGINEERING DEPARTMENT OF CSE Presented By Thillaiarasu.N SCRAMBLE 2 Solution 3 What is Pseudocode? 4 Consists of: Short Readable Formally styled English language Used for: Explaining the

More information

Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING MULTIPLE SELECTION To solve a problem that has several selection, use either of the following method: Multiple selection nested

More information

IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

IDENTIFY WAYS OF REPRESENTING ALGORITHMS. IDENTIFY WAYS OF REPRESENTING ALGORITHMS. OBJECTIVES: Identify ways of representing algorithms: Content Representation of algorithms as Pseudocode or Flowcharts; use of flow chart symbols: input/output

More information

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS INTRODUCTION TO PROBLEM SOLVING Introduction to Problem Solving Understanding problems Data processing Writing an algorithm CONTINUE.. Tool

More information

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 CHAPTER 2 PROBLEM SOLVING TECHNIQUES Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 Software Engineering vs Problem Solving Software Engineering - A branch of Computer Science & provides

More information

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation. UNIT III PROBLEM SOLVING AND OFFICE AUTOMATION Planning the Computer Program Purpose Algorithm Flow Charts Pseudo code -Application Software Packages- Introduction to Office Packages (not detailed commands

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving CS 199 Computer Programming Spring 2018 Lecture 2 Problem Solving ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

Final Examination Semester 2 / Year 2010

Final Examination Semester 2 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2010 COURSE : PROGRAMMING LOGIC AND DESIGN COURSE CODE : CCIS1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 5 Structured Program Development Department of Computer Engineering How to develop

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 5 - Structured Program Development Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad How to develop a program? Requirements Problem Analysis

More information

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals Pradeep K. Sinha Priti Sinha Chapter 11 Planning the Chapter 11: Planning Computer the Program Program Slide 1/50 Learning Objectives In this chapter you will learn about: Programs

More information

IT 1033: Fundamentals of Programming Loops

IT 1033: Fundamentals of Programming Loops IT 1033: Fundamentals of Programming Loops Budditha Hettige Department of Computer Science Repetitions: Loops A loop is a sequence of instruction s that is continually repeated until a certain condition

More information

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Program Development Cycle Program development

More information

Outline. Program development cycle. Algorithms development and representation. Examples.

Outline. Program development cycle. Algorithms development and representation. Examples. Outline Program development cycle. Algorithms development and representation. Examples. 1 Program Development Cycle Program development cycle steps: Problem definition. Problem analysis (understanding).

More information

PROBLEM SOLVING AND PYTHON PROGRAMMING

PROBLEM SOLVING AND PYTHON PROGRAMMING ALGORITHM UNIT-1 It is defined as a sequence of instructions that describe a method for solving a problem. In other words it is a step by step procedure for solving a problem. Properties of Algorithms

More information

CSC 121 Spring 2017 Howard Rosenthal

CSC 121 Spring 2017 Howard Rosenthal CSC 121 Spring 2017 Howard Rosenthal Agenda To be able to define computer program, algorithm, and highlevel programming language. To be able to list the basic stages involved in writing a computer program.

More information

Stepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017

Stepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017 Stepwise Refinement Lecture 12 COP 3014 Spring 2017 February 2, 2017 Top-Down Stepwise Refinement Top down stepwise refinement is a useful problem-solving technique that is good for coming up with an algorithm.

More information

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem

More information

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving CS111: PROGRAMMING LANGUAGE1 Lecture 2: Algorithmic Problem Solving Agenda 2 Problem Solving Techniques Pseudocode Algorithm Flow charts Examples How People Solve Problems 3 A Problem exists when what

More information

Pseudocode. ARITHMETIC OPERATORS: In pseudocode arithmetic operators are used to perform arithmetic operations. These operators are listed below:

Pseudocode. ARITHMETIC OPERATORS: In pseudocode arithmetic operators are used to perform arithmetic operations. These operators are listed below: Pseudocode There are 3 programming/pseudocode constructs: 1. Sequence: It refers that instructions should be executed one after another. 2. Selection: This construct is used to make a decision in choosing

More information

Introduction to Flowcharting

Introduction to Flowcharting Introduction to Flowcharting 1 Acknowledgment This tutorial is based upon Appendix C from Starting Out with C++: From Control Structures to Objects (5th Edition) Copyright Tony Gaddis 2007 Published by

More information

Chapter 3 Structured Program Development in C Part II

Chapter 3 Structured Program Development in C Part II Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called

More information

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today.

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today. Lecture 6 Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today. Previously Decision structures with flowcharts Boolean logic UML

More information

5. Selection: If and Switch Controls

5. Selection: If and Switch Controls Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include 1 Programming in C Looping Subtasks We will examine some basic algorithms that use the while and if constructs. These subtasks include Reading unknown quantity of data Counting things Accumulating (summing)

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure Learning Objectives At the end of this chapter, student should be able to: Understand the requirement of a loop Understand the Loop Control Variable () Use increment (++) and decrement ( ) operators Program

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Fundamentals of Programming. Lecture 6: Structured Development (part one)

Fundamentals of Programming. Lecture 6: Structured Development (part one) Fundamentals of Programming Lecture 6: Structured Development (part one) Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu edu Sharif University of Technology Computer Engineering Department Outline Algorithms

More information

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use?

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use? Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem Solving CMPUT101 Introduction to Computing (c) Yngvi Bjornsson & Jia You 1 Why are Algorithms Important? If

More information

SNS COLLEGE OF ENGINEERING,

SNS COLLEGE OF ENGINEERING, SNS COLLEGE OF ENGINEERING, COIMBATORE Department of Computer Science and Engineering QUESTION BANK(PART A) GE8151 - PROBLEM SOLVING AND PYTHON PROGRAMMING TWO MARKS UNIT-I 1. What is computer? Computers

More information

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1 OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software

More information

Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING

Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING Computer programming BTI 10202 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING

More information

Chapter 1: An Overview of Computers and Logic

Chapter 1: An Overview of Computers and Logic Chapter 1: An Overview of Computers and Logic Programming Logic and Design, Third Edition Comprehensive Objectives After studying Chapter 1, you should be able to: Understand computer components and operations

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

Unit 1 Lesson 4. Introduction to Control Statements

Unit 1 Lesson 4. Introduction to Control Statements Unit 1 Lesson 4 Introduction to Control Statements Essential Question: How are control loops used to alter the execution flow of a program? Lesson 4: Introduction to Control Statements Objectives: Use

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Class 8 ALGORITHMS AND FLOWCHARTS. The City School

Class 8 ALGORITHMS AND FLOWCHARTS. The City School Class 8 ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution

More information

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python CONDITION CONTROLLED LOOPS Introduction to Programming - Python Generating Random Numbers Generating a random integer Sometimes you need your program to generate information that isn t available when you

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Repetition Algorithms

Repetition Algorithms Repetition Algorithms Repetition Allows a program to execute a set of instructions over and over. The term loop is a synonym for a repetition statement. A Repetition Example Suppose that you have been

More information

International Diploma in Computer Studies

International Diploma in Computer Studies Introduction to Programming - 1.1 International Diploma in Computer Studies Programming Methods Session 1 Introduction to Programming Introduction to Programming - 1.2 Contents What is a programming language?

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3. Algorithm Design & Problem Solving. Programming. Databases

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3. Algorithm Design & Problem Solving. Programming. Databases 2 CHAPTER 1 Algorithm Design & Problem Solving 3 CHAPTER 2 Programming 4 CHAPTER 3 Databases TABLE OF CONTENTS 1. ALGORITHM DESIGN & PROBLEM-SOLVING 1.1 Problem-solving & Design Every computer system is

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

Introduction to Computer Programming/Handout 01 Page 1 of 13

Introduction to Computer Programming/Handout 01 Page 1 of 13 Introduction to Computer Programming/Handout 01 Page 1 of 13 Table of Contents Table of Contents... 1 Learning Objectives... 2 Program... 2 Programmer... 2 Programming Language... 2 Types of Languages...

More information

(I m not printing out these notes! Take your own.)

(I m not printing out these notes! Take your own.) PT1420 Week 2: Software Program Design I (I m not printing out these notes! Take your own.) Today we'll be discussing designing programs: Algorithms and errors Flowcharts and pseudocode Sequence structures

More information

Chapter 3 Problem Solving and the Computer

Chapter 3 Problem Solving and the Computer Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an

More information

Final Examination Semester 3 / Year 2010

Final Examination Semester 3 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2010 COURSE : PROGRAMMING LOGIC AND DESIGN COURSE CODE : CCIS1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

CS112 Lecture: Loops

CS112 Lecture: Loops CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.

More information

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA AZUWIR MOHD NOR ROOM: Pusat Pengajian CABIN C PHONE: (04) 979 8249 Email: azuwir@kukum.edu.my Office hours: make appoinment or

More information

Chapter 4 The If Then Statement

Chapter 4 The If Then Statement The If Then Statement Conditional control structure, also called a decision structure Executes a set of statements when a condition is true The condition is a Boolean expression For example, the statement

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

Computer System and programming in C

Computer System and programming in C Approaches to Problem Solving Concept of algorithm and flow charts ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence

More information

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION Planning the Computer Program Purpose Algorithm Flow Charts Pseudocode -Application Software Packages-

More information

BIL101E: Introduction to Computers and Information systems Lecture 8

BIL101E: Introduction to Computers and Information systems Lecture 8 BIL101E: Introduction to Computers and Information systems Lecture 8 8.1 Algorithms 8.2 Pseudocode 8.3 Control Structures 8.4 Decision Making: Equality and Relational Operators 8.5 The if Selection Structure

More information

Algorithms and Problem Solving

Algorithms and Problem Solving Algorithms and Problem Solving Introduction What is an Algorithm? Algorithm Properties Example Exercises Unit 16 1 What is an Algorithm? What is an Algorithm? An algorithm is a precisely defined and ordered

More information

Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function?

Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function? Meeting 1 Introduction to Functions Part 1 Graphing Points on a Plane (REVIEW) A plane is a flat, two-dimensional surface. We describe particular locations, or points, on a plane relative to two number

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

1. Introduction to Programming

1. Introduction to Programming Computer Science I CS 135 1. Introduction to Programming René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

Steps to program development

Steps to program development Automate processes - Programming Concepts and Design Steps to program development A computer program is a set of formal instructions, which the computer executes in order to carry out some designated task.

More information

Previously. Iteration. Date and time structures. Modularisation.

Previously. Iteration. Date and time structures. Modularisation. Lecture 7 Previously Iteration. Date and time structures. Modularisation. Today Pseudo code. File handling. Pseudo code Pseudocode is an informal high-level description of the operating principle of a

More information

[Page 177 (continued)] a. if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65 << endl";

[Page 177 (continued)] a. if ( age >= 65 ); cout << Age is greater than or equal to 65 << endl; else cout << Age is less than 65 << endl; Page 1 of 10 [Page 177 (continued)] Exercises 4.11 Identify and correct the error(s) in each of the following: a. if ( age >= 65 ); cout

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

Full file at

Full file at Chapter 1 1. a. False; b. False; c. True; d. False; e. False; f; True; g. True; h. False; i. False; j. True; k. False; l. True. 2. Keyboard and mouse. 3. Monitor and printer. 4. Because programs and data

More information

Unit II. (i) Computer Programming Languages

Unit II. (i) Computer Programming Languages Unit II. (i) Computer Programming Languages Need of a computer programming language: A programming language is an artificial language designed to communicate instructions to a computer. Thousands of different

More information

You will have mastered the material in this chapter when you can:

You will have mastered the material in this chapter when you can: CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand

More information

Simple Java Programming Constructs 4

Simple Java Programming Constructs 4 Simple Java Programming Constructs 4 Course Map In this module you will learn the basic Java programming constructs, the if and while statements. Introduction Computer Principles and Components Software

More information

Chapter 4 Introduction to Control Statements

Chapter 4 Introduction to Control Statements Introduction to Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives 2 How do you use the increment and decrement operators? What are the standard math methods?

More information

Programming Logic and Design Sixth Edition

Programming Logic and Design Sixth Edition Objectives Programming Logic and Design Sixth Edition Chapter 6 Arrays In this chapter, you will learn about: Arrays and how they occupy computer memory Manipulating an array to replace nested decisions

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

Algorithms and Flowcharts

Algorithms and Flowcharts UNIT 2 Chapter 1 Algorithms and Flowcharts After studying this lesson, the students will be able to understand the need of Algorithm and Flowcharts; solve problems by using algorithms and flowcharts; get

More information

Boolean Logic & Branching Lab Conditional Tests

Boolean Logic & Branching Lab Conditional Tests I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists

More information

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d. Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Loops (while and for)

Loops (while and for) Loops (while and for) CSE 1310 Introduction to Computers and Programming Alexandra Stefan 1 Motivation Was there any program we did (class or hw) where you wanted to repeat an action? 2 Motivation Name

More information

C Programming for Engineers Structured Program

C Programming for Engineers Structured Program C Programming for Engineers Structured Program ICEN 360 Spring 2017 Prof. Dola Saha 1 Switch Statement Ø Used to select one of several alternatives Ø useful when the selection is based on the value of

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

CS101 Introduction to computing Problem Solving (Computing)

CS101 Introduction to computing Problem Solving (Computing) CS101 Introduction to computing Problem Solving (Computing) A. Sahu and S. V.Rao Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati 1 Outline Problem Solving : Process involves Definition,

More information

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ). LOOPS 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ). 2-Give the result of the following program: #include

More information

Structure Array 1 / 50

Structure Array 1 / 50 Structure Array A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a structure using dot notation of

More information

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs PDS Lab Section 16 Autumn-2017 Tutorial 3 C Programming Constructs This flowchart shows how to find the roots of a Quadratic equation Ax 2 +Bx+C = 0 Start Input A,B,C x B 2 4AC False x If 0 True B x 2A

More information

Structured Program Development in C

Structured Program Development in C 1 3 Structured Program Development in C 3.2 Algorithms 2 Computing problems All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action. Chapter 5 Conditional and Iterative Statements Statement Statement are the instructions given to the computer to perform any kind of action. Types of Statement 1. Empty Statement The which does nothing.

More information

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection) Objectives In this chapter, you will: Learn about control structures Examine relational

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

PROBLEM SOLVING TECHNIQUES

PROBLEM SOLVING TECHNIQUES PROBLEM SOLVING TECHNIQUES UNIT I PROGRAMMING TECHNIQUES 1.1 Steps Involved in Computer Programming What is Program? A program is a set of instructions written by a programmer. The program contains detailed

More information

FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols.

FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols. FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols. Each symbol represents a specific activity. A typical problem involves

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Copyright 1992-2012 by Pearson Copyright 1992-2012 by Pearson Before writing a program to solve a problem, have

More information

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure Objectives Differentiate between a pretest loop and a posttest loop Include a pretest loop in pseudocode Include

More information