Advertisement
Nkzlxs

matching_cases Function

Apr 7th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.60 KB | None | 0 0
  1. bool matching_Cases(string user_inputValue[])
  2. {
  3.     //An array indicating which attribute is open
  4.     bool attributesGate[numbersOf_Attributes];
  5.  
  6.     //Total number of attribute used
  7.     int gatesOpened = 0;
  8.  
  9.     //Local array for storing input
  10.     string inputValue_string[numbersOf_Attributes];
  11.     /*
  12.     "Employee Name", "Country", "Designation", "Gender", "Level of Education",
  13.     "Employee ID", "Date Of Birth", "Height", "Weight", "Years of working",
  14.     "Basic Salary", "Allowances"
  15.     */
  16.  
  17.     //Detecting which attribute is open
  18.     for (int h = 0; h < numbersOf_Attributes; h++)
  19.     {
  20.         if (user_inputValue[h].length() == 0)
  21.         {
  22.             attributesGate[h] = false;
  23.         }
  24.         else
  25.         {
  26.             attributesGate[h] = true;
  27.         }
  28.     }
  29.  
  30.     //Counting the total attribute opened
  31.     //And put the user input array into a local array variable
  32.     for (int g = 0; g < numbersOf_Attributes; g++)
  33.     {
  34.         if (attributesGate[g] == true)
  35.         {
  36.             gatesOpened++;
  37.             inputValue_string[g] = user_inputValue[g];
  38.         }
  39.     }
  40.     cout << "Gates Opened: " << gatesOpened << endl;
  41.  
  42.     /////////////////////////////////////////////////
  43.     if (gatesOpened == 0)
  44.     {
  45.         return false;
  46.     }
  47.     /////////////////////////////////////////////////
  48.  
  49.     for (int a = 0; a < numbersOf_Attributes; a++)
  50.     {
  51.         for (int b = 0; b < THE_ARRAY_SIZE; b++)
  52.         {
  53.             valid_ResultsNo[a][b] = -1;
  54.         }
  55.     }
  56.  
  57.     for (int p = 0; p < numbersOf_Attributes; p++)
  58.     {
  59.         no_gatesOpened[p] = -1;
  60.     }
  61.  
  62.     //Opened Gates -= 1
  63.     //Amount to compare is = (n-1) where n is total number of attribute opened
  64.     int compare_Times = (gatesOpened - 1);
  65.     for (int a = 0; a < numbersOf_Attributes; a++)
  66.     {
  67.         for (int b = 0; b < THE_ARRAY_SIZE; b++)
  68.         {
  69.             final_ResultsNo[a][b] = -1;
  70.         }
  71.     }
  72.  
  73.     //Flags and locators
  74.     int counter_2 = 0;
  75.     int temp_store = 0;
  76.     int validCounts = 0;
  77.  
  78.     //Assigning ID to no_gatesOpened
  79.     for (int d = 0; d < numbersOf_Attributes; d++)
  80.     {
  81.         if (attributesGate[d] == true)
  82.         {
  83.             no_gatesOpened[counter_2] = d;
  84.             counter_2++;
  85.         }
  86.     }
  87.     //test no gatesOpened///////////////////////////////
  88.     int temp_nogate[12];
  89.     for (int h0 = 0; h0 < 12; h0++)
  90.     {
  91.         temp_nogate[h0] = -1;
  92.     }
  93.     counter_2 = 0;
  94.     for (int h = 0; h < numbersOf_Attributes; h++)
  95.     {
  96.         if (no_gatesOpened[h] != -1)
  97.         {
  98.             temp_nogate[counter_2] = no_gatesOpened[h];
  99.             counter_2++;
  100.         }
  101.     }
  102.     for (int h2 = 0; h2 < numbersOf_Attributes; h2++)
  103.     {
  104.         no_gatesOpened[h2] = temp_nogate[h2];
  105.     }
  106.     ////////////////////////////////////////////////////
  107.  
  108.     //Assigning IDs to inputValue_string
  109.     for (int f = 0; f < numbersOf_Attributes; f++)
  110.     {
  111.         counter_2 = 0;
  112.         if (attributesGate[f] == true)
  113.         {
  114.  
  115.             for (int t = 0; t < THE_ARRAY_SIZE; t++)
  116.             {
  117.                 temp_store = advancedCompare(inputValue_string[f], f, t);
  118.                 if (temp_store == t)
  119.                 {
  120.                     valid_ResultsNo[f][counter_2] = temp_store;
  121.                     counter_2++;
  122.                 }
  123.             }
  124.  
  125.             if (counter_2 != 0)
  126.             {
  127.                 validCounts++;
  128.             }
  129.         }
  130.     }
  131.  
  132.     //////////////////////////////////////////////////
  133.     cout << "How many valid: " << validCounts << endl;
  134.  
  135.     if (validCounts != gatesOpened && gatesOpened > 1)
  136.     {
  137.         return false;
  138.     }
  139.     //////////////////////////////////////////////////
  140.     int search_result_count = 0;
  141.     if (gatesOpened > 1)
  142.     {
  143.         for (int s = 0; s < compare_Times; s++)
  144.         {
  145.             counter_2 = 0;
  146.             if (s == 0)
  147.             {
  148.                 for (int i = 0; i < THE_ARRAY_SIZE; i++)
  149.                 {
  150.                     for (int j = 0; j < THE_ARRAY_SIZE; j++)
  151.                     {
  152.                         if (valid_ResultsNo[no_gatesOpened[s + 1]][i] == valid_ResultsNo[no_gatesOpened[s]][j])
  153.                         {
  154.                             if (valid_ResultsNo[no_gatesOpened[s]][j] != -1)
  155.                             {
  156.                                 final_ResultsNo[s][counter_2] = valid_ResultsNo[no_gatesOpened[s]][j];
  157.                                 counter_2++;
  158.                             }
  159.                         }
  160.                     }
  161.                 }
  162.             }
  163.             else
  164.             {
  165.                 for (int a = 0; a < THE_ARRAY_SIZE; a++)
  166.                 {
  167.                     for (int b = 0; b < THE_ARRAY_SIZE; b++)
  168.                     {
  169.                         if (valid_ResultsNo[no_gatesOpened[s + 1]][a] == final_ResultsNo[s - 1][b])
  170.                         {
  171.                             if (final_ResultsNo[s - 1][b] != -1)
  172.                             {
  173.                                 final_ResultsNo[s][counter_2] = valid_ResultsNo[no_gatesOpened[s + 1]][a];
  174.                                 counter_2++;
  175.                             }
  176.                         }
  177.                     }
  178.                 }
  179.             }
  180.         }
  181.         counter_2 = 1;
  182.         for (int p = 0; p < THE_ARRAY_SIZE; p++)
  183.         {
  184.             if (final_ResultsNo[compare_Times - 1][p] != -1)
  185.             {
  186.                 search_result_count++;
  187.             }
  188.         }
  189.         if (search_result_count > 0)
  190.         {
  191.             cout << "--------------------------------1+------------------------------------" << endl;
  192.             for (int p = 0; p < THE_ARRAY_SIZE; p++)
  193.             {
  194.                 if (final_ResultsNo[compare_Times - 1][p] != -1)
  195.                 {
  196.                     cout << counter_2 << ". ";
  197.                     cout << col1[final_ResultsNo[compare_Times - 1][p]] << " " << STR1[final_ResultsNo[compare_Times - 1][p]] << endl;
  198.  
  199.                     counter_2++;
  200.                 }
  201.             }
  202.             cout << "--------------------------------1+------------------------------------" << endl;
  203.         }
  204.     }
  205.     else
  206.     {
  207.         counter_2 = 1;
  208.         for (int p = 0; p < THE_ARRAY_SIZE; p++)
  209.         {
  210.             if (valid_ResultsNo[no_gatesOpened[0]][p] != -1)
  211.             {
  212.                 search_result_count++;
  213.             }
  214.         }
  215.         if (search_result_count > 0)
  216.         {
  217.             cout << "---------------------------------1-----------------------------------" << endl;
  218.             for (int p = 0; p < THE_ARRAY_SIZE; p++)
  219.             {
  220.                 if (valid_ResultsNo[no_gatesOpened[0]][p] != -1)
  221.                 {
  222.                     cout << counter_2 << ". ";
  223.                     cout << col1[valid_ResultsNo[no_gatesOpened[0]][p]] << " " << STR1[valid_ResultsNo[no_gatesOpened[0]][p]] << endl;
  224.  
  225.                     counter_2++;
  226.                 }
  227.             }
  228.             cout << "---------------------------------1-----------------------------------" << endl;
  229.         }
  230.     }
  231.     cout << "Matched Employee(s): " << search_result_count << endl;
  232.     if (search_result_count == 0)
  233.     {
  234.         cout << "---------------------------------0-----------------------------------" << endl;
  235.         cout << endl
  236.              << endl
  237.              << endl
  238.              << endl
  239.              << endl;
  240.         cout << "No Employee(s) Found!" << endl;
  241.         cout << endl
  242.              << endl
  243.              << endl
  244.              << endl
  245.              << endl;
  246.         cout << "---------------------------------0-----------------------------------" << endl;
  247.     }
  248.     return true;
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement