TheRasVa

[WIP] Симулятор банка v4

Oct 17th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.38 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6. bool success = true;
  7.  
  8.  
  9. class Account
  10. {
  11. private:
  12.     long double balance, overdraft, percent;
  13.     string id;
  14.  
  15. public:
  16.     Account(string ids)
  17.     {
  18.         id = ids;
  19.         ifstream file("BankSimId_" + id + ".txt");
  20.         //if (file.fail())
  21.         //{
  22.         //  string isCreate = "n";
  23.         //  system("color 4c");
  24.         //  system("title ERROR - Bank Simulator 2016");
  25.         //  cout << "E: Файл \"" << "BankSimId_" + id + ".txt" << "\" не существует.\nСоздать? (y/n)\n>> ";
  26.         //  getline(cin, isCreate);
  27.         //  if (isCreate == "y" || isCreate == "Y")
  28.         //  {
  29.         //      system("color 0E");
  30.         //      system("title Bank Simulator 2016");
  31.         //      cout << "Создание нового файла клиента.\n";
  32.         //      // TODO: Создание файла клиента прямо в программе.
  33.         //  }
  34.         //  else
  35.         //  {
  36.         //      success = false;
  37.         //      cout << "Введите правильный id и попробуйте еще раз.\n";
  38.         //      system("pause");
  39.         //      system("cls");
  40.         //      system("color 0E");
  41.         //      system("title Bank Simulator 2016");
  42.         //  }
  43.         //}
  44.         if (file.eof())
  45.         {
  46.             success = false;
  47.             system("color 4c");
  48.             system("title ERROR - Bank Simulator 2016");
  49.             cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"balance\"]\n";
  50.             system("pause");
  51.             system("cls");
  52.             system("color 0E");
  53.             system("title Bank Simulator 2016");
  54.         }
  55.  
  56.         file >> balance;
  57.         if (file.eof())
  58.         {
  59.             success = false;
  60.             system("color 4c");
  61.             cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"overdraft\"]\n";
  62.             system("pause");
  63.             system("cls");
  64.             system("color 0E");
  65.             system("title Bank Simulator 2016");
  66.         }
  67.  
  68.         file >> overdraft;
  69.         if (file.eof())
  70.         {
  71.             success = false;
  72.             system("color 4c");
  73.             cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"percent\"]\n";
  74.             system("pause");
  75.             system("cls");
  76.             system("color 0E");
  77.             system("title Bank Simulator 2016");
  78.         }
  79.  
  80.         file >> percent;
  81.         if (success)
  82.         {
  83.             success = true;
  84.             system("color 2a");
  85.             cout << "I: Чтение из файла \"" << "BankSimId_" + id + ".txt" << "\" выполнено.\n";
  86.             system("pause");
  87.             system("cls");
  88.             system("color 0E");
  89.         }
  90.         file.close();
  91.     }
  92.  
  93.     ~Account()
  94.     {
  95.  
  96.     }
  97.  
  98.     long double getBalance()   { return balance;   }
  99.     long double getOverdraft() { return overdraft; }
  100.     long double getPercent()   { return percent;   }
  101.     string getId()             { return id;        }
  102. };
  103.  
  104.  
  105. class Client
  106. {
  107. private:
  108.     string name, surname;
  109.     Account account;
  110.  
  111. public:
  112.     Client(string ids) :account(ids)
  113.     {
  114.         ifstream file("BankSimId_" + ids + ".txt");
  115.         if (file.fail())
  116.         {
  117.             string isCreate = "n";
  118.             system("color 4c");
  119.             system("title ERROR - Bank Simulator 2016");
  120.             cout << "E: Файл \"" << "BankSimId_" + ids + ".txt" << "\" не существует.\nСоздать? (y/n)\n>> ";
  121.             getline(cin, isCreate);
  122.             if (isCreate == "y" || isCreate == "Y")
  123.             {
  124.                 system("color 0E");
  125.                 system("title Bank Simulator 2016");
  126.                 cout << "Создание нового файла клиента.\n";
  127.                 // TODO: Создание файла клиента прямо в программе.
  128.             }
  129.             else
  130.             {
  131.                 success = false;
  132.                 cout << "Введите правильный id и попробуйте еще раз.\n";
  133.                 system("pause");
  134.                 system("cls");
  135.                 system("color 0E");
  136.                 system("title Bank Simulator 2016");
  137.             }
  138.         }
  139.  
  140.         if (file.eof())
  141.         {
  142.             success = false;
  143.             system("color 4c");
  144.             system("title ERROR - Bank Simulator 2016");
  145.             cout << "E: Файл " << "BankSimId_" + ids + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"surname\"]\n";
  146.             system("pause");
  147.             system("cls");
  148.             system("color 0E");
  149.             system("title Bank Simulator 2016");
  150.         }
  151.  
  152.         file >> surname;
  153.         if (file.eof())
  154.         {
  155.             success = false;
  156.             system("color 4c");
  157.             system("title ERROR - Bank Simulator 2016");
  158.             cout << "E: Файл " << "BankSimId_" + ids + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"name\"]\n";
  159.             system("pause");
  160.             system("cls");
  161.             system("color 0E");
  162.             system("title Bank Simulator 2016");
  163.         }
  164.  
  165.         file >> name;
  166.  
  167.  
  168.         file.close();
  169.     }
  170.  
  171.     ~Client()
  172.     {
  173.         if (success)
  174.         {
  175.             ofstream file("BankSimId_" + account.getId() + ".txt");
  176.             cout << "I: Запись в файл \"" << "BankSimId_" + account.getId() + ".txt" << "\"...\n";
  177.             file << surname << " " << name << " " << account.getBalance() << " " << account.getOverdraft() << " " << account.getPercent();
  178.             if (file.fail())
  179.             {
  180.                 system("color 4c");
  181.                 system("title ERROR - Bank Simulator 2016");
  182.                 cout << "E: Ошибка при записи в файл, выход...\n";
  183.             }
  184.             else
  185.             {
  186.                 system("color 2a");
  187.                 cout << "I: Запись выполнена, выход...\n";
  188.             }
  189.             system("pause");
  190.         }
  191.     }
  192.  
  193.     string getName()    { return name;    }
  194.     string getSurname() { return surname; }
  195. };
  196.  
  197.  
  198. int main()
  199. {
  200.     setlocale(0, "");
  201.     system("color 0E");
  202.     system("title Bank Simulator 2016");
  203.    
  204.     Client client("dfa2fsfe");
  205.  
  206.     system("pause");
  207.     return 0;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment