1 answer

Can someone help with this C++ code. I am trying to compile and I keep running...

Question:

Can someone help with this C++ code. I am trying to compile and I keep running into these 4 errors.   #include <iostream> #include <cassert> #include <string> using namespace std; typedef int     fsm_state; typedef char    fsm_input; bool is_final_state(fsm_state state) {   return (state == 3) ? true : false; } fsm_state get_start_state(void) {   return 0; } fsm_state move(fsm_state state, fsm_input input) {   // our alphabet includes only 'a' and 'b'   if (input != 'a' && input != 'b')     assert(0);   switch (state)   {     case 0:       if (input == 'a')       {         return 1;       }       else if (input == 'b')       {         return 0;       }       break;     case 1:       if (input == 'a')       {         return 1;       }       else if (input == 'b')       {         return 2;       }       break;     case 2:       if (input == 'a')       {         return 1;       }       else if (input == 'b')       {         return 3;       }       break;     case 3:       if (input == 'a')       {         return 1;       }       else if (input == 'b')       {         return 0;       }       break;       default:         assert(0);   } } bool recognize(string str) {   if (str == "")     return false;   fsm_state state = get_start_state();   string::const_iterator i = str.begin();   fsm_input input = *i;   while (i != str.end())   {     state = move(state, *i);     ++i;   }   if (is_final_state(state))     return true;   else     return false; } // simple driver for testing int main(int argc, char** argv) {   recognize(argv[1]) ? cout < 1 : cout < 0;   return 0; } 

Answers

Hi, I have fixed all compile time errors.

Please test with your test cases and let me know in case of any issue.

#include <iostream>
#include <cassert>
#include <string>
using namespace std;
typedef int fsm_state;
typedef char fsm_input;
bool is_final_state(fsm_state state)
{
return (state == 3) ? true : false;
}
fsm_state get_start_state(void)
{
return 0;
}
fsm_state move(fsm_state state, fsm_input input)
{
// our alphabet includes only 'a' and 'b'
if (input != 'a' && input != 'b')
assert(0);
switch (state)
{
case 0:
if (input == 'a')
{
return 1;
}
else if (input == 'b')
{
return 0;
}
break;
case 1:
if (input == 'a')
{
return 1;
}
else if (input == 'b')
{
return 2;
}
break;
case 2:
if (input == 'a')
{
return 1;
}
else if (input == 'b')
{
return 3;
}
break;
case 3:
if (input == 'a')
{
return 1;
}
else if (input == 'b')
{
return 0;
}
break;
default:
assert(0);
}
return -1; // Error code
}
bool recognize(string str)
{
if (str == "")
return false;
fsm_state state = get_start_state();
string::const_iterator i = str.begin();
fsm_input input = *i;
while (i != str.end())
{
state = move(state, *i);
++i;
}
if (is_final_state(state))
return true;
else
return false;
}
// simple driver for testing
int main(int argc, char** argv)
{
recognize(argv[1]) ? cout << "1" : cout << "0";
cout<<endl;
return 0;
}

.

Similar Solved Questions

