CSCI 130 Pseudocode. Structure Theorem Any program can be created by using the following 3 control structures: –sequence –selection (IF-THEN-ELSE) –iteration.

Slides:



Advertisements
Similar presentations
4 Control Statements: Part 1.
Advertisements

Lecture 7: Software Design (Part II)
CS 240 Computer Programming 1
Chapter 11 Describing Process Specifications and Structured Decisions
Program Flowchart, Pseudocode & Algorithm development
Repetition There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Understanding the Three Basic Structures
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Using Flowcharts. Sample Flowchart (without text) 2.
CS0004: Introduction to Programming Repetition – Do Loops.
Programming Logic and Design Seventh Edition
ITEC113 Algorithms and Programming Techniques
Steps in Program Development
BACS 287 Programming Logic 3. BACS 287 Iteration Constructs Iteration constructs are used when you want to execute a segment of code several times. In.
Chapter 9 Describing Process Specifications and Structured Decisions
Program Design and Development
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
ALGORITHMS AND FLOWCHARTS
Adapted from slides by Marie desJardins
Sw development1 Software Development 1.Define the problem (Analysis) 2.Plan the solution 3.Code 4.Test and debug 5.Maintain and Document.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Chapter 9 Describing Process Specifications and Structured Decisions
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Chapter 2 - Algorithms and Design
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.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
PSEUDOCODE C Programming Technique – Firdaus-Harun.com.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Visual Basic Programming
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
ITEC113 Algorithms and Programming Techniques
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
Cosc175 - Define Problem/Design Solution/Pseudocode/Trace 1 DEFINE THE PROBLEM.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Introduction to Algorithms
PROGRAM CONTROL STRUCTURE
Algorithms and Flowcharts
( Iteration / Repetition / Looping )
Each instruction on a separate line
A Beginner’s Guide to Programming Logic, Introductory
ALGORITHMS AND FLOWCHARTS
TOPIC 4: REPETITION CONTROL STRUCTURE
MSIS 655 Advanced Business Applications Programming
Iteration: Beyond the Basic PERFORM
ALGORITHMS AND FLOWCHARTS
Let’s all Repeat Together
Chapter 11 Describing Process Specifications and Structured Decisions
CHAPTER 4 Iterative Structure.
Flowcharts and Pseudo Code
Introduction to Programming
Loops.
Presentation transcript:

CSCI 130 Pseudocode

Structure Theorem Any program can be created by using the following 3 control structures: –sequence –selection (IF-THEN-ELSE) –iteration (DOWHILE)

What is Pseudocode? English like statements depicting the flow of logic in a computer program –1. Simple english –2. One instruction per line –3. Keywords and Indentation - clarity –4. Top to bottom - one entry, one exit –5. Modules

Key Words Receive info: READ, GET Display info: DISPLAY, PUT, OUTPUT Decision: IF…THEN…ELSE Iteration: DOWHILE

Sequence Example Write pseudocode for a program which will input the radius of a circle, and which will output the area

Sequence Solution GET radius area = pi * radius * radius OUTPUT area

Selection 1 Example Write the pseudocode for a program that will accept a number that is less than 100, and will output the number only if it meets that condition

Selection 1 Solution GET x IF x < 100 OUTPUT x END IF

Selection 2 Example Write the pseudocode for a program that will determine the net income given the gross income of an employee. Determine the tax according to the following table: % % % Over %

Selection 2 Solution GET grossIncome; IF grossIncome < THEN netIncome = grossIncome *.1 ELSE IF grossIncome < THEN netIncome = grossIncome *.15 ELSE IF grossIncome < THEN netIncome = grossIncome *.2 ELSE netIncome = grossIncome *.3 END IF DISPLAY netIncome

Iteration Counted DOWHILE –number of iterations is known in advance DOWHILE –number of iterations is not known in advance sentinel end of file

Counted DOWHILE Example Write the pseudocode for a program which will read in 10 numbers and output the sum and average

Counted DOWHILE solution totalSum = 0 average = 0 DOWHILE counter = 1 to 10 read num totalSum = totalSum + num ENDO average = totalSum / 10 OUTPUT totalSum, average

DOWHILE example 1 Write the pseudocode for a program that will allow the user to input numbers. The signal (sentinel) from the user that they are done is that they will enter 999. The program will then output the sum of the numbers.

DOWHILE solution 1 total = 0 READ num DOWHILE (num not= 999) total = total + num READ num ENDO OUTPUT total

DOWHILE example 2 Write the pseudocode for a program that will read in records from a file. The program will extract the first name, last name, and salary from the file. It will then output the first name, last name, and salary of each employee. At the end of the program, the total payroll is output.

DOWHILE solution 2 totalPayroll = 0 DOWHILE records exist READ inputRecord EXTRACT firstName, lastName, salary WRITE firstName, lastName, salary totalPayroll = totalPayroll + salary ENDO WRITE totalPayroll

Control Structures can be nested Decision structures within decision structures DOWHILES within DOWHILES Decisions structures within DOWHILES DOWHILES within Decision structures etc.

Putting it all together Write the pseudocode for a program which will accept a number grade as input, and which will output a message stating whether the student passed or failed. In addition, after each grade is done, ask the user if they want to continue. If they answer ‘YES’, request another grade, otherwise end the program.

Solution answer = ‘YES’ DOWHILE answer = ‘YES’ GET grade IF grade >= 60 OUTPUT ‘Student Passed’ ELSE OUTPUT ‘Student Failed’ END IF GET answer ENDO

Modules Subtasks Increases Readability Easier Development/Maintenance Program may have Modules (functions, paragraphs) but pseudocode does not necessarily show this (complex functions will be broken out in pseudocode) Module call matches module name EXACTLY

Module Example Write the pseudocode for a program that will accept a number in inches, and which will output that number converted to feet and yards

Module Solution GET inches ConvertToFeet ConvertToYards Modules: ConvertToFeet feet = inches / 12 OUTPUT feet ConvertToYards yards = inches / 36 OUTPUT yards

Module Solution 2 GET inches feet = ConvertToFeet(inches) yards = ConvertToYards(inches) OUTPUT feet OUTPUT yards Modules: ConvertToFeet(inputInches) feet = inputInches / 12 ConvertToYards(inputInches) yards = inputInches / 36