1 / 11

8 Nov

8 Nov. Backtracking Structure clashes & program decomposition. Backtracking. In the forms of iteration and selection used in JSP, the condition test precedes execution of a part: we use read-ahead rule to handle serial input files if pattern is a single character or record

fruma
Download Presentation

8 Nov

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 8 Nov Backtracking Structure clashes & program decomposition

  2. Backtracking In the forms of iteration and selection used in JSP, the condition test precedes execution of a part: • we use read-ahead rule to handle serial input files if pattern is a single character or record • we use multiple read ahead rule if pattern is some fixed number, n, of characters (or records) • use backtracking if there is no fixed number, n

  3. Backtracking Problem: A cardfile of punched cards is sorted into ascending sequence of values of a key which appears in each card. • 1st card for each group with a common key value is a header card • Other records are detail cards. • Each detail card carries an integer amount Sample CardFile • It is required to produce a report showing the totals of amount for all keys

  4. Corresponding data structures

  5. Basic Program Structure

  6. Backtracking Modified problem: file has a record-type field: • 'header‘ - indicates group-id of the set of records that follow • 'detail' - indicates that record belongs to a group and contains data • other – if not of type ‘header’ or ‘detail’, record is an error • Program should detect the following errors: • header missing • detail cards have some other identifier (not ‘detail’) • Groups containing errors should be listed as an errorlist (not totaled)

  7. Structure of Error List & Program

  8. Backtracking Recognition problem: We cannot recognize a good group with any predetermined fixed read ahead. We tackle the recognition problem using ‘backtracking’ in 3 stages: Stage a: Assume (posit) that a group will be good (ignore the recognition difficulty) and design the full program accordingly. Stage a Stage b: Verify each data along the way – if any data contradicts the assumption of good data, issue a quit statement that branches to the second selection (badgroup) Replace ‘select’ and ‘or’ with ‘posit’ and ‘admit’; check for header and detail errors and issue quit statements Stage b Stage c: Modify the program text resulting from stage b. to ensure that side-effects are repealed where necessary • note state of file and buffer (immediately following posit) • restore state of file and buffer (immediately following admit) Comment: By breaking the problem into distinct stages, we isolate difficulties and can focus on correct design of each partial solution

  9. Backtracking control structure • Backtracking control structure • Javal implentation of backTracking

  10. Exception Handling in Java Backtracking • structure diagram and structure text • Java implementation Try (стараться)..catch (поймать)..finally(окончательно) in JSP • Java Exception Handling in JSP Example: TryException • NumberFormatException and ArrayOutOfBoundsException are unchecked (несдержанный) If a checked (задержанный) exception throws an exception, you must either catch it or else declare in the method header that the exception is thrown. HelloRead2

  11. Sample Cardfile H 0001 D 0001 012 D 0001 020 H 0002 D 0002 015 H 0003 D 0003 025 D 0003 -015

More Related