12. The following diagram is an example of a deterministic finite state automaton, or DFA. This...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
12. The following diagram is an example of a deterministic finite state automaton, or DFA. This particular DFA describes an algorithm to determine if a sequence of characters is a properly formatted monetary amount with commas. For example, "$1,000" and "$25" and "$551,323,991,391" are properly formatted but "1,000" (no initial $) and “$1000" (missing comma) and "$5424,132" (missing comma) are not. IsMoney 1-9 0-9 0-9 State 0 State 1 State 2 State 3 0-9 0-9 0-9 State 4 State 5 State 6 State 7 The DFA works by starting in the oval labeled IsMoney. This is the initial state. If the first character of the string is $, then we advance to the second character and move to state 0. Otherwise we conclude the string is not a proper monetary amount. In state 0, if the second character is a digit between 1 and 9, then we ad- vance to the third character and move to state 1. Ötherwise we conclude the string is not a proper monetary amount. In state 1, if we have no more characters left in the string, then we conclude that the string is a monetary amount. This is called a final state and is indicated by a bold oval. If the third character is a digit between 0 and 9, then we advance to the fourth character and move to state 2. Otherwise if the third character is a comma then we advance to the fourth character and move to state 4. Otherwise we conclude the string is not a proper monetary amount. The rest of the DFA behaves in a similar manner. Write a program that uses recursion to implement the DFA. Your program should have a separate function for each state in the DFA. Each function should invoke the function corresponding to the next state indicated by the arrows in the dia- gram. There is mutual recursion because of the loop from state 7 to state 4. Test your solution with several strings and output whether each string is a properly formatted monetary amount. This solution calls a function for every character in the string. However, the solu- tion may be written in a tail-recursive manner, so it is possible that long strings will not exhaust the stack if your compiler is efficient. 12. The following diagram is an example of a deterministic finite state automaton, or DFA. This particular DFA describes an algorithm to determine if a sequence of characters is a properly formatted monetary amount with commas. For example, "$1,000" and "$25" and "$551,323,991,391" are properly formatted but "1,000" (no initial $) and “$1000" (missing comma) and "$5424,132" (missing comma) are not. IsMoney 1-9 0-9 0-9 State 0 State 1 State 2 State 3 0-9 0-9 0-9 State 4 State 5 State 6 State 7 The DFA works by starting in the oval labeled IsMoney. This is the initial state. If the first character of the string is $, then we advance to the second character and move to state 0. Otherwise we conclude the string is not a proper monetary amount. In state 0, if the second character is a digit between 1 and 9, then we ad- vance to the third character and move to state 1. Ötherwise we conclude the string is not a proper monetary amount. In state 1, if we have no more characters left in the string, then we conclude that the string is a monetary amount. This is called a final state and is indicated by a bold oval. If the third character is a digit between 0 and 9, then we advance to the fourth character and move to state 2. Otherwise if the third character is a comma then we advance to the fourth character and move to state 4. Otherwise we conclude the string is not a proper monetary amount. The rest of the DFA behaves in a similar manner. Write a program that uses recursion to implement the DFA. Your program should have a separate function for each state in the DFA. Each function should invoke the function corresponding to the next state indicated by the arrows in the dia- gram. There is mutual recursion because of the loop from state 7 to state 4. Test your solution with several strings and output whether each string is a properly formatted monetary amount. This solution calls a function for every character in the string. However, the solu- tion may be written in a tail-recursive manner, so it is possible that long strings will not exhaust the stack if your compiler is efficient.
Expert Answer:
Answer rating: 100% (QA)
1 invalid amount 2a valid amount inlude using stdut usin... View the full answer
Related Book For
Service Management Operations Strategy Information Technology
ISBN: 978-0077841201
8th edition
Authors: James Fitzsimmons, Mona Fitzsimmons, Sanjeev Bordoloi
Posted Date:
Students also viewed these physics questions
-
The CRAFT program is an example of a heuristic programming approach to problem solving. Why might CRAFT not find the optimal solution to a layout problem?
-
The Intel Core 2 Duo is an example of a processor, or CPU, as are the Celeron and PowerPC. List the two main tasks that the CPU performs in controlling the computer's workings and provide a short...
-
The debt and equity mix is an example of a financial leverage ratio and indicates the extent to which borrowed funds are used to finance assets. What are the main factors that go into determining the...
-
Dwights preferences over beer and whiskey satisfy more is better, but are concave (thus violating the usual assumption of convexity). a. On a diagram, sketch what such indifference curves would look...
-
A machine is used to fill container with a liquid product. Fill volume can be assumed to be normally distributed. A random sample of 10 containers is selected, and the net contents (oz.) are as...
-
Consider the one-dimensional, incompressible flow through the circular channel shown. The velocity at section (1) is given by \(U=U_{0}+U_{1} \sin \omega t\), where \(U_{0}=20 \mathrm{~m} /...
-
The following trial balance of Jeana Jones Tutoring Service, Inc., at August 31, 2011, does not balance: Investigation of the accounting records reveals that the bookkeeper: Requirement 1. Prepare...
-
A large number of firms are capable of producing chocolate- covered cockroaches. The linear, upward-sloping supply curve starts on the price axis at $ 6 per box. A few hardy consumers are willing to...
-
Jordon places the amount of $ 8 2 5 in a bank savings account today that offers an annual interest rate of 6 % compounded 5 2 times per year. How much will Jordon have in his account 9 years from...
-
Using information about the following company, calculate the share premium / (discount) a private equity house will be willing to pay for the Company. Assume pre deal net debt is refinanced. Assume...
-
Define each of the following concepts and provide an illustration where necessary. Nonsatiation Bads Partial Equilibrium Perfect Competition
-
After your discussions, Jane decides to obtain additional funding through the issuance of $10,000,000 in bonds with a annual coupon (stated or contractual) rate of 5%, interest paid every six months...
-
Describe Post Fiji Holistic Marketing in terms of (i) Internal Marketing (ii) Integrated Marketing (iii) Performance Marketing (iv) Relationship Marketing ? how can Singapore Airlines implement both...
-
Breakpoint Plc. is a business which is considering reviewing its payments of dividends for the forthcoming accounting periods. Assume that the current financial reporting period is December 2018 to...
-
4. Compute the additive inverse of each the following two's complement values. Express your answer in both base 2 and base 10: a. (1111)2 b. (11001)2 c. (01010)2 d. (01111):
-
Delaware Carnival Inc. will be offering a new ride in its amusement park. It has identified the following sales and costs from its introduction phase to the growth stages. Tickets to be sold Price...
-
Luxury furniture is promoting a no HST ( 1 3 % ) event for the fall sale. What is the actual selling price for the Sofa before tax shown on your receipt, if the ticket price of the sofa is $ 7 9 5 ....
-
Explain why it is not wise to accept a null hypothesis.
-
Green Valley Airport has been in operation for several years and is beginning to experience flight congestion. A study of airport operations revealed that planes arrive at an average rate of 12 per...
-
Go to www.pbinsight.com/welcome/mapinfo and find the definition of location intelligence. What use can be made of geographic information?
-
Last National Bank is concerned about the level of service at its single drive- in window. A study of customer arrivals during the windows busy period revealed that, on average, 20 customers per hour...
-
a. Who may bring suit under the 1934 Securities Exchange Act? b. Is the basis for action the same as in a 1933 Act suit? Explain.
-
What are the responsibilities of the plaintiff and the defendant in a 1933 Act suit?
-
Under what circumstances will a statement be presumed to be misleading?
Study smarter with the SolutionInn App