Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #include <string>
- #include <time.h>
- #include <cmath>
- #include <cstdlib>
- using namespace std;
- typedef struct {
- string number = "";
- string surname = "";
- string firstname = "";
- double maxDebit = 0;
- int maxTransAmount = 0;
- double balance = 0;
- string dateUpdated = "";
- string timeUpdated = "";
- } Account;
- typedef struct {
- string number;
- double amount;
- string date;
- string time;
- int ATMnumber;
- }Transaction;
- void create_account_file(Account* accounts, int count) {
- ofstream file("account.txt", ios::app);
- for (int i = 0; i < count; i++) {
- file << accounts[i].number.c_str() << '\t' << accounts[i].surname.c_str() << '\t' << accounts[i].firstname.c_str() << '\t' << accounts[i].maxDebit << '\t'
- << accounts[i].maxTransAmount << '\t' << accounts[i].balance << '\t' << accounts[i].dateUpdated.c_str() << '\t' << accounts[i].timeUpdated.c_str() << '\n';
- }
- file.close();
- }
- void create_transaction_file(Transaction* transactions, int count) {
- ofstream file("transaction.txt", ios::app);
- for (int i = 0; i < count; i++) {
- file << transactions[i].number << '\t' << transactions[i].amount << '\t' << transactions[i].date << '\t' << transactions[i].time << '\t' << transactions[i].ATMnumber << '\n';
- }
- file.close();
- }
- string get_date()
- {
- time_t rawtime;
- struct tm * timeinfo;
- char buffer[80];
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(buffer, sizeof(buffer), "%d-%m-%Y", timeinfo);
- string str(buffer);
- return str;
- }
- string get_time()
- {
- time_t rawtime;
- struct tm * timeinfo;
- char buffer[80];
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(buffer, sizeof(buffer), "%I:%M:%S", timeinfo);
- string str(buffer);
- return str;
- }
- void update_account(Account* account, Transaction* transaction){
- fstream transactions_file("transaction.txt",ios::in);
- fstream accounts_file("account.txt",ios::in);
- fstream temp_file("temp.txt",ios::out);
- fstream debit("debety.txt",ios::out);
- fstream limit("limity.txt",ios::out);
- while(
- accounts_file>>account->number
- >>account->surname
- >>account->firstname
- >>account->maxDebit
- >>account->maxTransAmount
- >>account->balance
- >>account->dateUpdated
- >>account->timeUpdated
- )
- {
- if (account->number == transaction->number){
- if (account->maxTransAmount < transaction->amount){
- limit<<transaction->number<<"\t"
- <<transaction->amount<<"\t"
- <<transaction->date<<"\t"
- <<transaction->time<<"\t"
- <<transaction->ATMnumber<<"\n";
- }
- else if (account->balance + account->maxDebit < transaction->amount){
- debit<<transaction->number<<"\t"
- <<transaction->amount<<"\t"
- <<transaction->date<<"\t"
- <<transaction->time<<"\t"
- <<transaction->ATMnumber<<"\n";
- }
- else{
- temp_file<<account->number<<"\t"
- <<account->surname<<"\t"
- <<account->firstname<<"\t"
- <<account->maxDebit<<"\t"
- <<account->maxTransAmount<<"\t"
- <<(account->balance = account->balance - transaction->amount)<<"\t"
- <<(account->dateUpdated = transaction->date)<<"\t"
- <<(account->timeUpdated = transaction->time)<<"\n";
- }
- }
- else{
- temp_file<<account->number<<"\t"
- <<account->surname<<"\t"
- <<account->firstname<<"\t"
- <<account->maxDebit<<"\t"
- <<account->maxTransAmount<<"\t"
- <<account->balance<<"\t"
- <<account->dateUpdated<<"\t"
- <<account->timeUpdated<<"\n";
- }
- }
- temp_file.close();
- accounts_file.close();
- temp_file.open("temp.txt",ios::in);
- accounts_file.open("account.txt",ios::out);
- while(
- temp_file>>account->number
- >>account->surname
- >>account->firstname
- >>account->maxDebit
- >>account->maxTransAmount
- >>account->balance
- >>account->dateUpdated
- >>account->timeUpdated)
- {
- accounts_file<<account->number<<"\t";
- accounts_file<<account->surname<<"\t";
- accounts_file<<account->firstname<<"\t";
- accounts_file<<account->maxDebit<<"\t";
- accounts_file<<account->maxTransAmount<<"\t";
- accounts_file<<account->balance<<"\t";
- accounts_file<<account->dateUpdated<<"\t";
- accounts_file<<account->timeUpdated<<"\n";
- }
- transactions_file.close();
- accounts_file.close();
- temp_file.close();
- debit.close();
- limit.close();
- }
- void create_an_account() {
- system("cls");
- Account* account = new Account;
- cout << "Account number: ";
- cin >> account->number;
- cout << "Surname: ";
- cin >> account->surname;
- cout << "First name: ";
- cin >> account->firstname;
- cout << "Maximal debit: ";
- cin >> account->maxDebit;
- cout << "Maximal transaction amount: ";
- cin >> account->maxTransAmount;
- cout << "Account balance: ";
- cin >> account->balance;
- account->dateUpdated = get_date();
- account->timeUpdated = get_time();
- create_account_file(account, 1);
- delete account;
- }
- void make_a_transaction() {
- system("cls");
- Transaction* transaction = new Transaction;
- Account* account = new Account;
- cout << "Account number: ";
- cin >> transaction->number;
- cout << "Transaction amount: ";
- cin >> transaction->amount;
- transaction->date = get_date();
- transaction->time = get_time();
- cout << "ATM number: ";
- cin >> transaction->ATMnumber;
- system("Pause");
- create_transaction_file(transaction, 1);
- update_account(account, transaction);
- delete transaction;
- }
- bool menu() {
- system("cls");
- cout << "MENU" << endl << "1. Create an account" << endl << "2. Make a transaction" << endl << "3. Exit" << endl;
- int option;
- cin >> option;
- switch (option) {
- case 1: {
- create_an_account();
- break;
- }
- case 2: {
- make_a_transaction();
- break;
- }
- case 3: {
- return true;
- break;
- }
- }
- return false;
- }
- int main() {
- while (menu() == false){
- menu();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement