Design a program and write program that will read a file of sales records and produce a sales report. Each record in the file contains a customer's number and name, a sales amount and a tax code. The tax code is to be applied to the sales amount to determine the sales tax due for that sale, as follows:

Tax code
Sales tax

0
Tax exempt

1
3%

2
5%

The report is to print a heading 'SALES REPORT', and detail lines listing the customer number, name, sales amount, sales tax and the total amount owing.

To design and write a program for generating a sales report from a file of sales records, you can follow these steps in any programming language:

1. Open the sales records file in read mode.
- Use the appropriate file opening function or method available in your chosen programming language.
- Make sure that the file exists and is accessible.

2. Create variables for the sales report totals.
- Initialize variables for the total sales amount, total sales tax, and the total amount owing.

3. Start reading the file line by line.
- Use a loop to iterate over each line in the file.

4. Parse the line and extract the relevant information.
- Split the line into individual fields (customer number, name, sales amount, and tax code) using a delimiter.
- Convert the sales amount and tax code to the appropriate data types for calculations.

5. Calculate the sales tax based on the tax code.
- Use conditional statements (if-else or switch-case) to determine the tax rate based on the tax code.
- Multiply the sales amount by the tax rate to get the sales tax for that sale.

6. Update the sales report totals.
- Add the sales amount to the total sales amount.
- Add the sales tax to the total sales tax.
- Calculate the total amount owing by adding the sales amount and sales tax.

7. Print the sales report to the console or a file.
- Print the report header with the title "SALES REPORT".
- For each sales record, print the customer number, name, sales amount, sales tax, and total amount owing.
- Optionally, format the amounts to display with the proper currency formatting.

8. Close the file and end the program.
- Close the sales records file to free up system resources.

Here is a sample code snippet in Python that demonstrates these steps:

```python
# Step 1: Open the sales records file
file_path = "sales_records.txt"
sales_file = open(file_path, "r")

# Step 2: Initialize variables for the sales report totals
total_sales_amount = 0
total_sales_tax = 0
total_amount_owing = 0

# Step 7: Print the sales report header
print("SALES REPORT")

# Step 3: Read the file line by line
for line in sales_file:
# Step 4: Parse the line and extract the relevant information
fields = line.split(",")
customer_number = fields[0]
customer_name = fields[1]
sales_amount = float(fields[2])
tax_code = int(fields[3])

# Step 5: Calculate the sales tax based on the tax code
if tax_code == 0:
sales_tax = 0 # Tax exempt
elif tax_code == 1:
sales_tax = sales_amount * 0.03 # 3% tax rate
elif tax_code == 2:
sales_tax = sales_amount * 0.05 # 5% tax rate
else:
sales_tax = 0 # Invalid tax code

# Step 6: Update the sales report totals
total_sales_amount += sales_amount
total_sales_tax += sales_tax
total_amount_owing += (sales_amount + sales_tax)

# Step 7: Print the sales record details
print("Customer Number:", customer_number)
print("Customer Name:", customer_name)
print("Sales Amount:", sales_amount)
print("Sales Tax:", sales_tax)
print("Total Amount Owing:", sales_amount + sales_tax)
print("----------------------------------------------------")

# Step 8: Close the file and end the program
sales_file.close()
```

Make sure to replace the file path `"sales_records.txt"` with the actual path to your sales records file. This code assumes that the sales records file is in a comma-separated format (CSV) with each field on a separate line.