Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- bool success = true;
- class Account
- {
- private:
- long double balance, overdraft, percent;
- string id;
- public:
- Account(string ids)
- {
- id = ids;
- ifstream file("BankSimId_" + id + ".txt");
- //if (file.fail())
- //{
- // string isCreate = "n";
- // system("color 4c");
- // system("title ERROR - Bank Simulator 2016");
- // cout << "E: Файл \"" << "BankSimId_" + id + ".txt" << "\" не существует.\nСоздать? (y/n)\n>> ";
- // getline(cin, isCreate);
- // if (isCreate == "y" || isCreate == "Y")
- // {
- // system("color 0E");
- // system("title Bank Simulator 2016");
- // cout << "Создание нового файла клиента.\n";
- // // TODO: Создание файла клиента прямо в программе.
- // }
- // else
- // {
- // success = false;
- // cout << "Введите правильный id и попробуйте еще раз.\n";
- // system("pause");
- // system("cls");
- // system("color 0E");
- // system("title Bank Simulator 2016");
- // }
- //}
- if (file.eof())
- {
- success = false;
- system("color 4c");
- system("title ERROR - Bank Simulator 2016");
- cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"balance\"]\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- file >> balance;
- if (file.eof())
- {
- success = false;
- system("color 4c");
- cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"overdraft\"]\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- file >> overdraft;
- if (file.eof())
- {
- success = false;
- system("color 4c");
- cout << "E: Файл " << "BankSimId_" + id + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"percent\"]\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- file >> percent;
- if (success)
- {
- success = true;
- system("color 2a");
- cout << "I: Чтение из файла \"" << "BankSimId_" + id + ".txt" << "\" выполнено.\n";
- system("pause");
- system("cls");
- system("color 0E");
- }
- file.close();
- }
- ~Account()
- {
- }
- long double getBalance() { return balance; }
- long double getOverdraft() { return overdraft; }
- long double getPercent() { return percent; }
- string getId() { return id; }
- };
- class Client
- {
- private:
- string name, surname;
- Account account;
- public:
- Client(string ids) :account(ids)
- {
- ifstream file("BankSimId_" + ids + ".txt");
- if (file.fail())
- {
- string isCreate = "n";
- system("color 4c");
- system("title ERROR - Bank Simulator 2016");
- cout << "E: Файл \"" << "BankSimId_" + ids + ".txt" << "\" не существует.\nСоздать? (y/n)\n>> ";
- getline(cin, isCreate);
- if (isCreate == "y" || isCreate == "Y")
- {
- system("color 0E");
- system("title Bank Simulator 2016");
- cout << "Создание нового файла клиента.\n";
- // TODO: Создание файла клиента прямо в программе.
- }
- else
- {
- success = false;
- cout << "Введите правильный id и попробуйте еще раз.\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- }
- if (file.eof())
- {
- success = false;
- system("color 4c");
- system("title ERROR - Bank Simulator 2016");
- cout << "E: Файл " << "BankSimId_" + ids + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"surname\"]\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- file >> surname;
- if (file.eof())
- {
- success = false;
- system("color 4c");
- system("title ERROR - Bank Simulator 2016");
- cout << "E: Файл " << "BankSimId_" + ids + ".txt" << " поврежден.\n[Ошибка \"EndOfFile\" при чтении \"name\"]\n";
- system("pause");
- system("cls");
- system("color 0E");
- system("title Bank Simulator 2016");
- }
- file >> name;
- file.close();
- }
- ~Client()
- {
- if (success)
- {
- ofstream file("BankSimId_" + account.getId() + ".txt");
- cout << "I: Запись в файл \"" << "BankSimId_" + account.getId() + ".txt" << "\"...\n";
- file << surname << " " << name << " " << account.getBalance() << " " << account.getOverdraft() << " " << account.getPercent();
- if (file.fail())
- {
- system("color 4c");
- system("title ERROR - Bank Simulator 2016");
- cout << "E: Ошибка при записи в файл, выход...\n";
- }
- else
- {
- system("color 2a");
- cout << "I: Запись выполнена, выход...\n";
- }
- system("pause");
- }
- }
- string getName() { return name; }
- string getSurname() { return surname; }
- };
- int main()
- {
- setlocale(0, "");
- system("color 0E");
- system("title Bank Simulator 2016");
- Client client("dfa2fsfe");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment