Flowcharts for C programmers Ian McCrum. flowcharts Diagrams are used in many places; they can be used as a design aid or a documentation aid. As a design.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Lecture 7: Software Design (Part II)
More on Algorithms and Problem Solving
User Interface Structure Design
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
How Are Algorithms Developed?
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 2 - Problem Solving
Contents Page Versions Paige Hetherington. Version 1 Here is my version 1 of my contents page. I like the plain layout of the page because I believe it.
ITEC113 Algorithms and Programming Techniques
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Chapter 2- Visual Basic Schneider
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
There is a certain way that an HTML file should be set up. The HTML section declares a beginning and an ending. Within the HTML, there should be a HEAD.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Introduction to C Programming
Chapter 3 Planning Your Solution
The Program Design Phases
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
CSC103: Introduction to Computer and 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.
Karnaugh Maps By: Shakil Nobes.
European Computer Driving Licence Syllabus version 5.0 Module 4 – Spreadsheets Chapter 22 – Functions Pass ECDL5 for Office 2007 Module 4 Spreadsheets.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
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.
1 Relational Expressions Relational expressions: –Expressions that compare operands –Sometimes called conditions –Evaluated to yield a result –Typically.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Chapter Two Creating a First Project in Visual Basic.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
ITEC113 Algorithms and Programming Techniques
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Programming, an introduction to Pascal
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.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
INF2050 Word Processing II. Assignment 1- Advertisement You are to create an advertisement for something that is for sale or rent (car, apartment, etc.)
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Unit 6 Repetition Processing Instructor: Brent Presley.
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
IPC144 Session 4 Flowcharts 1. Objectives: By the end of this session, the student will be able to: List the three elements of the Structure Theorem Identify.
Algorithms and Pseudocode
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
ICS124 Session 9 Flowcharting 1. By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify.
IPC144 Session 4 Flowcharts 1. Objectives: By the end of this session, the student will be able to: List the three elements of the Structure Theorem Identify.
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
OCR A Level F453: High level languages Programming techniques a. identify a variety of programming paradigms (low-level, object- oriented,
Introduction To Flowcharting
Print slides for students reference
Unit# 9: Computer Program Development
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
Introduction to Algorithms and Programming
Chapter 3 - Structured Program Development
How Are Algorithms Developed?
CHAPTER 17 The Report Writer Module
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
No Yes START Do you live in Scotland? Take umbrella See last Flowchart
Chapter 3: Selection Structures: Making Decisions
Microsoft Official Academic Course, Microsoft Word 2013
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Programming Logic and Design Eighth Edition
TERMS AND CONDITIONS   These PowerPoint slides are a tool for lecturers, and as such: YOU MAY add content to the slides, delete content from the slides,
Presentation transcript:

Flowcharts for C programmers Ian McCrum

flowcharts Diagrams are used in many places; they can be used as a design aid or a documentation aid. As a design aid they can allow visualisation of relationships, show how a system is partitioned and the structure of how things go together. We can do this before coding (or circuit design). There is also a much more formal method of using a variety of diagrams; management and systems analysis for example. A Unified Modelling Language (UML) can tease out the entities, attributes and relationships of all aspects of data for example. Here we will present the bare minimum of simple flowcharts, enough so that anyone can follow them without prior training.

Simple Flowcharts Time moves from top to bottom A single entry point at the top Try to avoid lines crossing (not always possible) One box one job Decision points should only have two exits Deliberately use English and not abbreviated C keywords, don’t use “IF”, use “IS”…? Instead Use common sense! The diagram should be clear

The bare minimum The start and end symbols The input (or output box) The statement box The process or sub-program box (C function) The decision box Continuation circles to link to the next page) 6 shapes are enough; some texts add dozens, symbols for storage of 4 or 5 types, printing etc. KISS! Keep it simple

Making flowcharts WORD is adequate ( use insert->shape) Microsoft Office has flowchart plugins Microsoft Viso is pretty good but expensive There are open source alternatives such as the libreoffice or OpenOffice products There is opensource flowcharting software as well – yED is easy to learn and quick to use – stick to its “flowchart” shapes, use F2… I like the way it self aligns the boxes. Don’t use colour. Simple black and white works… (IMHO)

START One start box, usually OVAL, you can use the words “START program1.c” if you wish. Best to use a white background and black lines. If using Word, insert a textbox with no lines and use the GROUP option using rightclick. Use the same symbol as a finish box Set X to zero, Initialise variables For simple statements I just use a text box in WORD but set its border to a 2 pixel black line. It is good to avoid using the equals sign ‘=‘ and to use English language to make it read better Read in the state of the pushbutton The input or output box. Use English here, if outputting say “Light the LED” for example Sub program sqr Calculate square root of x A function in C can be represented by a box with double lines at the sides. Make the contents English! Is the switch pressed ? A decision box: use English words and have a question mark at it the end, this should ask a question. It will have two labelled exits It helps if you use the centre justify option for the textbox Finally, on this page!, the continuation circle, label it A

A Continuation circle on the next page. There should be pairs of letters, one of each pair That’s all there is too it! There are weaknesses in this system but it does serve its purpose well. Major weakness is that there is no mechanism to give information about any variables or even functions you use. Adding “declarations” makes the charts unwieldly. I often add “margin notes” to my charts. In final year, those of you that take the OOP module will study Object Orientated Programming where you focus on the design of data, and attach relevant functions inside the data definitions. (cf Classes and Methods) C does have a “struct” system but it was given a major overhaul in C++, an OOPS language. Computing professionals spend a lot of time designing good data objects. C promotes focussing on the functions, you actually need to think about both. If interested read the seminal text Algorithms Plus Data Structures Equals Programs by Niklaus Wirth

Relationship of flowcharts to C If statementsif else statements YES NO

do{ this and this }while(this true); e.g do{ i++; }while(RAO==0); YES NO Do loops – test at the bottom!

While(test is true){ do this and this } e.G while(RA0==0){ RA1=1; } While loops – test at the top – body may never get executed YES NO

For loops – complicated in flowcharts; three things present in a for loop header The first item in the for statement is executed before entering the loop The next thing in the for statement is a conditional test, if true the for loop is exited, skipping over the body of the loop The last thing is only executed if the body of the loop gets entered, it gets executed at the bottom of the body and after it a jump up to the conditional test is done. Although semicolons separate each of the three sections, you can have multiple statements in each section, separated by a comma.

for(i=0,j=0 ; i<10 ; i++,j++) { x=i*j; }

Real examples void putch(char ch){ unsigned char status; do{ status=TXIF; }while(status==0); TXD=ch; } In practice most programmers would… while(!TXIF){;} TXD=ch; Or do{;/}while(!TXIF); TXD=ch;

Further example unsigned int getch(void){ unsigned char sta; do{ sta=RXIF; }while(sta==0); return RXREG; Or while(!RXIF){;} return (RXREG); // often C is not an exact // match for the flowchart

Tutorials Q1Write a flowchart to average 10 numbers brought in from the keyboard Q2Work through and array of 10 numbers and output the smallest value Q3Work through an array replacing each element with a weighted average of 25% of each immediate neighbour added to 50% of itself. Leave the first and last elements untouched Q4Flowchart the strstr function (look it up in the standard C library – c.f website file, page 96 or 120)