1 answer
Pls can you solve this exercise 29, and 30 active 4 E1-29 Using the accounting equation...
pls can you solve this exercise 29, and 30 active 4 E1-29 Using the accounting equation to analyze business transactions Ashley Stamper opened a medical practice. During July, the first month of operation, the business, titled Ashley Stamper, MD, experienced the followin cvents: Jul 6 9 12 15 20 ...
1 answer
X ACCT 2302 quiz 3-1 When Homework #3 (Due Wednesday, January 30th by 11:59pm) POINTS n...
x ACCT 2302 quiz 3-1 When Homework #3 (Due Wednesday, January 30th by 11:59pm) POINTS n Mayer Company, the Cutting Department had beginning work in process of 6.000 unts, transterred out 24,000 unts, and had an encing work in process of 3,000 unts. How marry units were started by Moyer during the mo...
1 answer
Case: Oubre v
Case: Oubre v. Entergy Operations, Inc.Question :Why do you think Oubre did not make restitution? What is Oubre is trying to achieve in trying to set aside her agreement to the severance package? Do you agree with the decision of the U.S. Supreme Court?...
1 answer
Jacob undergoes an excision of a carotid body tumor. How is the procedure coded? Are any...
Jacob undergoes an excision of a carotid body tumor. How is the procedure coded? Are any modifiers attached?...
1 answer
And X...,X, U[0,1], Given X...., X, are iid Y, is defined as Yn = min(x1,x2,...,x,). a.s. Prove that in Y, probabilit →...
and X...,X, U[0,1], Given X...., X, are iid Y, is defined as Yn = min(x1,x2,...,x,). a.s. Prove that in Y, probabilit → = 0 and Y. →=0...
1 answer
Problem 4 (25 points) A 40 degree inclined water manometer is to measure a gauge pressure...
Problem 4 (25 points) A 40 degree inclined water manometer is to measure a gauge pressure of 5000 Pa in a system involving air. The differential length on the manometer is measured with accuracy of 0.5 mm and resolution of 1 mm. Density of air compared to density of water is negligible. Specific wei...
3 answers
Hi, I have to take chemistry placement test for college this week
Hi, I have to take chemistry placement test for college this week. Does anyone here have advice for studying to prepare for the test? I took chemistry in high school 2 years ago so I don't remember anything....
1 answer
2 Ω 6A P2 10 Ω 5 Ω 4 Ω ΜΑ- 3Α
2 Ω 6A P2 10 Ω 5 Ω 4 Ω ΜΑ- 3Α...
1 answer
How do you solve #x^ { 5} + 3x ^ { 4} + 16x ^ { 3} + 48x ^ { 2} + 63x + 189= 0#?
How do you solve #x^ { 5} + 3x ^ { 4} + 16x ^ { 3} + 48x ^ { 2} + 63x + 189= 0#?...
1 answer
Discuss the reasons why gerontological nursing is a high-risk specialty for legal liability
Discuss the reasons why gerontological nursing is a high-risk specialty for legal liability...
1 answer
A small factory produces a small toy with a fixed cost of S10,000/month. If the factory...
A small factory produces a small toy with a fixed cost of S10,000/month. If the factory manager wants to have a profit of $2 per unit, the revenue is $15/unit and variable cost is $5/unit what is quantity to achieve this profit? 6668...
1 answer
A(n) ________ is a paid individual, corporation, or a commercial bank trust department that acts as...
A(n) ________ is a paid individual, corporation, or a commercial bank trust department that acts as a third party to a bond indenture. Select one: a. bond issuer b. bond rating agency c. investment banker d. trustee...
1 answer
The answers are not A. 3.35 B. 45,500 or A. 3.19 B. 2.83 Current Attempt in...
The answers are not A. 3.35 B. 45,500 or A. 3.19 B. 2.83 Current Attempt in Progress Your answer is incorrect. On January 1, 2020, Novak Company issued 10-year, $2,140,000 face value, 6% bonds, at par. Each $1,000 bond is convertible into 14 shares of Novak common stock. Novak's net income in 20...
1 answer
Estinr Plan AD'ake) 1 eup of Com Flakes cereal !cup of 1% fat nilk Eating Plan...
Estinr Plan AD'ake) 1 eup of Com Flakes cereal !cup of 1% fat nilk Eating Plan B Day's Intake)Eating Plan D Dry'Itake 1 eup of Corn Flakes cereal of cotfee 2 slices of whole-wheat bread 20 ounces coffee 2 ounces thinly sliced baked 2 ounces soy milk 1 honey nut granola bar 6 ounces choco...
1 answer
Coto do Sold Budget W Factory est products, and 2. W onded 27.200 the inventories on...
Coto do Sold Budget W Factory est products, and 2. W onded 27.200 the inventories on June 1eremated to be for purchase in un for Chema Compe t produce da t ed 10.00 during $12.200 per barrel recorded in the chemical proces s for WE use the pre m tente per budget for W process The desired Inventories...
1 answer
The gas mileages (in miles per gallon) of 28 randomly selected sports cars are listed in...
The gas mileages (in miles per gallon) of 28 randomly selected sports cars are listed in the accompanying table. Assume the mileages are not normally distributed. Use the standard normal distribution or the t-distribution to construct a 99% confidence interval for the population mean. Justify your d...
1 answer
Solve the following partial differential equation by the variable separation method: Ә?u Әr2 ди ду +u(x,...
Solve the following partial differential equation by the variable separation method: Ә?u Әr2 ди ду +u(x, y)...