SHARE
TWEET

Card Number - Bank Identification

daniil_mironoff Dec 9th, 2018 (edited) 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int size_str(char * str) {
  5.     int size = 0;
  6.     while (str[size] != 0) {
  7.         size++;
  8.     }
  9.    
  10.     return size;
  11. }
  12.  
  13. int return_int_char_hz(char * num, int a, int b) {
  14.     int chislo = 0;
  15.     for (int i = 0; b >= a + i; i++) {
  16.         chislo = chislo * 10 + (num[a + i] - 48);
  17.     }
  18.    
  19.     return chislo;
  20. }
  21.  
  22.  
  23. int main() {
  24.     char * card_num;
  25.     char * next_card_num;
  26.     int size_card_num;
  27.     enter_card_number: ;
  28.     card_num = new char[16];
  29.     cout << "Enter card number: ";
  30.     cin >> card_num;
  31.  
  32.     size_card_num = size_str(card_num);
  33.     while(size_str(card_num) < 16) {
  34.         next_card_num = new char[4];
  35.         cin >> next_card_num;
  36.        
  37.         for(int i = 0; size_str(next_card_num) > i; i++) {
  38.             card_num[size_card_num + i] = next_card_num[i];
  39.         }
  40.        
  41.         size_card_num += size_str(next_card_num);
  42.         delete next_card_num;
  43.     }
  44.  
  45.     if (size_card_num > 16) {
  46.         cout << "Invalid number card. Enter card number again.\n";
  47.         delete card_num;
  48.         goto enter_card_number;
  49.     }
  50.  
  51.     for(int i = 0; i < 16; i++) {
  52.         if (card_num[i] < 48 || 57 < card_num[i]) {
  53.             cout << "Invalid number card. Enter card number again.\n";
  54.             delete card_num;
  55.             goto enter_card_number;
  56.         }
  57.     }
  58.    
  59.     // Payment system
  60.     switch (card_num[0]) {
  61.         case '2':
  62.             cout << "Payment system: MIR" << endl;
  63.             break;
  64.         case '3':
  65.             cout << "Payment system: American Express/Maestro/JCB International" << endl;
  66.             break;
  67.         case '4':
  68.             cout << "Payment system: VISA" << endl;
  69.             break;
  70.         case '5':
  71.             cout << "Payment system: MasterCard" << endl;
  72.             break;
  73.         case '6':
  74.             cout << "Payment system: China UnionPay" << endl;
  75.             break;
  76.         case '7':
  77.             cout << "Payment system: UEC" << endl;
  78.             break;
  79.         default:
  80.             cout << "Payment system: undefined" << endl;
  81.             break;
  82.     }
  83.    
  84.     int num1 = return_int_char_hz(card_num, 1, 4);
  85.     int num2 = return_int_char_hz(card_num, 1, 5);
  86.    
  87.     int ** banks = new int * [7];
  88.     banks[0] = new int [7] {15428, 5841, 77964, 21178, 48601, 48673, 76371}; // alfabank
  89.     banks[1] = new int [5] {27229, 47520, 27883, 6223, 2006}; // VTB24
  90.     banks[2] = new int [6] {16792, 65204, 25744, 48265, 54373, 65203}; // MDM
  91.     banks[3] = new int [4] {5870, 34146, 32301, 44573}; // otkritie
  92.     banks[4] = new int [6] {47817, 47818, 76206, 76208, 54759, 20373}; // promsvyazbank
  93.     banks[5] = new int [12] {4693, 3900, 7758, 27601, 27631, 27644, 27683, 27901, 4696, 4692, 4691, 2022}; // sberbank
  94.     banks[6] = new int [11] {11900, 24553, 24554, 56515, 90986, 94343, 29047, 57808, 57809, 76642, 31318}; // trast
  95.    
  96.     int counts[7] = {7, 5, 6, 4, 6, 12, 11};
  97.     int name_bank = -1;
  98.    
  99.     for (int i = 0; 7 > i; i++) {
  100.         int count = counts[i];
  101.         for (int j = 0; j < count; j++) {
  102.             if (banks[i][j] == num1 || banks[i][j] == num2) {
  103.                 name_bank = i;
  104.             }
  105.         }
  106.     }
  107.    
  108.     switch (name_bank) {
  109.         case 0:
  110.             cout << "Bank: Alfabank" << endl;
  111.             break;
  112.         case 1:
  113.             cout << "Bank: VTB24" << endl;
  114.             break;
  115.         case 2:
  116.             cout << "Bank: MDM" << endl;
  117.             break;
  118.         case 3:
  119.             cout << "Bank: Otrkitie" << endl;
  120.             break;
  121.         case 4:
  122.             cout << "Bank: Promsvyazbank" << endl;
  123.             break;
  124.         case 5:
  125.             cout << "Bank: Sberbank" << endl;
  126.             break;
  127.         case 6:
  128.             cout << "Bank: Trast" << endl;
  129.             break;
  130.         default:
  131.             cout << "Bank: undefined" << endl;
  132.             break;
  133.     }
  134.    
  135.     return 0;
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top