Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int advancedCompare(string q, int attributeNo, int pos)
- {
- //Check if the element in that pos is a valid data
- if (STR1[pos].length() == 0)
- {
- return -1;
- }
- string a = "";
- string b = "";
- int w = 0;
- char o_DOB[3] = {'=', '=', '='};
- int i_DOB[3] = {0, 0, 0};
- int e_DOB[3] = {0, 0, 0};
- int temp_store_2 = 0;
- if (attributeNo >= 5 && !(isdigit(q[0])) && attributeNo != 6)
- {
- a = q.substr(0, 1);
- b = q.substr(1, 30);
- w = stoi(b);
- }
- else if (attributeNo >= 5 && isdigit(q[0]) && attributeNo != 6)
- {
- w = stoi(q);
- }
- else if (attributeNo == 6)
- {
- string temp_STR1 = "";
- string temp_STR2 = "";
- int met_slash = 0;
- if (isdigit(q[0]))
- {
- b = q.substr(0, 2);
- i_DOB[0] = stoi(b);
- }
- else
- {
- o_DOB[0] = q[0];
- b = q.substr(1, 2);
- i_DOB[0] = stoi(b);
- }
- int encounter_times = 0;
- for (int u = 0; u < q.length(); u++)
- {
- met_slash = 0;
- if (q[u] == '/')
- {
- //if encounter a space then set met_space to 1
- met_slash = 1;
- encounter_times++;
- }
- if (met_slash == 1)
- {
- if (isdigit(q[u + 1]) && encounter_times == 1)
- {
- b = q.substr(u + 1, 2);
- i_DOB[1] = stoi(b);
- }
- else if (!(isdigit(q[u + 1])) && encounter_times == 1)
- {
- o_DOB[1] = q[u + 1];
- b = q.substr(u + 2, 2);
- i_DOB[1] = stoi(b);
- }
- else if (isdigit(q[u + 1]) && encounter_times == 2)
- {
- b = q.substr(u + 1, 4);
- i_DOB[2] = stoi(b);
- }
- else if (!(isdigit(q[u + 1])) && encounter_times == 2)
- {
- o_DOB[2] = q[u + 1];
- b = q.substr(u + 2, 4);
- i_DOB[2] = stoi(b);
- }
- }
- }
- }
- int compareResult = 0;
- switch (attributeNo)
- {
- //name
- case 0:
- compareResult = STR1[pos].find(q);
- break;
- //country
- case 1:
- compareResult = STR2[pos].find(q);
- break;
- //designation
- case 2:
- compareResult = STR3[pos].find(q);
- break;
- //gender
- case 3:
- if (STR4[pos].compare("female") == 0)
- {
- if (q.compare("female") == 0)
- {
- // cout << "is female" << endl;
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (STR4[pos].compare("male") == 0)
- {
- if (q.compare("male") == 0)
- {
- // cout << "is male" << endl;
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- break;
- //level of education
- case 4:
- compareResult = STR5[pos].find(q);
- break;
- //ID
- case 5:
- if (a.find('>') == 0)
- {
- if (w < col1[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col1[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col1[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- //DOB
- case 6:
- temp_store_2 = col2[pos];
- for (int d = 1000000; d <= 31000000; d += 1000000)
- {
- if (temp_store_2 >= d && temp_store_2 < (d + 1000000))
- {
- e_DOB[0] = (d / 1000000);
- temp_store_2 -= (d);
- }
- }
- for (int m = 10000; m <= 120000; m += 10000)
- {
- if (temp_store_2 >= m && temp_store_2 < (m + 10000))
- {
- e_DOB[1] = (m / 10000);
- temp_store_2 -= (m);
- }
- }
- for (int y = 0; y < 10000; y++)
- {
- if (temp_store_2 == y)
- {
- e_DOB[2] = y;
- }
- }
- // cout << "I_DOB: " << o_DOB[0] << i_DOB[0] << "/" << o_DOB[1] << i_DOB[1] << "/" << o_DOB[2] << i_DOB[2] << endl;
- // cout << "E_DOB: " << e_DOB[0] << '/' << e_DOB[1] << '/' << e_DOB[2] << endl;
- if (i_DOB[0] >= 0 && i_DOB[1] >= 0 && i_DOB[2] >= 0)
- {
- char flags[3] = {'n', 'n', 'n'};
- for (int n = 0; n < 3; n++)
- {
- switch (o_DOB[n])
- {
- case '>':
- if (e_DOB[n] > i_DOB[n])
- {
- flags[n] = 'y';
- }
- else
- {
- flags[n] = 'n';
- }
- break;
- case '<':
- if (e_DOB[n] < i_DOB[n])
- {
- flags[n] = 'y';
- }
- else
- {
- flags[n] = 'n';
- }
- break;
- case '=':
- if (e_DOB[n] == i_DOB[n])
- {
- flags[n] = 'y';
- }
- else
- {
- flags[n] = 'n';
- }
- break;
- }
- }
- if (flags[0] == 'y' && flags[1] == 'y' && flags[2] == 'y')
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else
- {
- compareResult = -1;
- }
- break;
- //Height
- case 7:
- if (a.find('>') == 0)
- {
- if (w < col3[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col3[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col3[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- //Weight
- case 8:
- if (a.find('>') == 0)
- {
- if (w < col4[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col4[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col4[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- //Years of working
- case 9:
- if (a.find('>') == 0)
- {
- if (w < col5[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col5[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col5[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- //Basic Salary
- case 10:
- if (a.find('>') == 0)
- {
- if (w < col6[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col6[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col6[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- //Allowances
- case 11:
- if (a.find('>') == 0)
- {
- if (w < col7[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (a.find('<') == 0)
- {
- if (w > col7[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- }
- else if (w == col7[pos])
- {
- compareResult = pos;
- }
- else
- {
- compareResult = -1;
- }
- break;
- }
- //cout << "Debug: Compare Result in Advanced Compare String: " << attributeNo << endl;
- if (compareResult == string::npos)
- {
- return -1;
- }
- else
- {
- return pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement