Home » Questions » Information [ Ask a new question ]

bool success = true; if(x == 0) { if(do_up) run_do_up(); else if(do_a) run_do_a(); else if(do_n) -

bool success = true; if(x == 0) { if(do_up) run_do_up(); else if(do_a) run_do_a(); else if(do_n) -

"if(x == 0)
{
if(do_up)
run_do_up();
else if(do_a)
run_do_a();
else if(do_n)
run_do_n();
else
success = false;
}
else if(x == 1)
{
if(do_n)
run_do_n();
else if(do_a)
run_do_a();
else
success = false;
}
else//x == 2
{
if(do_a)
run_do_a();
else if(do_n)
run_do_n();
else
success = false;
}
switch(x){
case 0:{
if(do_up)
run_do_up();
else if(do_a)
run_do_a();
else if(do_n)
run_do_n();
else
success = false;
break;
}
case 1:{
if(do_n)
run_do_n();
else if(do_a)
run_do_a();
else
success = false;
break;
}
default: {
if(do_a)
run_do_a();
else if(do_n)
run_do_n();
else
success = false;
}
}

if(x==0 && do_up)run_do_up(); //the only case this happens
else //case 1 does n first, other cases do a first
if(do_a && (x!=1 || (x==1 && !do_n)))run_do_a();
else
if(do_n && (x==1 || (x!=1 && !do_a)))run_do_n();
else success=false;

...
if(do_up) which_to_call=0;
else if(do_a) which_to_call=1;
else if(do_n) which_to_call=2;
else which_to_call=-1; //error flag

#include
#include

#ifdef TEST
bool do_n, do_a, do_up;
bool success;
bool T = true;

void run_do_up() { std::cout << ""did up\n""; }
void run_do_a() { std::cout << ""did a\n""; }
void run_do_n() { std::cout << ""did n\n""; }
#endif

struct conditional_action {
bool const &condition;
std::function action;

template
conditional_action(bool const &b, F &a) : condition(b), action(a) {}

conditional_action() : condition(T), action([&]{success = false; }) {}
};

conditional_action actions[4][3] {
{ { do_up, run_do_up }, { do_a, run_do_a }, { do_n, run_do_n } },
{ { do_n, run_do_n }, { do_a, run_do_a } },
{ { do_a, run_do_a }, { do_n, run_do_n } }
};

void exec(size_t x) {
for (auto const &a : actions[x])
if (a.condition) {
a.action();
return;
}
}

#ifdef TEST

int main() {
do_n = true;
exec(0);

do_a = true;
exec(2);
}
#endif

switch(x){
case 0: success = cond_do_up(do_up) || cond_do_a(do_a) || cond_do_n(do_n);"

Asked by: Guest | Views: 30
Total answers/comments: 2
Guest [Entry]

"Answer:

Answer:

Answer:"
Guest [Entry]

"Answer:

Hindi pong sinasabi mo

Explanation:

Pabrainliest"