Prelude to programming 6th edition by elizabeth drake

This preview shows page 103 - 111 out of 142 pages.

Prelude to Programming, 6th edition by Elizabeth Drake Using Modules and Submodules A module performs a single task. A module is self-contained and independent of other modules. A module is relatively short. Ideally, statements should not exceed one page. Benefits of Modular Programming o program is easier to read o easier to design, code, and test the program one module at a time o different program modules can be designed and/or coded by different programmers o a single module may be used in more than one place in the program o modules that perform common programming tasks can be used in more than one program
Hierarchy Charts o Like an organization chart o Shows position of modules in the program o Depicts what modules exist and how they are related o Large programs need a “map” for documentation Prelude to Programming, 6th edition by Elizabeth Drake
Coding, Documenting, Testing Coding Coding is done in a specific programming language. We will use pseudocode. This phase should only begin after a solid design exists!!! Documenting Code needs to contain documentation that describes to the reader what the code is doing Two types of comments are used within the code: Internal documentation is for the programmers to read External documentation is for the user Prelude to Programming, 6th edition by Elizabeth Drake
The Testing Phase Testing Create test data that will be used to check the program’s correctness. Use desk checking (or walking through a program by hand with a set of data that you know the answer to). Check that the program will catch errors by using test data designed to create errors. The more testing of various types of data you can use, the more likely you are to have a program that is free of errors. Prelude to Programming, 6th edition by Elizabeth Drake
Types of Errors: Syntax Errors Syntax errors : a violation of the programming language’s rules for creating valid statements May be caused by incorrect grammar or punctuation, or misspelling a keyword The program will not run at all with syntax errors Prelude to Programming, 6th edition by Elizabeth Drake
Types of Errors: Logic Errors Logic errors : the program runs, but does not produce the expected results May be caused by using an incorrect formula, or incorrect sequence of statements, etc. Can be detected during the desk checking phase of the programming cycle runtime errors Prelude to Programming, 6th edition by Elizabeth Drake
EXERCISE: In the following scripts what type of error will you get (if any)? 1. z= -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y) 2. x= -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y) 3. x= -pi:pi/10:pi; y = tan(sine(x)) - sine(tan(x)); plot(x,y) Prelude to Programming, 6th edition by Elizabeth Drake
EXERCISE SOLUTION: In the following scripts what type of error will you get (if any)?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture