BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.

Slides:



Advertisements
Similar presentations
Lecture 7: Software Design (Part II)
Advertisements

CS 240 Computer Programming 1
How Are Algorithms Developed?
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.
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Programming
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
Programming Logic and Design Seventh Edition
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
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.
Program Design and Development
Program Development and Programming Languages
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 3 Planning Your Solution
The Program Design Phases
A Tour of Visual Basic BACS 287. Early History of Basic Beginners All-Purpose Symbolic Instruction Code An “Interpreted” teaching language English-like.
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
DCT 1123 Problem Solving & Algorithms
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CSC141 Introduction to Computer Programming
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up 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.
Programming Concepts Chapter 3.
Software Life Cycle What Requirements Gathering, Problem definition
1 © 2002 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Lesson Year 1 CS112/0401/V1 LESSON 6 DESIGN TOOL PSEUDOCODE  Program Design Language (PDL)  Represent logic in English-like manner  Easier to.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Lecture 2 Numerical Methods for Engineering MECN 3500 Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus Dr.
ITEC113 Algorithms and Programming Techniques
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
BACS 287 Programming Logic 2. BACS 287 Sequence Construct The sequence construct is the default execution mode for the CPU. The instructions are executed.
5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
1 Program Planning and Design Important stages before actual program is written.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Algorithms and Pseudocode
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Introduction to Flowcharts
Program Program is a collection of instructions that will perform some task.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
 Problem Analysis  Coding  Debugging  Testing.
Algorithms and Flowcharts
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
Flow Charts Basic Flow Chart Symbols Few sample flowcharts Rules
Chapter 2- Visual Basic Schneider
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
PROGRAM CONTROL STRUCTURE
Introduction to Programming
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Introduction To Flowcharting
Programming Fundamentals
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
Flowcharts and Pseudo Code
Presentation transcript:

BACS 287 Programming Logic 1

BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented Unstructured is unacceptable. Structured programming is a good place to start learning. Object-oriented is the most modern and is used in more advanced courses.

BACS 287 Structured Programs Structured programs traditionally break the problem up into modules A module: – Performs a single, well-defined task – Is relatively small – Has a single entry and exit point – Does not interact with other modules Structured programs tend to not use the ‘GOTO’ statement

BACS 287 Structured Programs and VB Relatively easy to implement structured programs in Visual Basic. – Event-driven nature makes modules natural – All major structured programming constructs are supported Since the user interface is easy to define, we can concentrate on structuring the procedures.

BACS 287 Program Design Good programming design dictates that modules be written using the 3 basic programming constructs. Any procedural logic can be represented using strictly these 3 structures. Your Visual Basic code modules should be written using this style.

BACS 287 Structured Coding Basics Any program can be written using 3 basic constructs. – Sequence – Selection – Iteration Visual Basic has many ways to implement these constructs.

BACS 287 Basic Programming Constructs Sequence - Perform instructions one after the other Selection - Make a choice and follow a logic path – IF-THEN-ELSE – CASE Iteration - Repeat a code segment several times – DO WHILE – DO UNTIL

BACS 287 Procedural Logic Design Tools Many tools exist to plan procedural logic. Two common ones will be used in this class Pseudocode – English-like – Free form – Easy to convert to VB code Flowchart – Graphic representation – Better for high-level overview than pseudocode

BACS 287 Pseudocode The “Rules” – One statement per line – Indent nested structures – End all structures with appropriate terminator ‘IF’ statements with ‘ENDIF’ ‘DO’ statements with ‘ENDDO’ ‘CASE’ statements end with ENDCASE – Use structured programming constructs

Pseudocode Example Start Get temperature If temperature < 40 then Wear a coat Else Don’t wear a coat Endif Stop BACS 287

Flowchart Symbols

BACS 287 Flowcharts The “Rules” – Use the basic flowchart symbols (boxes) – All boxes are connected by flow lines – Flow lines do not cross other flow lines – Flow lines are vertical and horizontal, not curved or diagonal – General flow is from top to bottom, left to right – Start with a single ‘Start’ box and end with a single ‘Stop’ box – Draw the entire chart at a consistent logical level

BACS 287 Flowchart Example

BACS 287 Sequence Construct - Example The Problem: Initialize a variable called ‘X’ to a value of 1. Add 1 to this value. Display the result on the screen.

BACS 287 Sequence Construct Start X = 1 X = X + 1 Write X to screen Stop

BACS 287 Selection Construct – Example 1 The Problem: Read the value of a variable ‘X’. When the value of ‘X’ is greater than 4, display “error”. Otherwise, display “ok”.

BACS 287 Selection (If-Then-Else) Start Read X IF X > 4.0 then Print “Error” Else Print “OK” EndIF Stop

BACS 287 Selection Construct – Example 2 The Problem: Read the value of a variable ‘X’. When the value of ‘X’ is “red”, print “value is red”. When the value of ‘X’ is “blue”, print “value is blue”. When it is neither, print “error”.

BACS 287 Selection (Case) Start Read X Select Case X Case “red” Print “Value is red” Case “blue” Print “Value is blue” Case Else Print “Error” EndCase Stop

BACS 287 Iteration Construct – Example The Problem: Calculate the sum of the first 10 digits (that is, 1 through 10). When you finish, print this value. Perform these calculations by performing an IF-THEN test at the top of the loop. Next, repeat where the IF-THEN is at the bottom of the loop.

BACS 287 Iteration (Do While) Start X = 1 Sum = 0 Do While X < 11 Sum = Sum + X X = X + 1 EndDo Print Sum Stop

BACS 287 Iteration (Do Until) Start X = 1 Sum = 0 Do Until X > 10 Sum = Sum + X X = X + 1 EndDo Print Sum Stop

BACS 287 Putting it All Together Note that the 3 programming constructs are combined to solve problems. Also note that they can be “nested” within one another. The key is to think logically and plan out a strategy for solution that takes into account all possibilities.

BACS 287 You Try It – Example 1 The Problem: Read a students GPA. If the value is equal to 4.0, print a “President’s letter.” If the GPA is between 3.5 and 3.99, print a “Dean’s letter.” If it is between 3.25 and 3.499, print a “Director’s letter.” If it is between 3.0 and 3.249, print a “Honor role letter.” If it is below 3.0, don’t print anything.

BACS 287 You Try It – Example 1 Solution Start Read GPA If GPA >= 4.0 then Print President’s letter ElseIf GPA >= 3.5 then Print Dean’s letter ElseIf GPA >= 3.25 then Print Director’s letter ElseIf GPA >= 3.0 then Print Honor Roll letter EndIf Stop

BACS 287 You Try It – Example 2 The Problem: Read a number. Write code to print “This is a loop” the number of times indicated by the number. The test should be at the top of the loop. Next, do the same by putting the test at the bottom of the loop.

BACS 287 You Try It – Example 2 Solution Start Get Loop Count X = 1 Do While X <= Loop Count Print “This is a loop” X = X + 1 EndDo Stop