MAX POINTS plus more MAX points available 3000 total points
MAX POINTS plus more MAX points available. 3000 total points!! Serious answers only please!!
The State Machine, I need this done preferably in C++. There is also a part 2 of the state machine. If you want to earn more MAX points, you can use this problem\'s solution to solve part 2. Here is the link to that question as well.
http://www.chegg.com/homework-help/questions-and-answers/max-points-state-machine-part-2-2-need-done-preferably-c--part-2-2-want-earn-max-points-pa-q6283345
Thank you!
http://www.chegg.com/homework-help/questions-and-answers/max-points-state-machine-part-2-2-need-done-preferably-c--part-2-2-want-earn-max-points-pa-q6283345
Thank you!
Solution
#include<iostream>
using namespace std;
enum state{
Cat, Noise, Food
};
void stateMachine(char *input)
{
state CurrentState = Cat;
for(int i=0 ;i<(sizeof(input)/sizeof(char)); i++)
{
switch(input[i])
{
case \'1\':
if(CurrentState == Cat)
{
CurrentState = Food;
}
else if(CurrentState == Food)
{
CurrentState = Noise;
}
else
{
CurrentState = Cat;
}
break;
case \'2\':
if(CurrentState == Cat)
{
CurrentState = Noise;
}
else if(CurrentState == Noise)
{
CurrentState = Food;
}
else
{
CurrentState = Cat;
}
break;
case \'A\':
if(CurrentState == Cat)
cout<<\"Meow\"<<\"\ \";
else if(CurrentState == Food)
cout<<\"Lemons\"<<\"\ \";
else
cout<<\"Boing\"<<\"\ \";
break;
case \'B\':
if(CurrentState == Cat)
cout<<\"Ignore\"<<\"\ \";
else if(CurrentState == Food)
cout<<\"Cinnamon\"<<\"\ \";
else
cout<<\"Thud\"<<\"\ \";
break;
}
}
}
int main(int argc, char** argv) {
char input1[20] = \"BB2AAB1A\";
char input2[20] = \"11B2AB1B\";
char input3[20] = \"A1BB122A\";
char input4[20] = \"122A22A1A\";
char input5[20] = \"AA2AA2A22B\";
cout<<\"\ \ For input:\"<<input1<<\"\ \ \";
stateMachine(input1);
cout<<\"\ \ For input:\"<<input2<<\"\ \ \";
stateMachine(input2);
cout<<\"\ \ For input:\"<<input3<<\"\ \ \";
stateMachine(input3);
cout<<\"\ \ For input:\"<<input4<<\"\ \ \";
stateMachine(input4);
cout<<\"\ \ For input:\"<<input5<<\"\ \ \";
stateMachine(input5);
return 0;
}
------------------------------------
OUTPUT
For input:BB2AAB1A
Ignore
Ignore
Boing
Boing
Thud
Meow
For input:11B2AB1B
Thud
Lemons
Cinnamon
Thud
For input:A1BB122A
Meow
Cinnamon
Cinnamon
Meow
For input:122A22A1A
Boing
Meow
For input:AA2AA2A22B
Meow
Meow
Boing
Boing
Lemons