The Art of Design Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.

Slides:



Advertisements
Similar presentations
Give qualifications of instructors: DAP
Advertisements

Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
Chapter 2 - Problem Solving
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
Debugging: Catching Bugs ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
1 Array, Pointer and Reference ( III ) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures.
The Art of Design Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Control Statements (II) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Debugging: Catching Bugs ( II ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
1 Array, Pointer and Reference ( I ) Ying Wu Electrical Engineering and Computer Science Northwestern University EECS 230 Lectures.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Chapter 1 Program Design
Program Design Divide and Conquer –Divide the program into separate tasks Functional Decomposition Top-Down Design –Divide an overall problem into discrete.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Input, Output, and Processing
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Array, Pointer and Reference ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Review, Pseudocode, Flow Charting, and Storyboarding.
Function ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
COP1220/CGS2423 Introduction to C++/ C for Engineers Professor: Dr. Miguel Alonso Jr. Fall 2008.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Introduction to Computing Systems and Programming Programming.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Fundamental Programming Fundamental Programming Data Processing and Expressions.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Chapter 1.2 Introduction to C++ Programming
Algorithms and Problem Solving
Chapter 1.2 Introduction to C++ Programming
REPETITION CONTROL STRUCTURE
Chapter 1.2 Introduction to C++ Programming
Input and Output Upsorn Praphamontripong CS 1110
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 2 part #3 C++ Input / Output
Introduction to C++ Programming
Looping III (do … while statement)
Week 4 Lecture-2 Chapter 6 (Methods).
Chapter 2 part #3 C++ Input / Output
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

The Art of Design Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series

Outline Data flow Top-down vs. bottom-up Coarse to fine Two examples –MP#1 –MP#2

Data Flow Data –data representation  describe your inputs/outputs E.g. 1: a segment of command line? E.g. 2: the set of operators? Inputs and outputs of the building blocks –what are given? –what are expected? Data flow –blocks are connected through data flow

Flow chart Coding is a very very small part of programming –design  40% –coding  10% –debugging  50% When you start to work –always draw flow charts –organize your thoughts by flow charts –use testing cases to validate your flow charts

Top-down “Incremental” programming –Divide-and-conquer Task decomposition –No matter how small a task is, you can always divide it into a set of small sequential subtasks –You need to understand your tasks Focus –Make the structure clear and neat –Always use the basic controls Sequential Selection repetitive

Coarse to Fine Coarse  Fine Coarse design –determines the structure of the program –tells the basic idea –details are all ignored –concentrate on data flow –Organize it by subtasks Refinement –A rough “block” can always by replaced by a refined flowchart –It is much easier, because the tasks are simpler

Bottom-up “Brain-storming” programming Bottom design –creating a set of small “tools” –thinking based on “basic operations” Bottom  Up –putting tools together –this needs more experiences

“Tools” Extracting those basic operations –E.g. 1: bypass all “white spaces” –E.g. 2: check digits Forming functions –inputs –outputs –error checking

Before you start … Data representation? –How do you represent a “segment”? st/ed Your objectives? –Find a segment  determine st/ed

A Coarse Design Command line  buffer[500] Find the first element of a seg. Find the last element of the seg. Copy the segment to piece[100] piece  screen End of the string? Start the next segment Y N done

Code it int main() { cout << “Welcome bla bla bla” << endl; char buffer[500]; cout << "\nInput a command line: "; cin.getline(buffer, 500); char piece[500]; int st = 0, ed = 0; while( buffer[st]!=0 ){ st = _find_the_first_element( ); ed = _find_the_last_element( st ); _copy_segment(piece, st, ed); _display_segment(piece); st = ed + 1; } return 0; }

Checking after actions Command line  buffer[500] Find the first element of a seg. Successful? Find the last element of the seg. Successful? Copy the segment to piece[100] piece  screen End of the string? Start the next segment Error Y N N Y Y N

Code it int main() { cout << “Welcome bla bla bla” << endl; char buffer[500]; cout << "\nInput a command line: "; cin.getline(buffer, 500); char piece[500]; int st = 0, ed = 0, err_code = 1; while( buffer[st]!=0 ){ st = _find_the_first_element( ); if (buffer[st] == 0) err_code = 0; ed = _find_the_last_element( st ); // err_code can be set inside if (err_code == 0) break; else { _copy_segment(piece, st, ed); _display_segment(piece); st = ed + 1; } return err_code; }

Coarse-to-fine Find the first element of a seg. st ‘ ‘v ‘‘ a‘‘ r‘‘ _‘‘ 1‘‘ ‘ a‘‘ ‘ +‘‘ ‘3‘‘.‘‘ 1‘‘ 4‘‘ 0 buffer[0] buffer[st] == ‘ ‘ && buffer[st] != 0 st ++ Y N st

Coarse-to-fine Find the first element of a seg. sted Scan to find ed init ed = st Is buffer[st] a letter? Is buffer[st] a digit? Is buffer[st] an operator? Scan to find ed err_code = 0 YN Y N Y N Scan to find ed Is buffer[st] a ‘:’? Is buffer[st] a ‘[‘? Scan to find ed Y Y ed and err_code

Go even finer Scan to find ed buffer[st] = ‘[‘ ed init ed = st+1 Conditions for buffer[ed] ed ++ err_code = 0 break buffer[ed] != ‘]’

Put things together From coarse-to-fine –always draw flowcharts –keep all your flowchart Adding things little by little –don’t put together all at once Validate the new components –whenever you refine a block, always debug it and make sure the whole thing is correct –keep the structure of the program clear

Data Representation (MP#2) Attention, we only check 4 types of valid grammars. 1.assignment: "operand_1 = operand_2", e.g., a = 1 2.binary operation: "operand_1 operator operand_2", e.g., a + b 3.unary operation: "operand_1 operator", e.g., a++ 4.assignment and binary operation: "result = operand_1 operator operand_2", e.g., a = b + c According to that, we can define –Operations, (e.g., +, -, *, /, ++, --) –Operation types. (e.g., assignment, unary, binary) So, enum OP {ASN, ADD, MIN, MUL, DIV, INC, DEC}; enum OP_TYPE {asn, unary, binary};

A Coarse Design Print version/welcome Command line  buffer[500] Resolve a statement “understand” a statement Quit ? Y N done Successful? Y error

Data Flow Resolve a statement ( ) Understand a statement ( ) result_name # of pieces operator_name operator_type operand_1 operand_2 err_code CL_buffer[]

Tools Read_a_Piece( ) start_from buffer[ ] piece[ ] err_code Is_Char_a_Letter( ) c T/F Is_Char_a_Digit( ) c T/F Is_Char_a_Operator( ) c T/F Use MP#1

Coarse-to-fine Resolve_a_Statement –T1: scanning to determine the # of pieces –T2: finding operators –T3: grammar check –T4: finding two operands (based on T1/T2) Understand_a_Statement –Switch/case based on op type –Simply translate and print them out