Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.

Similar presentations


Presentation on theme: "Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved."— Presentation transcript:

1 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 1 Chapter 2 Developing a Program

2 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 2 2.1The Program Development Cycle Problem solving principles –Completely understand the problem –Devise a plan to solve it –Carry out the plan –Review the results Writing a program –1) Analyze the problem –2) Design the program –3) Code the program –4) Test the program

3 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 3 1) Analyze the Problem Example –The problem: A local department store needs to develop a program which, when given an items original price and the percentage it has been discounted will compute the total price( including sales tax) of items that have been placed on sale. What are the inputs? (given data) What are the outputs? (required data) How will we calculate the required outputs from the given inputs?

4 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 4 2.2 Program Design Modular programming –Determine the major tasks that the program must accomplish. Each of these tasks will be a module. –Some modules will be complex themselves, and they will be broken into submodules, and those submodules may also be broken into even smaller modules. –This is called top-down design

5 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 5 The first illustration of top down design describes the 3 fundamental tasks that are required in the Brewster example: –Input –Perform Calculations (Process) –Output Input Perform Calculations Output Input variables:AmountSaved=OriginalPrice*Discount rate/100 Display ItemNameSalePrice=OrigialPrice-AmountSaved TotalPrice DiscountRate Tax=SalePrice*.065 OriginalPriceTotalPrice=SalePrice+Tax

6 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 6 A Code Module Performs a single task Is self-contained and independent of other modules Relatively short – less than 1 page Calling module Called module Transfer of control Main is the controller of all sub-modules

7 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 7 Hierarchy Chart Like an organization chart – shows position of modules in the program. Depicts what modules exist and how they are related. Large programs need a “map” for documentation. One page of code per module – keeps the program manageable. We will have very small modules while getting comfortable using these tools.

8 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 8 Hierarch Chart for Example Main Module Input Data Perform Calculations Output Results

9 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 9 2.3Coding, Documenting, and Testing Coding –done in a specific programming language. We will use pseudocode. –should only begin after a solid design exists. Documenting –Code needs to contain documentation that describes to the reader what the code is doing – called comments –This kind of documentation is for the programmers to read –There is also User Documentation that is external to the code and may take the form of a User’s Guide

10 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 10 Testing –Create test data that will be used to check the program’s correctness. For example, if the following test data is used, does the program generate the expected results? (Determine the expected results before the code is written.) Item Name =Beach Ball Price =60 Discount Percentage=20 If a Desk check of the code gets the same answer as the expected results then the code has been tested, and is likely correct.

11 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 11 Types of Errors Syntax – wrong grammar, i.e., breaking the rules of how to write the language –Forgetting punctuation, misspelling keyword –The program will not run at all with syntax errors Logic - the program runs, but does not produce the expected results. –Using an incorrect formula, incorrect sequence of statements, etc. –These errors are detected during the desk-check, of the program; an important part of the cycle.

12 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 12 2.4 Structured Programming A method for designing and coding programs in a systematic, organized manner. It combines the principles of top-down design, modularity and the use of the three accepted control structures of sequence, repetition and selection. Sequence, repetition and selection can be expressed in pseudocode, or with Flowcharts

13 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 13 Flowcharts Another tool for programmers to design programs –Describe the flow of a program module’s execution with diagrams. –(Completely different from hierarchy charts). –Connected symbols are used to describe sequence, repetition, and selection. –Some prefer to use flow charting to learn how to express algorithms, and others prefer to use pseudocode.

14 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 14 Control Structures SequenceSequence –in sequential order. –The simplest of control structures – start at the beginning and continue in sequential order. RepetitionRepetition – repeat statements more than once –Called a loop, it needs a stop condition, I.e, the program will continue to loop until some condition is met. SelectionSelection – selectively execute statements –Called a branch, it requires a condition to determine when to execute statements.

15 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 15 2.5 An Introduction to GUIs and OOP GUI – Graphical User Interface –Users interact with software using a mouse, to select from menu choices, clicking on buttons, etc. –Development of GUI software uses tools specifically designed for that task. –Event-driven programming is the development of software where the flow of control is based on the user’s clicking on menus and buttons, etc. These user actions are called events. Event-driven programming still uses the basic principles of structured programming – program modules, control structures, good programming style, and program testing.

16 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 16 Object-oriented Programming Focus is on the objects that will be used to solve the problems. Object – a structure that contains attributes and methods (data and process) Object-oriented Design starts with identifying the required objects. Java, C++, SmallTalk are languages based on Object-oriented programming

17 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 17 Importance of Structured Programming Structured, Event-driven, and Object-oriented programming techniques are not separate form each other. All require the basic principles of structured programming – program modules, control structures, good programming style, and program testing.

18 Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved. 18 Pseudocode Language (Ch 2) In this chapter we added a way to create and call modules in our programs. InputAssignment Input Variable Set Variable = 10 Set Variable = AnotherVariable OutputArithmetic Operations Write “literal text”( ) ^ * / + - Write Variable Write “literal text”, Variable Create a module Call a sub-module ModuleName Call ModuleName …. End


Download ppt "Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved."

Similar presentations


Ads by Google