1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.

Slides:



Advertisements
Similar presentations
Container Classes A container class is a data type that is capable of holding a collection of items. In C++, container classes can be implemented as.
Advertisements

Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Zhigang Zhu, CSC212 Data Structures - Section FG Lecture 1: Introduction Instructor: Zhigang Zhu Department of Computer Science City College.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Unit 171 Algorithms and Problem Solving  Introduction  Algorithm Design  Algorithm Properties  Algorithm Control Flow  Examples  Comparing Algorithms.
 An important topic: preconditions and postconditions.  They are a method of specifying what a function accomplishes. Preconditions and Postconditions.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Computer Science 1620 Programming & Problem Solving.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
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.
Edgardo Molina, CSC212 Data Structures - Section AB Lecture 1: Introduction Instructor: Edgardo Molina Department of Computer Science City College.
Slides by Vinod Rathnam with material from Alex Mariakakis Kellen Donohue, David Mailhot, and Hal Perkins Midterm Review.
Classes Representing Non-Trivial Objects. Problem Write a program that reads a temperature (either Fahrenheit or Celsius), and displays that same temperature.
1 Chapter 9 Scope, Lifetime, and More on Functions.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Xiaoyan Li, CSC211 Data Structures Lecture 1: Introduction Instructor: Prof. Xiaoyan Li Department of Computer Science Mount Holyoke College.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Data Structures Chapter 1- Introduction Mohamed Mustaq.A.
CPS120: Introduction to Computer Science
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Systems Life Cycle. Know the elements of the system that are created Understand the need for thorough testing Be able to describe the different tests.
P An important topic: preconditions and postconditions. p They are a method of specifying what a function accomplishes. Preconditions and Postconditions.
 A Collection class is a data type that is capable of holding a group of items.  In Java, Collection classes can be implemented as a class, along with.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
P An important topic: preconditions and postconditions. p They are a method of specifying what a function accomplishes. Illinois State University Department.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Introduction to Java Java Translation Program Structure
Classes Representing Non-Trivial Objects. Problem Write a program that reads a temperature (either Fahrenheit or Celsius), and displays that same temperature.
 An important topic: preconditions and postconditions.  They are a method of specifying what a method accomplishes. Preconditions and Postconditions.
Software Development p Data structure p A collection of data organized so that the data can be accessed using a set of specific techniques p Object-oriented.
Introduction to Programming
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Container Classes  A container class is a data type that is capable of holding a collection of items.  In C++, container classes can be implemented as.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
21. THE STANDARD LIBRARY. General Rules The C standard library is divided into 15 parts (24 in C99), with each part described by a header. The names of.
George Wolberg, CSC212 Data Structures Lecture 1: Introduction Instructor: George Wolberg Department of Computer Science City College of New York.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Chapter 9: Value-Returning Functions
Chapter 1 The Phases of Software Development
Welcome to CSIS 10B Overview of Course Software Design (from Nyhoff)
Types CSCE 314 Spring 2016.
INTRODUCTION TO PROBLEM SOLVING
Chapter 1 The Phases of Software Development
Collection Classes A Collection class is a data type that is capable of holding a group of items. In Java, Collection classes can be implemented as a class,
Specifications What? Not how!.
Introduction to the C Language
Introduction to the C Language
Preconditions, Postconditions & Assertions
Introduction to Data Structures
Writing Methods AP Computer Science A.
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Data Structures and Algorithms for Information Processing
Preconditions and Postconditions
Single-Result Functions & Modularity
Preconditions and Postconditions
Presentation transcript:

1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples

2 Why Data Structures?  Main function of computers is to perform calculations—fast, efficiently.  Complex jobs require intensive calculations  How do you make computers work efficiently? Hardware Hardware Software Software  Software solution (independent of hardware) Algorithms Algorithms Algorithms depend on data structures Algorithms depend on data structures

3 What Is a Data Structure?  In a general sense, any data representation is a data structure. E.g., integer, string  Specifically, data structure is an organization for a collection of data items.  You choose appropriate data structure for efficient processing of data.

