MAX POINTS!! 3000 total points!!! The State Machine, part 2 of 2. I need this do
ID: 3569072 • Letter: M
Question
MAX POINTS!! 3000 total points!!! The State Machine, part 2 of 2. I need this done preferably in C++. This is part 2 of 2. If you want to earn more MAX points, you can do part 1 as well and use that solution to solve this question for part 2.
SERIOUS ANSWERS only please!!
Here is the link - http://www.chegg.com/homework-help/questions-and-answers/state-machine-need-done-preferably-c--also-part-2-state-machine-want-earn-max-points-use-s-q6283289
More MAX POINTS = This is part 2 of 2 of the State Machine. You can use part 1 to help solve this problem as well and earn MAX points for problem 1 too. Here is the link.
http://www.chegg.com/homework-help/questions-and-answers/state-machine-need-done-preferably-c--also-part-2-state-machine-want-earn-max-points-use-s-q6283289
Thank you!!
Explanation / Answer
#include<iostream>
using namespace std;
enum state{
A, B, C, D, E
};
int stateMachine(char *input)
{
int total = 0;
state CurrentState = A;
for(int i=0 ;i<(sizeof(input)/sizeof(char)); i++)
{
switch(input[i])
{
case 'W':
if(CurrentState == A)
CurrentState = B;
if(CurrentState == B)
CurrentState = A;
total += 28;
break;
case 'X':
if(CurrentState == A)
CurrentState = C;
if(CurrentState == C)
CurrentState = A;
total += 5;
break;
case 'Y':
if(CurrentState == A)
CurrentState = D;
if(CurrentState == D)
CurrentState = A;
total += 16;
break;
case 'Z':
if(CurrentState == A)
CurrentState = E;
if(CurrentState == E)
CurrentState = A;
total += 22;
break;
case 'S':
if(CurrentState == B)
CurrentState = D;
if(CurrentState == D)
CurrentState = B;
total += 7;
break;
case 'M':
if(CurrentState == B)
CurrentState = E;
if(CurrentState == E)
CurrentState = B;
total += 31;
break;
case 'J':
if(CurrentState == B)
CurrentState = C;
if(CurrentState == C)
CurrentState = B;
total += 10;
break;
case 'T':
if(CurrentState == C)
CurrentState = E;
if(CurrentState == E)
CurrentState = C;
total += 19;
break;
case 'K':
if(CurrentState == C)
CurrentState = D;
if(CurrentState == D)
CurrentState = C;
total += 22;
break;
case 'L':
if(CurrentState == E)
CurrentState = D;
if(CurrentState == D)
CurrentState = E;
total += 12;
break;
}
}
return total;
}
int main() {
char inputs[6][20] = {"WMTK", "WJTL","XJML", "XTMS","ZMJK","ZTJS"};
int min=9999;
int minIndex = 0;
int max=0;
int maxIndex=0;
for(int i=0; i<6; i++)
{
cout<<"For input:"<<inputs[i]<<" ";
int weight = stateMachine(inputs[i]);
cout<<"Weight: "<<weight;
cout<<" ";
if(min>weight)
{
min = weight;
minIndex = i;
}
if(max<weight)
{
max = weight;
maxIndex = i;
}
}
cout<<"Max weight is: "<<max<<" for the input: "<<inputs[maxIndex]<<" ";
cout<<"Min weight is: "<<min<<" for the input: "<<inputs[minIndex]<<" ";
return 0;
}
------------------------------------------------
OUTPUT
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.