Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use only MATLAB to solve this problem Write a MATLAB function called krustyKrab(

ID: 672580 • Letter: U

Question

use only MATLAB to solve this problem

Write a MATLAB function called krustyKrab() that takes in the name of a '.txt' file which has a list of what a particular customer ordered. The first line of the text file will contain the customer’s name. Each additional line of the text file will have the item the customer requested and its standard price from the menu. The krustyKrab() function needs to output the total of the order, including a 15% sales tax (because Krabs likes his money!) as well as a new '.txt' file that has the full receipt from the order.

The receipt (your output text file) will need to include the exact same lines that were printed on the original '.txt' file, plus the following three lines:
1. The subtotal of the order (the sum of all the prices of each item ordered)

2. The total of the order rounded to two decimals (the subtotal with a 15% sales tax)

3. The Krusty Krab slogan: 'The Krusty Krab, Come spend your money here!'


The name of the output '.txt' file should be the name of the input '.txt' file given with ‘_receipt’ appended to it.

For example, given the following input text file named 'Order1.txt':

  
1 Name: Patrick Star

2 Krabby Patty $2.00

3 Coral Bits $1.95

4 Small Sea Foam Soda $1.00


This function should output the total cost from the receipt, including 15% sales tax, which is rounded to two decimals, as a double:

total => 5.69

The output file will be named 'Order1_receipt.txt' and have the three new lines in addition to the lines from the original text file.

1 Name: Patrick Star

2 Krabby Patty $2.00

3 Coral Bits $1.95

4 Small Sea Foam Soda $1.00

5 Subtotal=$4.95

6 Total=$5.69

7 The Krusty Krab, Come spend your money here!

Notes:

? The lines indicating which items were ordered should appear EXACTLY the same in the receipt '.txt' file you output as the input file, including the customer’s name being first.

? The subtotal and total lines should be formatted EXACTLY as indicated, i.e. the word, an equal sign, a dollar sign, and then the value.

? There should NOT be an extraneous empty line at the end of your output '.txt' file.

Hints:

? The prices of each item in the given '.txt' file will always appear immediately after the ‘$’ character present in that line.

? When using fprintf(), in order to format your decimals correctly for the subtotal and total values, you must use %0.2f as your variable in the string. Therefore, the line fprintf(fh2, 'Subtotal=%0.2f', 5); prints the following line to the specified file >> Subtotal=$5.00, where, the ‘f’ stands for floating point number, and will avoid any weird display of your rounded number. The ‘0.2’ indicates that it will only display two places after the decimal point.

Explanation / Answer

// function krustyKrab

ipfp = open('CustomerOrder.txt','r');

// open the customer order file to read the customer orders

opfp = open('Order1_receipt.txt','w');

for i from 1 to 10 do

value := order * price;

fprintf(opfp, 'SubTotal = %0.2f', value);