Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

overloded problem please fix for me : #include #include #include table.h #include using namespace std; / / Define the states and events ( already

overloded problem please fix for me :
#include
#include
#include "table.h"
#include
using namespace std;
// Define the states and events (already defined in your problem statement)
enum STATE { nke, ok1, ok2, ok3, fa1, fa2, fa3};
typedef enum EVENT { A, B, C, D, E, F } anEvent;
int mapping(const Pair& p)
{
return (p.first *6)+ p.second;
}
int main(){
std::ifstream combinationFile("correct_combination.txt");
if (!combinationFile.is_open())
{
std::cerr "Error: Could not open combination file." std::endl;
return 1;
}
std::string correctCombination;
std::getline(combinationFile, correctCombination);
combinationFile.close();
Table, STATE> transition_table(21, mapping);
Table, std::string > action_table(21, mapping);
transition_table.insert(makePair(makePair(nke, A), fa1));
action_table.insert(makePair(makePair(nke, A), "alarm"));
std::string enteredCombination;
std::cout "Enter the combination: ";
std::getline(std::cin, enteredCombination);
STATE currentState = nke;
bool unlocked = false;
for (char ch : enteredCombination){
anEvent event;
switch (ch)
{
case 'A': event = A; break;
case 'B': event = B; break;
case 'C': event = C; break;
case 'D': event = D; break;
case 'E': event = E; break;
case 'F': event = F; break;
default:
std::cerr "Invalid character entered." std::endl;
return 1;
}
Pair key = makePair(currentState, event);
int index = mapping(key);
currentState = transition_table.lookUp(key);
std::string action = action_table.lookUp(key);
if (action == "unlock")
{
unlocked = true;
break;
}
else if (action == "alarm")
{
std::cout "Alarm! Incorrect combination." std::endl;
break;
}
}
if (unlocked)
{
std::cout "Lock unlocked!" std::endl;
}
else if (!unlocked && enteredCombination.size()== correctCombination.size())
{
std::cout "Incorrect combination." std::endl;
}
return 0;
}
Problem show in the picture please solve for me
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions