Skip to content

Commit

Permalink
Update file associations in VSCode settings.json + allowed for large…
Browse files Browse the repository at this point in the history
…r integers to be inputted rather than being told it was invalid
  • Loading branch information
tylerlight071 committed May 27, 2024
1 parent 1019fb5 commit 3add992
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 32 deletions.
51 changes: 50 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
95 changes: 64 additions & 31 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <fstream>
#include <cctype>
#include <iomanip>
#include <limits> // For numeric limits
#include <limits>

using namespace std;

Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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<streamsize>::max(), '\n');
Expand All @@ -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.";
Expand All @@ -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<char *>(&ac), sizeof(account));
if (!outFile) {
if (!outFile)
{
cout << "Error: Failed to write account to file." << endl;
}
outFile.close();
Expand Down Expand Up @@ -285,7 +300,8 @@ void modify_account(int n)
while (!File.eof() && !found)
{
File.read(reinterpret_cast<char *>(&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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -327,17 +344,21 @@ void delete_account(int n)
{
outFile.write(reinterpret_cast<char *>(&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");
}
Expand Down Expand Up @@ -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);
Expand All @@ -381,35 +403,42 @@ void deposit_withdraw(int n, int option)
while (!File.eof() && !found)
{
File.read(reinterpret_cast<char *>(&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();
if (option == 1)
{
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<streamsize>::max(), '\n');
}
ac.dep(amt);
ac.dep(static_cast<int>(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<streamsize>::max(), '\n');
}
int bal = ac.retdeposit() - amt;
int bal = ac.retdeposit() - static_cast<int>(amt);
if ((bal < 500 && ac.rettype() == 'S') || (bal < 1000 && ac.rettype() == 'C'))
cout << "Insufficient balance";
else
ac.draw(amt);
{
ac.draw(static_cast<int>(amt));
transaction_successful = true;
}
}
int pos = static_cast<int>(File.tellg()) - sizeof(account);
File.seekp(pos, ios::beg);
Expand All @@ -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
Expand Down

0 comments on commit 3add992

Please sign in to comment.