|
| 1 | +#pragma once |
| 2 | +#include<iostream> |
| 3 | +#include<fstream> |
| 4 | +#include<stdlib.h> |
| 5 | +#include<string> |
| 6 | +#include <vector> |
| 7 | +#include <windows.h> |
| 8 | +#include <ctime> |
| 9 | +#include <conio.h> |
| 10 | + |
| 11 | +using namespace std; |
| 12 | +int accountNum, increaments; |
| 13 | +long double balance = 0; |
| 14 | +long double available; |
| 15 | +long double borrow = 0; |
| 16 | +struct accounts { |
| 17 | + |
| 18 | + string name; |
| 19 | + string password; |
| 20 | + double balance; |
| 21 | + double borrowed; |
| 22 | +}; |
| 23 | +//function declaring////////////////////////////////////////// |
| 24 | +void CheckBalance(); |
| 25 | +void Borrow(); |
| 26 | +void Deposit(); |
| 27 | +void Return(); |
| 28 | +void Menu(accounts oldData[]); |
| 29 | +void MainMenu(); |
| 30 | +void outData(accounts oldData[]); |
| 31 | +void inputNewData(accounts data); |
| 32 | +void inputUpgradeData(accounts data[]); |
| 33 | +/////////////////////////////////////////////////////////////// |
| 34 | +//function defintion/////////////////////////////////////////// |
| 35 | +void Menu(accounts oldData[]) { |
| 36 | + char num = '1'; |
| 37 | + while (num != '0') |
| 38 | + { |
| 39 | + system("CLS"); |
| 40 | + cout << "\n 1.Deposit" << endl; |
| 41 | + cout << "\n 2.Borrow money from bank" << endl; |
| 42 | + cout << "\n 3.Return money to bank" << endl << endl; |
| 43 | + cout << "\n If you want to quit from this section please press 0" << endl << endl; |
| 44 | + num = _getch(); |
| 45 | + switch (num) { |
| 46 | + case 49: |
| 47 | + system("CLS"); |
| 48 | + Deposit(); |
| 49 | + oldData[accountNum].balance = ::balance; |
| 50 | + inputUpgradeData(oldData); |
| 51 | + break; |
| 52 | + case 50: |
| 53 | + system("CLS"); |
| 54 | + Borrow(); |
| 55 | + oldData[accountNum].balance = ::balance; |
| 56 | + oldData[accountNum].borrowed = ::borrow; |
| 57 | + inputUpgradeData(oldData); |
| 58 | + break; |
| 59 | + case 51: |
| 60 | + system("CLS"); |
| 61 | + Return(); |
| 62 | + oldData[accountNum].balance = ::balance; |
| 63 | + oldData[accountNum].borrowed = ::borrow; |
| 64 | + inputUpgradeData(oldData); |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | + cout << "\n "; |
| 69 | +} |
| 70 | + |
| 71 | +void CheckBalance() { |
| 72 | + system("CLS"); |
| 73 | + cout << "\n You balance: " << ::balance << "$" << endl << endl; |
| 74 | + cout << "\n "; |
| 75 | + system("pause"); |
| 76 | +} |
| 77 | + |
| 78 | +void Deposit() |
| 79 | +{ |
| 80 | + double money; |
| 81 | + cout << "\n Please enter amount of money - "; |
| 82 | + cin >> money; |
| 83 | + if (money == 0) |
| 84 | + { |
| 85 | + cout << "\n You entered 0 value so now you are redirected to the menu" << endl; |
| 86 | + Sleep(2000); |
| 87 | + } |
| 88 | + else if (money > 0) |
| 89 | + { |
| 90 | + ::balance = ::balance + money; |
| 91 | + |
| 92 | + cout << "\n Please wait for a while, while we are transfering money to your account" << endl; |
| 93 | + Sleep(2000); |
| 94 | + cout << "\n "; |
| 95 | + cout << money << "$ amount of money was added to your balance" << endl << endl; |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + cout << "\n Error!" << endl; |
| 100 | + cout << "\n Please enter valid amount of money!" << endl << endl; |
| 101 | + } |
| 102 | + cout << "\n "; |
| 103 | + system("pause"); |
| 104 | +} |
| 105 | + |
| 106 | +void Borrow() |
| 107 | +{ |
| 108 | + long double borrow; |
| 109 | + cout << "\n In during time in our bank we have " << ::available << "$" << endl; |
| 110 | + cout << "\n How much do you want to borrow?" << endl; |
| 111 | + cout << "\n "; |
| 112 | + cin >> borrow; |
| 113 | + if (borrow == 0) |
| 114 | + { |
| 115 | + cout << "\n You entered 0 value so now you are redirected to the menu" << endl << endl; |
| 116 | + Sleep(2000); |
| 117 | + } |
| 118 | + else if (borrow <= ::available && borrow > 0) |
| 119 | + { |
| 120 | + cout << "\n We can give you such amount of money." << endl; |
| 121 | + cout << "\n Please wait for a while, while we are transfering money to your account" << endl; |
| 122 | + Sleep(3000); |
| 123 | + ::available = ::available - borrow; |
| 124 | + ::balance = ::balance + borrow; |
| 125 | + ::borrow = ::borrow + borrow; |
| 126 | + cout << "\n Money is successfully transfered to your account." << endl << endl; |
| 127 | + } |
| 128 | + else if (::borrow < 0) |
| 129 | + { |
| 130 | + cout << "\n Error!" << endl; |
| 131 | + cout << "\n Please enter valid amount of money!" << endl << endl; |
| 132 | + } |
| 133 | + else { |
| 134 | + cout << "\n We are sorry but we cant give you such amount of money" << endl << endl; |
| 135 | + } |
| 136 | + cout << "\n "; |
| 137 | + system("pause"); |
| 138 | +} |
| 139 | + |
| 140 | +void Return() |
| 141 | +{ |
| 142 | + char choise; |
| 143 | + long double retr; |
| 144 | + if (::borrow > 0) { |
| 145 | + cout << "\n You have borrowed - " << ::borrow << "$" << endl; |
| 146 | + cout << "\n If you want to return some amount of money please press SPACE or press anything to go back to menu." << endl; |
| 147 | + choise = _getch(); |
| 148 | + if (choise == 32) { |
| 149 | + cout << "\n How much do you want to return?" << endl; |
| 150 | + cout << "\n "; |
| 151 | + cin >> retr; |
| 152 | + if (retr == 0) |
| 153 | + { |
| 154 | + cout << "\n You entered 0 value so now you are redirected to the menu" << endl; |
| 155 | + Sleep(2000); |
| 156 | + } |
| 157 | + else if (retr > 0 && retr <= ::borrow) { |
| 158 | + cout << "\n Please wait while we are taking from your account money back." << endl; |
| 159 | + ::borrow = ::borrow - retr; |
| 160 | + ::balance = ::balance - retr; |
| 161 | + ::available = ::available + retr; |
| 162 | + Sleep(3000); |
| 163 | + cout << "\n Money is successfully taken from your account." << endl << endl; |
| 164 | + } |
| 165 | + else |
| 166 | + { |
| 167 | + cout << "\n Error!" << endl; |
| 168 | + cout << "\n Please enter valid amount of money!" << endl << endl; |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + else { |
| 173 | + cout << "\n You haven't borrowed any money from us." << endl << endl; |
| 174 | + } |
| 175 | + cout << "\n "; |
| 176 | + system("pause"); |
| 177 | +} |
| 178 | + |
| 179 | +void outData(accounts oldData[]) { |
| 180 | + ifstream file; |
| 181 | + file.open("data.txt"); |
| 182 | + if (!file.is_open()) { |
| 183 | + cout << "Error\n"; |
| 184 | + |
| 185 | + } |
| 186 | + else { |
| 187 | + //cout << "file is opened\n"; |
| 188 | + string str = ""; |
| 189 | + int i = 0, j = 0; |
| 190 | + string strArr[4]; |
| 191 | + do { |
| 192 | + getline(file, str, '|'); |
| 193 | + if (j < 4) { |
| 194 | + strArr[j] = str; |
| 195 | + j++; |
| 196 | + } |
| 197 | + else { |
| 198 | + oldData[i].name = strArr[0]; |
| 199 | + oldData[i].password = strArr[1]; |
| 200 | + oldData[i].balance = stoi(strArr[2]); |
| 201 | + oldData[i].borrowed = stoi(strArr[3]); |
| 202 | + ::increaments++; |
| 203 | + j = 0; |
| 204 | + strArr[j] = str; |
| 205 | + j++; |
| 206 | + i++; |
| 207 | + } |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + //cout<<str<<"|"; |
| 212 | + }while (!file.eof()); |
| 213 | + } |
| 214 | +} |
| 215 | +void inputNewData(accounts data) { |
| 216 | + ofstream file; |
| 217 | + file.open("data.txt", ofstream::app); |
| 218 | + file << data.name; |
| 219 | + file << "|"; |
| 220 | + file << data.password; |
| 221 | + file << "|"; |
| 222 | + file << data.balance; |
| 223 | + file << "|"; |
| 224 | + file << data.borrowed; |
| 225 | + file << "|"; |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + file.close(); |
| 231 | +} |
| 232 | +void inputUpgradeData(accounts data[]) { |
| 233 | + ofstream file; |
| 234 | + file.open("data.txt"); |
| 235 | + for (int i = 0; i <::increaments; i++) { |
| 236 | + |
| 237 | + file << data[i].name; |
| 238 | + file << "|"; |
| 239 | + file << data[i].password; |
| 240 | + file << "|"; |
| 241 | + file << data[i].balance; |
| 242 | + file << "|"; |
| 243 | + file << data[i].borrowed; |
| 244 | + file << "|"; |
| 245 | + |
| 246 | + } |
| 247 | + |
| 248 | + file.close(); |
| 249 | +} |
0 commit comments