1 / 6

Example: Process Customer Record

Example: Process Customer Record.

red
Download Presentation

Example: Process Customer Record

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. Example: Process Customer Record • A program is required to read a customer’s name, a purchase amount, and a tax code. The tax code has been validated and will be one of those listed on page 43 of the textbook. The program must then compute the sales tax and the total amount due, and print the customer’s name, purchase amount, sales tax, and total amount due. Create a: • Defining diagram • Solution algorithm • Pseudocode algorithm using nested if statements

  2. Process Customer Record Pseudocode Customer Record Pseudocode READ Name, Amount, TaxCode IF TaxCode = 0 THEN SET SalesTax = 0 ELSE IF TaxCode = 1 THEN COMPUTE SalesTax = Amount * 0.03 ELSE IF TaxCode = 2 THEN COMPUTE SalesTax = Amount * 0.05 ELSE COMPUTE SalesTax = Amount * 0.07 ENDIF ENDIF ENDIF COMPUTE Total = Amount + SalesTax PRINT Name, Amount, SalesTax, Total END

  3. The Case Structure • The case control structure in pseudocode is another way of expressing a linear nested IF statement • It is used in pseudocode for two reasons: it can be directly translated into many high-level languages, and it makes the pseudocode easier to write and understand • Nested IFs often look cumbersome in pseudocode and depend on correct structure and indentation for readability

  4. General Form of CASE Statement CASE OF variable value1: Statement Block 1 value2: Statement Block 2 … valuen: Statement Block n Other: Statement Block Other ENDCASE

  5. Example: Process Customer Record (Redo of Previous Example) • A program is required to read a customer’s name, a purchase amount, and a tax code. The tax code has been validated and will be one of the items listed on page 49 of the textbook. The program must then compute the sales tax and the total amount due, and print the customer’s name, purchase amount, sales tax, and total amount due. Create a: • Defining diagram • Solution algorithm • Pseudocode algorithm using a case statement

  6. Process Customer Record Pseudocode Customer Record Pseudocode READ Name, Amount, TaxCode CASE OF TaxCode 0: SET SalesTax = 0 1: COMPUTE SalesTax = Amount * 0.03 2: COMPUTE SalesTax = Amount * 0.05 3: COMPUTE SalesTax = Amount * 0.07 ENDCASE COMPUTE Total = Amount + SalesTax PRINT Name, Amount, SalesTax, Total END

More Related