From 3add992370e591946ba43a305b76b3210fecece0 Mon Sep 17 00:00:00 2001 From: Tyler Lightwood Date: Mon, 27 May 2024 20:20:21 +0100 Subject: [PATCH] Update file associations in VSCode settings.json + allowed for larger integers to be inputted rather than being told it was invalid --- .vscode/settings.json | 51 ++++++++++++++++++++++- main.cpp | 95 +++++++++++++++++++++++++++++-------------- 2 files changed, 114 insertions(+), 32 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cba2e6..f2e326b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,54 @@ { "files.associations": { - "iostream": "cpp" + "iostream": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "format": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "istream": "cpp", + "iterator": "cpp", + "locale": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "xfacet": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/main.cpp b/main.cpp index d91de0c..8c3ebef 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include // For numeric limits +#include using namespace std; @@ -28,7 +28,8 @@ class account void account::create_account() { cout << "\nEnter The account No. :"; - while (!(cin >> acno) || acno < 0) { + while (!(cin >> acno) || acno < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -39,13 +40,15 @@ void account::create_account() cout << "\nEnter Type of The account (C/S) : "; cin >> type; type = toupper(type); - while (type != 'C' && type != 'S') { + while (type != 'C' && type != 'S') + { cout << "Invalid input. Please enter 'C' for Current or 'S' for Saving: "; cin >> type; type = toupper(type); } cout << "\nEnter The Initial amount (>=500 for Saving and >=1000 for Current) : "; - while (!(cin >> deposit) || ((type == 'S' && deposit < 500) || (type == 'C' && deposit < 1000))) { + while (!(cin >> deposit) || ((type == 'S' && deposit < 500) || (type == 'C' && deposit < 1000))) + { cout << "Invalid input. Please enter a valid initial amount (>=500 for Saving and >=1000 for Current): "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -70,13 +73,15 @@ void account::modify() cout << "\nModify Type of Account (C/S) : "; cin >> type; type = toupper(type); - while (type != 'C' && type != 'S') { + while (type != 'C' && type != 'S') + { cout << "Invalid input. Please enter 'C' for Current or 'S' for Saving: "; cin >> type; type = toupper(type); } cout << "\nModify Balance amount : "; - while (!(cin >> deposit) || deposit < 0) { + while (!(cin >> deposit) || deposit < 0) + { cout << "Invalid input. Please enter a positive amount: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -85,7 +90,8 @@ void account::modify() void account::dep(int x) { - if (x < 0) { + if (x < 0) + { cout << "Invalid deposit amount. Cannot be negative." << endl; return; } @@ -94,11 +100,13 @@ void account::dep(int x) void account::draw(int x) { - if (x < 0) { + if (x < 0) + { cout << "Invalid withdraw amount. Cannot be negative." << endl; return; } - if (deposit - x < 0) { + if (deposit - x < 0) + { cout << "Insufficient balance." << endl; return; } @@ -163,7 +171,8 @@ int main() break; case '2': cout << "\n\n\tEnter The account No. : "; - while (!(cin >> num) || num < 0) { + while (!(cin >> num) || num < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -173,7 +182,8 @@ int main() break; case '3': cout << "\n\n\tEnter The account No. : "; - while (!(cin >> num) || num < 0) { + while (!(cin >> num) || num < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -183,7 +193,8 @@ int main() break; case '4': cout << "\n\n\tEnter The account No. : "; - while (!(cin >> num) || num < 0) { + while (!(cin >> num) || num < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -195,7 +206,8 @@ int main() break; case '6': cout << "\n\n\tEnter The account No. : "; - while (!(cin >> num) || num < 0) { + while (!(cin >> num) || num < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -205,7 +217,8 @@ int main() break; case '7': cout << "\n\n\tEnter The account No. : "; - while (!(cin >> num) || num < 0) { + while (!(cin >> num) || num < 0) + { cout << "Invalid input. Please enter a positive integer for the account number: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); @@ -214,7 +227,7 @@ int main() cout << "\n\nAccount modified successfully!"; break; case '8': - cout << "\n\n\tThanks for using bank management system"; + cout << "\n\n\tThanks for using Lightwood Bank"; break; default: cout << "\n\n\tInvalid option. Please select a number between 1 and 8."; @@ -231,13 +244,15 @@ void write_account() account ac; ofstream outFile; outFile.open("account.dat", ios::binary | ios::app); - if (!outFile) { + if (!outFile) + { cout << "Error: File could not be opened for writing." << endl; return; } ac.create_account(); outFile.write(reinterpret_cast(&ac), sizeof(account)); - if (!outFile) { + if (!outFile) + { cout << "Error: Failed to write account to file." << endl; } outFile.close(); @@ -285,7 +300,8 @@ void modify_account(int n) while (!File.eof() && !found) { File.read(reinterpret_cast(&ac), sizeof(account)); - if (File.eof()) break; // Break if end of file is reached + if (File.eof()) + break; // Break if end of file is reached if (ac.retacno() == n) { ac.show_account(); @@ -316,7 +332,8 @@ void delete_account(int n) return; } outFile.open("Temp.dat", ios::binary); - if (!outFile) { + if (!outFile) + { cout << "Error: Temporary file could not be opened for writing." << endl; return; } @@ -327,17 +344,21 @@ void delete_account(int n) { outFile.write(reinterpret_cast(&ac), sizeof(account)); } - else { + else + { found = true; } } inFile.close(); outFile.close(); - if (found) { + if (found) + { remove("account.dat"); rename("Temp.dat", "account.dat"); cout << "\n\n\tRecord Deleted .."; - } else { + } + else + { cout << "\n\n\tAccount number does not exist."; remove("Temp.dat"); } @@ -368,8 +389,9 @@ void display_all() // Function to deposit and withdraw amounts void deposit_withdraw(int n, int option) { - int amt; + long long amt; // Use long long to handle larger values bool found = false; + bool transaction_successful = false; // Flag to track if the transaction was successful account ac; fstream File; File.open("account.dat", ios::binary | ios::in | ios::out); @@ -381,7 +403,8 @@ void deposit_withdraw(int n, int option) while (!File.eof() && !found) { File.read(reinterpret_cast(&ac), sizeof(account)); - if (File.eof()) break; // Break if end of file is reached + if (File.eof()) + break; // Break if end of file is reached if (ac.retacno() == n) { ac.show_account(); @@ -389,27 +412,33 @@ void deposit_withdraw(int n, int option) { cout << "\n\n\tTO DEPOSIT AMOUNT "; cout << "\n\nEnter The amount to be deposited: "; - while (!(cin >> amt) || amt < 0) { - cout << "Invalid input. Please enter a positive amount: "; + while (!(cin >> amt) || amt <= 0 || amt > LLONG_MAX) + { + cout << "Invalid input. Please enter a positive amount within the valid range: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); } - ac.dep(amt); + ac.dep(static_cast(amt)); + transaction_successful = true; } if (option == 2) { cout << "\n\n\tTO WITHDRAW AMOUNT "; cout << "\n\nEnter The amount to be withdrawn: "; - while (!(cin >> amt) || amt < 0) { - cout << "Invalid input. Please enter a positive amount: "; + while (!(cin >> amt) || amt <= 0 || amt > LLONG_MAX) + { + cout << "Invalid input. Please enter a positive amount within the valid range: "; cin.clear(); cin.ignore(numeric_limits::max(), '\n'); } - int bal = ac.retdeposit() - amt; + int bal = ac.retdeposit() - static_cast(amt); if ((bal < 500 && ac.rettype() == 'S') || (bal < 1000 && ac.rettype() == 'C')) cout << "Insufficient balance"; else - ac.draw(amt); + { + ac.draw(static_cast(amt)); + transaction_successful = true; + } } int pos = static_cast(File.tellg()) - sizeof(account); File.seekp(pos, ios::beg); @@ -421,6 +450,10 @@ void deposit_withdraw(int n, int option) File.close(); if (!found) cout << "\n\nRecord Not Found "; + else if (transaction_successful && option == 1) + cout << "\n\nAmount deposited successfully!"; + else if (transaction_successful && option == 2) + cout << "\n\nAmount withdrawn successfully!"; } // Introductory function