Phases of Software Development 1. Problem Analysis 2. Design of Solution Decomposing the problem Decomposing the problem Using existing sources Using existing sources 3. Implementation 4. Testing

An important topic:  preconditions and  postconditions. They are a method of specifying what a function accomplishes. Preconditions and Postconditions

Frequently, programmer must communicate precisely  what a function accomplishes,  without any indication of how the function does its work. Can you think of a situation where this would occur ?

Example  You are the head of a programming team and you want one of your programmers to write a function for part of a project. HERE ARE THE REQUIREMENTS FOR A FUNCTION THAT I WANT YOU TO WRITE. I DON'T CARE WHAT METHOD THE FUNCTION USES, AS LONG AS THESE REQUIREMENTS ARE MET.

What are Preconditions and Postconditions?  One way to specify such requirements is with a pair of statements about the function.  The precondition statement indicates what must be true before the function is called.  The postcondition statement indicates what will be true when the function finishes its work.

Example void write_sqrt(double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output....

Example void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output.... }  The precondition and postcondition appear as comments in your program.

Example void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output.... }

Example write_sqrt( -10 ); write_sqrt( 0 ); write_sqrt( 5.6 ); Which of these function calls meet the precondition ?

Example void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output.... }  The postcondition always indicates what work the function has accomplished. In this case, when the function returns the square root of x has been written.

Another Example bool is_vowel( char letter ) // Precondition: letter is an uppercase or // lowercase letter (in the range 'A'... 'Z' or 'a'... 'z'). // Postcondition: The value returned by the // function is true if Letter is a vowel; // otherwise the value returned by the function is // false....

Another Example is_vowel( 'A' ); is_vowel(' Z' ); is_vowel( '?' ); What values will be returned by these function calls ?

Another Example is_vowel( 'A' ); is_vowel(' Z' ); is_vowel( '?' ); What values will be returned by these function calls ? true false Nobody knows, because the precondition has been violated.

Always make sure the precondition is valid...  The programmer who calls the function is responsible for ensuring that the precondition is valid when the function is called.

... so the postcondition becomes true at the function’s end.  The programmer who writes the function counts on the precondition being valid, and ensures that the postcondition becomes true at the function’s end. THEN MY FUNCTION WILL EXECUTE, AND WHEN IT IS DONE, THE POSTCONDITION WILL BE TRUE. I GUARANTEE IT.

A Quiz Suppose that you call a function, and you neglect to make sure that the precondition is valid. Who is responsible if this inadvertently causes a 40- day flood or other disaster?  You  The programmer who wrote that torrential function  Noah

Your Turn 1. Suppose that you are to write a boolean function which checks if an integer is even or not. What are the preconditions and postconditions? 2. Suppose that you are to write a function which imports the balance and interest rate for a savings account and returns the amount of interest. What are the preconditions and postconditions?

Your Turn 1. Suppose you are to write a function which converts a Frerenheit temperature reading into Celsius. What are the preconditions and postconditions? 2. Suppose that you are to write a function which imports an int array and the number of array elements and prints the array contents. What are the preconditions and postconditions?

On the other hand, careful programmers also follow these rules:  When you write a function, you should make every effort to detect when a precondition has been violated.  If you detect that a precondition has been violated, then print an error message and halt the program.

On the other hand, careful programmers also follow these rules:  When you write a function, you should make every effort to detect when a precondition has been violated.  If you detect that a precondition has been violated, then print an error message and halt the program... ...rather than causing a disaster. a disaster.

Advantages of Using Preconditions and Postconditions  Succinctly describes the behavior of a function... ... without cluttering up your thinking with details of how the function works.  At a later point, you may reimplement the function in a new way... ... but programs (which only depend on the precondition/postcondition) will still work with no changes.

Precondition  The programmer who calls a function ensures that the precondition is valid.  The programmer who writes a function can bank on the precondition being true when the function begins execution. Postcondition  The programmer who writes a function ensures that the postcondition is true when the function finishes executing. Summary