AleksandarH

Y1S1 Colleague's Semester Homework, Banking

Apr 30th, 2021 (edited)
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.78 KB | None | 0 0
  1. #include<iostream>
  2. #include <fstream>
  3. #include <bitset>
  4. using namespace std;
  5.  
  6. struct bank {
  7.     char name[20];
  8.     int BGN = 0, EUR = 0, USD = 0;
  9.     int acc_no;
  10.     int day;
  11.     int month;
  12.     int year;
  13.  
  14. };
  15. // Декларирана Структура
  16.  
  17. void depositor(bank* D, int& depositorCount);
  18. void multiple(bank* D, int& depositorCount);
  19. void showBGN(bank* D, int& depositorCount);
  20. void showEUR(bank* D, int& depositorCount);
  21. void withdraw(bank* D, int& depositorCount);
  22. void WriteToBinary(bank* D, int& depositorCount);
  23. int readBinary(bank* D);
  24. void sort(bank* D, int& depositorCount);
  25.  
  26. void createDepositor(bank* D, int& depositorCount, bank newDepositor)
  27. {
  28.     D[depositorCount] = newDepositor;
  29.     depositorCount++;
  30. }
  31. // Брояч за депоситори
  32. void main()
  33. {
  34.  
  35.     bank D[50];
  36.     int  choiceBinary;
  37.     int adddepositor = readBinary(D);
  38.     int ch;
  39.     do {
  40.         cout << "\t ----------------------------------------" << endl;
  41.         cout << "\t                 MAIN MENU" << endl;
  42.         cout << "\t ----------------------------------------" << endl;
  43.         cout << "\t| 1. Add Depositor                       |" << endl;
  44.         cout << "\t| 2. Add multiple depositors             |" << endl;
  45.         cout << "\t| 3. Show all depositors with value BGN  |" << endl;
  46.         cout << "\t| 4. Show depositor with max deposit EUR |" << endl;
  47.         cout << "\t| 5. Withdraw                            |" << endl;
  48.         cout << "\t| 6. Sort profiles                       |" << endl;
  49.         cout << "\t| 7. Save binary to file                 |" << endl;
  50.         cout << "\t| 8. Exit                                |" << endl;
  51.         cout << "\t ----------------------------------------" << endl;
  52.         // Това е главното меню
  53.         do {
  54.             cout << "\n\t YOUR CHOICE IS: ";
  55.             cin >> ch;
  56.         } while (ch < 1 || ch>8);
  57.         switch (ch)
  58.         {
  59.         case 1: depositor(D, adddepositor); break;
  60.         case 2: multiple(D, adddepositor); break;
  61.         case 3: showBGN(D, adddepositor); break;
  62.         case 4: showEUR(D, adddepositor); break;
  63.         case 5: withdraw(D, adddepositor); break;
  64.         case 6: sort(D, adddepositor); break;
  65.         case 7: WriteToBinary(D, adddepositor); break;
  66.  
  67.         }
  68.     } while (ch != 8);
  69.  
  70. } // Това е цялото меню в което се съдържа switch която праща към case-овете
  71.  
  72.  
  73. void depositor(bank* D, int& depositorCount)
  74. {
  75.     bank newdepositor;
  76.     int n, ch, choice;
  77.     int deposit;
  78.     int bg1 = 0, bg2 = 0, bg3 = 0;
  79.     int usd1 = 0, usd2 = 0, usd3 = 0;
  80.     int eur1 = 0, eur2 = 0, eur3 = 0;
  81.  
  82.     system("cls");
  83.     cout << "\n DEPOSITOR ACCOUNT:" << endl; // В тази функция може да се въведе само 1 депоситор
  84.     cout << "\n Enter name: ";
  85.     cin.ignore();
  86.     cin >> newdepositor.name;
  87.     cout << "\n Create account number:";
  88.     cin >> newdepositor.acc_no;
  89.     if (newdepositor.acc_no < 1)
  90.     {
  91.         system("cls");
  92.         cout << "\t|--------------------------------------|" << endl;
  93.         cout << "\t| Your account number cant be under 1  |" << endl;
  94.         cout << "\t|--------------------------------------|" << endl;
  95.  
  96.         return;
  97.     }
  98.     for (int i = 0; i < depositorCount; i++)
  99.     {
  100.         if (newdepositor.acc_no == D[i].acc_no)
  101.         {
  102.             system("cls");
  103.             cout << " This account number already exist, please enter a different number" << endl;
  104.             return;
  105.         }
  106.     }
  107.     // Ако депоситорите са повече от 50 програмата ще прекъсне броенето и ще се върне назад към менюто
  108.     cout << "\n Enter day: ";
  109.     cin >> newdepositor.day;
  110.     cout << "\n Enter month (in numbers): ";
  111.     cin >> newdepositor.month;
  112.     cout << "\n Enter year: ";
  113.     cin >> newdepositor.year;
  114.     do {
  115.  
  116.         cout << "\n 1. New Depositor";
  117.         cout << "\n 2. Go back to main menu ";
  118.         cout << "\n Choose option: ";
  119.         cin >> ch;
  120.         if (ch < 1 || ch > 2)
  121.         {
  122.             system("cls");
  123.             cout << "|----------------------|" << endl;
  124.             cout << "| Please select 1 or 2 |" << endl;
  125.             cout << "|----------------------|" << endl;
  126.         } // Ако се избере по-малко от 1 или по-голямо от 2 програмата ще се прекрати
  127.         else if (ch == 2)
  128.         {
  129.             system("cls");
  130.             return;
  131.         } // Ако се избере 2 ще се върне към главното меню
  132.     } while (ch < 1 || ch > 2);
  133.     do {
  134.         cout << "\n 1. Deposit";
  135.         cout << "\n Choose option:";
  136.         cin >> ch;
  137.         if (ch < 1 || ch > 1)
  138.         {
  139.  
  140.             system("cls");
  141.             cout << "|---------------------------------|" << endl;
  142.             cout << "| Please select the first option! |" << endl;
  143.             cout << "|---------------------------------|" << endl;
  144.  
  145.         }// Ако се избере по-малко от 1 или по-голямо от 2 програмата ще се прекрати
  146.     } while (ch != 1);
  147.     cout << "\n How many deposits you want to make? ";
  148.     cin >> deposit;
  149.     for (int i = 0; i < deposit; i++) // Брояч за влогове
  150.     {
  151.         if (deposit < 1)
  152.         {
  153.             system("cls");
  154.             cout << "|-----------------------------------------|" << endl;
  155.             cout << "|  Minimum deposit for your account is 1  |" << endl;
  156.             cout << "|  Please try again                       |" << endl;
  157.             cout << "|-----------------------------------------|" << endl;
  158.             return;
  159.         }
  160.         if (deposit > 3)
  161.         {
  162.             system("cls");
  163.             cout << "|-----------------------------------------|" << endl;
  164.             cout << "| Maximum deposits for your account is 3  |" << endl;
  165.             cout << "| Please try again                        |" << endl;
  166.             cout << "|-----------------------------------------|" << endl;
  167.             return;
  168.         }
  169.         // Максимума на влоговете е 3 и ако се избере повече от 3 програмата ще се прекрати
  170.         do {
  171.  
  172.             cout << "\n Values:" << endl;
  173.             cout << "\n 1. BGN";
  174.             cout << "\n 2 .USD";
  175.             cout << "\n 3. EUR";
  176.             cout << "\n Choose your value: ";
  177.             cin >> choice;
  178.             if (choice < 1 || choice > 3)
  179.             {
  180.                 system("cls");
  181.                 cout << "|---------------------------------|" << endl;
  182.                 cout << "| Please enter number from 1 to 3 |" << endl;
  183.                 cout << "|---------------------------------|" << endl;
  184.  
  185.             }
  186.             if (choice == 1)
  187.             {
  188.                 if (deposit == 3)
  189.                 {
  190.                     cout << "\n How much you want to deposit: ";
  191.                     cin >> bg3;
  192.                 }
  193.                 if (deposit < 3)
  194.                 {
  195.                     cout << "\n How much you want to deposit (Minimum is 500 BGN): ";
  196.                     if (choice == 1 || deposit == 1)
  197.                     {
  198.                         cin >> bg1;
  199.                     }
  200.                     else if (choice == 1 || deposit == 2)
  201.                     {
  202.                         cin >> bg1 >> bg2;
  203.                     }
  204.                     if (bg1 < 500)
  205.                     {
  206.                         system("cls");
  207.                         cout << "|-------------------------------------------------------|" << endl;
  208.                         cout << "| Minimum deposit is 500 BGN for deposits under 3 times |" << endl;
  209.                         cout << "|-------------------------------------------------------|" << endl << endl;
  210.                         return;
  211.  
  212.                     }
  213.                 }
  214.                 newdepositor.BGN += bg1 + bg2 + bg3; // Събира стойностите на вкараните суми в една обща
  215.  
  216.             }
  217.  
  218.             if (choice == 2)
  219.             {
  220.                 if (deposit == 3)
  221.                 {
  222.                     cout << "\n How much you want to deposit: ";
  223.                     cin >> usd3;
  224.                 }
  225.                 if (deposit < 3)
  226.                 {
  227.                     cout << "\n How much you want to deposit (Minimum is 500 USD): ";
  228.                     if (choice == 2 || deposit == 1)
  229.                     {
  230.                         cin >> usd1;
  231.                     }
  232.                     else if (choice == 2 || deposit == 2)
  233.                     {
  234.                         cin >> usd1 >> usd2;
  235.                     }
  236.                     if (usd1 < 500)
  237.                     {
  238.                         system("cls");
  239.                         cout << "|-------------------------------------------------------|" << endl;
  240.                         cout << "| Minimum deposit is 500 USD for deposits under 3 times |" << endl;
  241.                         cout << "|-------------------------------------------------------|" << endl << endl;
  242.                         return;
  243.  
  244.                     }
  245.                 }
  246.                 newdepositor.USD += usd1 + usd2 + usd3; // Събира стойностите на вкараните суми в една обща
  247.             }
  248.             if (choice == 3)
  249.             {
  250.                 if (deposit == 3)
  251.                 {
  252.                     cout << "\n How much you want to deposit: ";
  253.                     cin >> eur3;
  254.                 }
  255.                 if (deposit < 3)
  256.                 {
  257.                     cout << "\n How much you want to deposit (Minimum is 500 EUR): ";
  258.                     if (choice == 3 || deposit == 1)
  259.                     {
  260.                         cin >> eur1;
  261.                     }
  262.                     else if (choice == 3 || deposit == 2)
  263.                     {
  264.                         cin >> eur1 >> eur2;
  265.                     }
  266.                     if (eur1 < 500)
  267.                     {
  268.                         system("cls");
  269.                         cout << "|-------------------------------------------------------|" << endl;
  270.                         cout << "| Minimum deposit is 500 EUR for deposits under 3 times |" << endl;
  271.                         cout << "|-------------------------------------------------------|" << endl << endl;
  272.                         return;
  273.  
  274.                     }
  275.                 }
  276.                 newdepositor.EUR += eur1 + eur2 + eur3; // Събира стойностите на вкараните суми в една обща
  277.             }
  278.  
  279.         } while (choice < 1 || choice >3);
  280.  
  281.     }
  282.  
  283.     createDepositor(D, depositorCount, newdepositor);
  284.     system("cls");
  285. }
  286.  
  287.  
  288. void multiple(bank* D, int& depositorCount)
  289. {
  290.     bank newdepositor;
  291.     int  deposit, n, ch;
  292.     int bg1 = 0, bg2 = 0, bg3 = 0;
  293.     int usd1 = 0, usd2 = 0, usd3 = 0;
  294.     int eur1 = 0, eur2 = 0, eur3 = 0;
  295.     cout << "\n How many depositors do you want to add?" << endl;
  296.     cin >> n;
  297.  
  298.     for (int i = 0; i < n; i++) // Този брояч следи колко хора са въведени от интеджера "n", и ако са повече от 1 ще се повтори до толкова колкото са на брой
  299.     {
  300.         if (n < 1)
  301.         {
  302.             system("cls");
  303.             cout << "\n The minimum is 1 depositor" << endl;
  304.             cout << "\n Please try again" << endl;
  305.             return;
  306.  
  307.         }
  308.         else if (n > 50)
  309.         {
  310.             system("cls");
  311.             cout << "\n The maximum is 50" << endl;
  312.             cout << "\n Please try again" << endl;
  313.             return;
  314.  
  315.         }
  316.         // Ако депоситорите са повече от 50 програмата ще прекъсне броенето и ще се върне назад към менюто
  317.         system("cls");
  318.         cout << "\n DEPOSITOR ACCOUNT:" << endl;
  319.         cout << "\n Enter name: ";
  320.         cin.ignore();
  321.         cin >> newdepositor.name;
  322.         cout << "\n Create account number:";
  323.         cin >> newdepositor.acc_no;
  324.         if (newdepositor.acc_no < 1)
  325.         {
  326.             system("cls");
  327.             cout << "\t|--------------------------------------|" << endl;
  328.             cout << "\t| Your account number cant be under 1  |" << endl;
  329.             cout << "\t|--------------------------------------|" << endl;
  330.  
  331.             return;
  332.         }// Ако номера на акаунта е под 1 ще излезе грешка и програмата ще спре
  333.         for (int i = 0; i < depositorCount; i++)
  334.         {
  335.             if (newdepositor.acc_no == D[i].acc_no)
  336.             {
  337.                 system("cls");
  338.                 cout << " This account number already exist, please enter a different number" << endl;
  339.                 return;
  340.             }
  341.         }
  342.         // Тука се проверява ако номера на акаунта вече съществува ще излезе грешка
  343.         cout << "\n Enter day: ";
  344.         cin >> newdepositor.day;
  345.         cout << "\n Enter month: ";
  346.         cin >> newdepositor.month;
  347.         cout << "\n Enter year: ";
  348.         cin >> newdepositor.year;
  349.         do {
  350.  
  351.             cout << "\n 1. New Depositor";
  352.             cout << "\n 2. Go back to main menu ";
  353.             cout << "\n Choose option: ";
  354.             cin >> ch;
  355.             if (ch < 1 || ch > 2)
  356.             {
  357.                 system("cls");
  358.                 cout << "|----------------------|" << endl;
  359.                 cout << "| Please select 1 or 2 |" << endl;
  360.                 cout << "|----------------------|" << endl;
  361.             }
  362.             else if (ch == 2)
  363.             {
  364.                 system("cls");
  365.                 return;
  366.             }
  367.         } while (ch < 1 || ch > 2);
  368.         do {
  369.             cout << "\n 1. Deposit";
  370.             cout << "\n Choose option:";
  371.             cin >> ch;
  372.             if (ch < 1 || ch > 1)
  373.             {
  374.  
  375.                 system("cls");
  376.                 cout << "|---------------------------------|" << endl;
  377.                 cout << "| Please select the first option! |" << endl;
  378.                 cout << "|---------------------------------|" << endl;
  379.  
  380.             }
  381.         } while (ch != 1);
  382.         cout << "\n How many deposits you want to make? ";
  383.         cin >> deposit;
  384.         for (int i = 0; i < deposit; i++)
  385.         {
  386.             if (deposit > 3)
  387.             {
  388.                 system("cls");
  389.                 cout << "|-----------------------------------------|" << endl;
  390.                 cout << "| Maximum deposits for your account is 3  |" << endl;
  391.                 cout << "| Please try again                        |" << endl;
  392.                 cout << "|-----------------------------------------|" << endl;
  393.                 break;
  394.             }
  395.             else if (deposit < 1)
  396.             {
  397.                 system("cls");
  398.                 cout << "|-----------------------------------------|" << endl;
  399.                 cout << "|  Minimum deposit for your account is 1  |" << endl;
  400.                 cout << "|  Please try again                       |" << endl;
  401.                 cout << "|-----------------------------------------|" << endl;
  402.                 break;
  403.             }
  404.             do {
  405.                 cout << "\n Values:" << endl;
  406.                 cout << "\n 1. BGN";
  407.                 cout << "\n 2 .USD";
  408.                 cout << "\n 3. EUR";
  409.                 cout << "\n Choose your value: ";
  410.                 cin >> ch;
  411.                 if (ch < 1 || ch > 3)
  412.                 {
  413.                     cout << "\n Please enter number from 1 to 3";
  414.  
  415.                 }
  416.                 if (ch == 1)
  417.                 {
  418.                     if (deposit == 3)
  419.                     {
  420.                         cout << "\n How much you want to deposit: ";
  421.                         cin >> bg3;
  422.                     }
  423.                     if (deposit < 3)
  424.                     {
  425.                         cout << "\n How much you want to deposit (Minimum is 500 BGN): ";
  426.                         if (ch == 1 || deposit == 1)
  427.                         {
  428.                             cin >> bg1;
  429.                         }
  430.                         else if (ch == 1 || deposit == 2)
  431.                         {
  432.                             cin >> bg1 >> bg2;
  433.                         }
  434.                         if (bg1 < 500)
  435.                         {
  436.                             system("cls");
  437.                             cout << "|-------------------------------------------------------|" << endl;
  438.                             cout << "| Minimum deposit is 500 BGN for deposits under 3 times |" << endl;
  439.                             cout << "|-------------------------------------------------------|" << endl << endl;
  440.                             return;
  441.  
  442.                         }
  443.                     }
  444.                     newdepositor.BGN += bg1 + bg2 + bg3;
  445.  
  446.                 }
  447.  
  448.                 if (ch == 2)
  449.                 {
  450.                     if (deposit == 3)
  451.                     {
  452.                         cout << "\n How much you want to deposit: ";
  453.                         cin >> usd3;
  454.                     }
  455.                     if (deposit < 3)
  456.                     {
  457.                         cout << "\n How much you want to deposit (Minimum is 500 USD): ";
  458.                         if (ch == 2 || deposit == 1)
  459.                         {
  460.                             cin >> usd1;
  461.                         }
  462.                         else if (ch == 2 || deposit == 2)
  463.                         {
  464.                             cin >> usd1 >> usd2;
  465.                         }
  466.                         if (usd1 < 500)
  467.                         {
  468.                             system("cls");
  469.                             cout << "|-------------------------------------------------------|" << endl;
  470.                             cout << "| Minimum deposit is 500 USD for deposits under 3 times |" << endl;
  471.                             cout << "|-------------------------------------------------------|" << endl << endl;
  472.                             return;
  473.  
  474.                         }
  475.                     }
  476.                     newdepositor.USD += usd1 + usd2 + usd3;
  477.                 }
  478.                 if (ch == 3)
  479.                 {
  480.                     if (deposit == 3)
  481.                     {
  482.                         cout << "\n How much you want to deposit: ";
  483.                         cin >> eur3;
  484.                     }
  485.                     if (deposit < 3)
  486.                     {
  487.                         cout << "\n How much you want to deposit (Minimum is 500 EUR): ";
  488.                         if (ch == 3 || deposit == 1)
  489.                         {
  490.                             cin >> eur1;
  491.                         }
  492.                         else if (ch == 3 || deposit == 2)
  493.                         {
  494.                             cin >> eur1 >> eur2;
  495.                         }
  496.                         if (eur1 < 500)
  497.                         {
  498.                             system("cls");
  499.                             cout << "|-------------------------------------------------------|" << endl;
  500.                             cout << "| Minimum deposit is 500 EUR for deposits under 3 times |" << endl;
  501.                             cout << "|-------------------------------------------------------|" << endl << endl;
  502.                             return;
  503.  
  504.                         }
  505.                     }
  506.                     newdepositor.EUR += eur1 + eur2 + eur3;
  507.                 }
  508.                 // Ако се избере под 3 депосита програмата ще направи така че минимума от валутата която е въведена да бъде 500
  509.             } while (ch < 1 || ch>3);
  510.         }createDepositor(D, depositorCount, newdepositor);
  511.  
  512.     }system("cls");
  513. }
  514.  
  515. void showBGN(bank* D, int& depositorCount)
  516. {
  517.     if (depositorCount < 1)
  518.     {
  519.         system("cls");
  520.         cout << "|-------------------------------------------------------------|" << endl;
  521.         cout << "| There are not depositors added yet !                        |" << endl;
  522.         cout << "| You can add some buy choose the option in main menu 1 or 2. |" << endl;
  523.         cout << "|-------------------------------------------------------------|" << endl;
  524.  
  525.     }
  526.     // Ако не са добавени депоситори функцията ще даде грешка
  527.     else if (depositorCount > 0)
  528.     {
  529.  
  530.         system("cls");
  531.         cout << "|------------------------------------------|" << endl;
  532.         cout << "| These are all depositors with value BGN  |" << endl;
  533.         cout << "|------------------------------------------|" << endl;
  534.         for (int i = 0; i < depositorCount; i++)
  535.         {
  536.  
  537.  
  538.             if (D[i].BGN > 0)
  539.             {
  540.  
  541.                 cout << " NAME: " << D[i].name << endl;
  542.                 cout << " MONEY DEPOSIT: " << D[i].BGN << " lv" << endl;
  543.             }
  544.  
  545.  
  546.         }
  547.     }// Изписва всички депоситори които са депоситнали с BGN
  548.  
  549. }
  550.  
  551.  
  552. void showEUR(bank* D, int& depositorCount)
  553. {
  554.  
  555.     if (depositorCount < 1)
  556.     {
  557.         system("cls");
  558.         cout << "|-------------------------------------------------------------|" << endl;
  559.         cout << "| There are not depositors added yet !                        |" << endl;
  560.         cout << "| You can add some buy choose the option in main menu 1 or 2. |" << endl;
  561.         cout << "|-------------------------------------------------------------|" << endl;
  562.     }
  563.     else if (depositorCount > 0)
  564.     {
  565.  
  566.         int max = 0;
  567.         for (int i = 0; i < depositorCount; i++)
  568.         {
  569.             if (D[i].EUR > max)
  570.             {
  571.                 max = D[i].EUR;
  572.             }// Ако еврото е по-голямо от макса, то макса равно на еврото
  573.         }
  574.         for (int i = 0; i < depositorCount; i++)
  575.         {
  576.             if (D[i].EUR == max)
  577.             {
  578.                 system("cls");
  579.                 cout << " Depositor ( " << D[i].name << " ) with ACCOUNT number ( " << D[i].acc_no << " ) has the biggest deposit of ( " << max << " ) EUR." << endl;
  580.             }
  581.         }
  582.     }
  583. }
  584. // Функцията ще покаже максимума с еврото
  585.  
  586. void withdraw(bank* D, int& depositorCount)
  587. {
  588.     bank newdepositor;
  589.     int search;
  590.     int ch;
  591.     int wdraw;
  592.     int balance;
  593.     if (depositorCount < 1)
  594.     {
  595.         system("cls");
  596.         cout << "|-------------------------------------------------------------|" << endl;
  597.         cout << "| You haven't deposit yet  !                                   |" << endl;
  598.         cout << "| You can deposit by choose the option in main menu 1 or 2.   |" << endl;
  599.         cout << "|-------------------------------------------------------------|" << endl;
  600.     }
  601.     // Ако не са добавени депоситори тази функция не може да се използва
  602.     else if (depositorCount > 0)
  603.     {
  604.         system("cls");
  605.         cout << "\n Enter your account number: ";
  606.         cin >> search;
  607.         for (int i = 0; i < depositorCount; i++)
  608.         {
  609.             if (search == D[i].acc_no)// Ако номера на акаунта съществува програмата ще продължи
  610.             {
  611.  
  612.                 do {
  613.                     cout << "|----------------------------------------------|" << endl;
  614.                     cout << "| 1. Withdraw everything and Shut down profile |" << endl;
  615.                     cout << "|----------------------------------------------|" << endl << endl;
  616.                     cout << "\n Values:" << endl;
  617.                     cout << "\n 2. BGN";
  618.                     cout << "\n 3. USD";
  619.                     cout << "\n 4. EUR";
  620.                     cout << "\n Choose option: ";
  621.                     cin >> ch;
  622.                     if (ch < 1 || ch > 4)
  623.                     {
  624.                         cout << "\n Please enter number from 1 to 5";
  625.  
  626.                     }// Изборът трябва да от 1 до 4
  627.                     switch (ch)
  628.                     {
  629.                     case 1:  if (D[i].BGN > 0)
  630.                     {
  631.                         D[i].BGN = D[i].BGN - D[i].BGN;
  632.                         system("cls");
  633.                         cout << "|-------------------------------------------|" << endl;
  634.                         cout << "| Transaction was successful                |" << endl;
  635.                         cout << "| Your balance is " << D[i].BGN << " lv                      |" << endl;
  636.                         cout << "| Your account was successfully shut down   |" << endl;
  637.                         cout << "|-------------------------------------------|" << endl;
  638.                         // Занулява парите в акаунта
  639.                     }
  640.                           else if (D[i].USD > 0)
  641.                     {
  642.                         D[i].USD = D[i].USD - D[i].USD;
  643.                         system("cls");
  644.                         cout << "|-------------------------------------------|" << endl;
  645.                         cout << "| Transaction was successful                |" << endl;
  646.                         cout << "| Your balance is " << D[i].USD << " USD                     |" << endl;
  647.                         cout << "| Your account was successfully shut down   |" << endl;
  648.                         cout << "|-------------------------------------------|" << endl;
  649.                         // Занулява парите в акаунта
  650.                     }
  651.                           else if (D[i].EUR > 0)
  652.                     {
  653.                         D[i].EUR = D[i].EUR - D[i].EUR;
  654.                         system("cls");
  655.                         cout << "|-------------------------------------------|" << endl;
  656.                         cout << "| Transaction was successful                |" << endl;
  657.                         cout << "| Your balance is " << D[i].EUR << " EUR                     |" << endl;
  658.                         cout << "| Your account was successfully shut down   |" << endl;
  659.                         cout << "|-------------------------------------------|" << endl;
  660.                         // Занулява парите в акаунта
  661.                     }
  662.                           D[i].acc_no = 0;
  663.                           break;// Номера на акунта става нула
  664.                     case 2:  if (D[i].BGN > 0)
  665.                     {
  666.                         cout << "\n How much you want to withdraw :";
  667.                         cin >> wdraw;// Избира се колко пари да се извадят от акаунта
  668.                         D[i].BGN = D[i].BGN - wdraw;// След като се зададът колко пари да се изкарат от акаунта се задава новата сума
  669.                         if (wdraw > D[i].BGN)
  670.                         {
  671.                             system("cls");
  672.                             cout << "|------------------------------------------------|" << endl;
  673.                             cout << "| You can't withdraw more money than you deposit |" << endl;
  674.                             cout << "|------------------------------------------------|" << endl;
  675.                             break;
  676.                         }
  677.                         else
  678.                         {
  679.                             system("cls");
  680.                             cout << "|-------------------------------------------|" << endl;
  681.                             cout << "| Transaction was successful                |" << endl;
  682.                             cout << "| Your balance is " << D[i].BGN << " BGN                     |" << endl;
  683.                             cout << "|-------------------------------------------|" << endl;
  684.                             break;
  685.                         }
  686.  
  687.                     }
  688.                           else if (D[i].BGN < 1)
  689.                     {
  690.                         system("cls");
  691.                         cout << "|-----------------------------------------|" << endl;
  692.                         cout << "| You haven't deposit with this value yet |" << endl;
  693.                         cout << "|-----------------------------------------|" << endl;
  694.                         break;
  695.  
  696.                     }
  697.                     case 3:
  698.                         if (D[i].USD > 0)
  699.                         {
  700.                             cout << "\n How much you want to withdraw :";
  701.                             cin >> wdraw;// Избира се колко пари да се извадят от акаунта
  702.                             D[i].USD = D[i].USD - wdraw;// След като се зададът колко пари да се изкарат от акаунта се задава новата сума
  703.                             if (wdraw > D[i].BGN)
  704.                             {
  705.                                 system("cls");
  706.                                 cout << "|------------------------------------------------|" << endl;
  707.                                 cout << "| You can't withdraw more money than you deposit |" << endl;
  708.                                 cout << "|------------------------------------------------|" << endl;
  709.                                 break;
  710.                             }
  711.                             else
  712.                             {
  713.                                 system("cls");
  714.                                 cout << "|-------------------------------------------|" << endl;
  715.                                 cout << "| Transaction was successful                |" << endl;
  716.                                 cout << "| Your balance is " << D[i].USD << " USD                     |" << endl;
  717.                                 cout << "|-------------------------------------------|" << endl;
  718.                                 break;
  719.                             }
  720.                         }
  721.                         else if (D[i].USD < 1)
  722.                         {
  723.                             system("cls");
  724.                             cout << "|-----------------------------------------|" << endl;
  725.                             cout << "| You haven't deposit with this value yet |" << endl;
  726.                             cout << "|-----------------------------------------|" << endl;
  727.                             break;
  728.                         }
  729.                     case 4:
  730.  
  731.                         if (D[i].EUR > 0)
  732.                         {
  733.                             cout << "\n How much you want to withdraw :";
  734.                             cin >> wdraw;// Избира се колко пари да се извадят от акаунта
  735.                             D[i].EUR = D[i].EUR - wdraw;// След като се зададът колко пари да се изкарат от акаунта се задава новата сума
  736.                             if (wdraw > D[i].BGN)
  737.                             {
  738.                                 system("cls");
  739.                                 cout << "|------------------------------------------------|" << endl;
  740.                                 cout << "| You can't withdraw more money than you deposit |" << endl;
  741.                                 cout << "|------------------------------------------------|" << endl;
  742.                                 break;
  743.                             }
  744.                             else
  745.                             {
  746.                                 system("cls");
  747.                                 cout << "|-------------------------------------------|" << endl;
  748.                                 cout << "| Transaction was successful                |" << endl;
  749.                                 cout << "| Your balance is " << D[i].EUR << " EUR                     |" << endl;
  750.                                 cout << "|-------------------------------------------|" << endl;
  751.                                 break;
  752.                             }
  753.                         }
  754.                         else if (D[i].EUR < 1)
  755.                         {
  756.                             system("cls");
  757.                             cout << "|-----------------------------------------|" << endl;
  758.                             cout << "| You haven't deposit with this value yet |" << endl;
  759.                             cout << "|-----------------------------------------|" << endl;
  760.                             break;
  761.                         }
  762.  
  763.  
  764.                     }
  765.                 } while (ch < 1 || ch >4);
  766.             }
  767.  
  768.         }
  769.  
  770.  
  771.     }
  772. }
  773.  
  774. void WriteToBinary(bank* D, int& depositorCount)
  775. {
  776.     fstream file("Depositor(s).bin", ios::binary | ios::out);
  777.     if (!file)
  778.     {
  779.         cout << "error while opening this file";
  780.     }
  781.     file.write((char*)D, sizeof(bank) * depositorCount);
  782.     file.close();
  783.     system("cls");
  784.     cout << "|--------------------------------------------|" << endl;
  785.     cout << "| Depositor(s) data was successfully saved ! |" << endl;
  786.     cout << "|--------------------------------------------|" << endl << endl;
  787.  
  788.  
  789. }
  790. // Запис в двоичен файл
  791. int readBinary(bank* D)
  792. {
  793.     long pos;
  794.     int n = 0, i; bank b;
  795.     fstream file;
  796.     file.open("Depositor(s).bin", ios::binary | ios::in);
  797.     if (!file)
  798.     {
  799.         cout << "\n file not exist\n";
  800.         return n;
  801.     }
  802.     file.seekg(0l, ios::end);
  803.     pos = file.tellg();
  804.     file.close();
  805.     n = pos / (sizeof(bank));
  806.     file.open("Depositor(s).bin", ios::binary | ios::in);
  807.     if (!file) { cout << "\n Error in file \n"; exit(1); }
  808.     for (i = 0; i < n; i++)
  809.     {
  810.         file.read((char*)&b, sizeof(bank));
  811.         D[i] = b;
  812.     }
  813.     file.close();
  814.     return n;
  815. }
  816. // Четене на двоичен файл
  817. void sort(bank* D, int& depositorCount)
  818. {
  819.     if (depositorCount < 1)
  820.     {
  821.         system("cls");
  822.         cout << "|-------------------------------------------------------------|" << endl;
  823.         cout << "| There are not depositors added yet !                        |" << endl;
  824.         cout << "| You can add some buy choose the option in main menu 1 or 2. |" << endl;
  825.         cout << "|-------------------------------------------------------------|" << endl << endl;
  826.  
  827.     }
  828.     else if (depositorCount > 0)
  829.     {
  830.         system("cls");
  831.         cout << "|--------------------------------------------------------------|" << endl;
  832.         cout << "|    SORT PROFILES: CREATING ACCOUNG DATE AND MONEY DEPOSIT    |" << endl;
  833.         cout << "|--------------------------------------------------------------|" << endl;
  834.         for (int i = 0; i < depositorCount; i++)
  835.         {
  836.             for (int j = i + 1; j < depositorCount; j++)
  837.             {
  838.                 if (D[i].year > D[j].year)
  839.                 {
  840.                     struct bank temp = D[i];
  841.                     D[i] = D[j];
  842.                     D[j] = temp;
  843.                 }
  844.                 else if (D[i].year == D[j].year && D[i].month > D[j].month)
  845.                 {
  846.                     struct bank temp = D[i];
  847.                     D[i] = D[j];
  848.                     D[j] = temp;
  849.                 }
  850.                 else if (D[i].year == D[j].year && D[i].month == D[j].month && D[i].day > D[j].day)
  851.                 {
  852.                     struct bank temp = D[i];
  853.                     D[i] = D[j];
  854.                     D[j] = temp;
  855.                 }
  856.  
  857.             }
  858.         }
  859.         // Сортировка на датите
  860.         cout << "Accounts deleted:" << endl;
  861.         for (int i = 0; i < depositorCount; i++)
  862.         {
  863.             if (D[i].acc_no == 0)
  864.             {
  865.                 cout << D[i].name << endl;
  866.                 cout << "No deposits, account shutted down" << endl;
  867.             }
  868.         }// Показва изтрите акаунти
  869.         cout << endl << "Active accounts:" << endl;
  870.         for (int i = 0; i < depositorCount; i++)
  871.         {
  872.             if (D[i].acc_no != 0)
  873.             {
  874.                 cout << endl;
  875.                 cout << "ACCOUNT NUMBER: " << D[i].acc_no << endl; // Изписва номер на акунта
  876.                 cout << "ACCOUNT NAME: " << D[i].name << endl; // Изписва името на акаунта
  877.                 cout << "Created on date: " << D[i].day << "." << D[i].month << "." << D[i].year << endl; // Изписва датата на която е създаден акаунта
  878.                 if (D[i].BGN < 1)
  879.                 {
  880.                     cout << "MONEY DEPOSIT: 0 lv" << endl;
  881.                 }
  882.                 else if (D[i].BGN > 0)
  883.                 {
  884.                     cout << "MONEY DEPOSIT: " << D[i].BGN << " lv" << endl; // Изписва парите които са вкарани вътре
  885.                 }
  886.                 if (D[i].USD < 1)
  887.                 {
  888.                     cout << "MONEY DEPOSIT: 0 USD" << endl;
  889.                 }
  890.                 else if (D[i].USD > 0)
  891.                 {
  892.                     cout << "MONEY DEPOSIT: " << D[i].USD << " USD" << endl;// Изписва парите които са вкарани вътре
  893.                 }
  894.                 if (D[i].EUR < 1)
  895.                 {
  896.                     cout << "MONEY DEPOSIT: 0 EUR" << endl;
  897.                 }
  898.                 else if (D[i].EUR > 0)
  899.                 {
  900.                     cout << "MONEY DEPOSIT: " << D[i].EUR << " EUR" << endl << endl;// Изписва парите които са вкарани вътре
  901.                 }
  902.             }
  903.         }
  904.     }
  905. }
Add Comment
Please, Sign In to add comment