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

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

Give qualifications of instructors: DAP
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Basics of Computer Programming Web Design Section 8-1.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
1 Classes with Pointer Data Members (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230.
Debugging: Catching Bugs ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
The Art of Design 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.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
1 String Library and Stream I/O Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
1 Midterm Review Ying Wu Electrical Engineering & Computer Science Northwestern University EECS230 Lectures Series.
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 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 1 Program Design
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
New Mexico Computer Science For All Introduction to Algorithms Maureen Psaila-Dombrowski.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
CS161 Topic #14 1 Today in CS161 Lecture #14 Practicing! Writing Programs to Practice Write a program that counts the number of vowels in a sentence, ended.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Simple Program Design Third Edition A Step-by-Step Approach
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
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.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
1 C++ Classes (I) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
The basics of the programming process The development of programming languages to improve software development Programming languages that the average user.
Chapter 8 First steps in modularisation. Objectives To introduce modularisation as a means of dividing a problem into subtasks To present hierarchy charts.
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.
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?
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Fundamental Programming Fundamental Programming More on Repetition.
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.
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.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Algorithms and Problem Solving
Topic Pre-processor cout To output a message.
Chapter 1.2 Introduction to C++ Programming
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Starting Out with Programming Logic & Design
Looping III (do … while statement)
Algorithms and Problem Solving
Starting Out with Programming Logic & Design
CS31 Discussion 1D Winter19: week 3
CS31 Discussion 1H Fall18: week 3
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Presentation transcript:

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

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

Data Flow Data –data representation  describe your inputs/outputs E.g. 1: an inputted sentence? E.g. 2: a segment of a command line? 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% The starting point of design –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

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 last 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