New DOCX Document
New DOCX Document
//would be better to make a system that displays all accounts for verification
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
struct Account {
string accountNumber;
string accountHolderName;
string password;
double balance;
string accountType;
double interestRate;//Annual interest rate in percentage
time_t lastInterestApplied;//Timestamp of when interest was last applied
};
// Function prototypes
void createAccount(vector<Account> &accounts);
/*std::vector is a container from the C++ Standard Library (defined in the <vector> header).
It represents a dynamic array, meaning it can grow or shrink in size as needed during runtime.
Unlike a traditional array, which has a fixed size, a vector can change its size
by adding or removing elements dynamically. It handles memory management internally.*/
/*<Account> - In your code, Account is a structure (or class) that represents a bank account,
containing fields like accountNumber, balance, accountType, etc.*/
/* & accounts - you are passing the vector by reference. This means that the function
will work with the original vector, not a copy of it. Any changes made to accounts
within the function will directly affect the original vector outside the function.
Without & (passing by value): The function works with a copy of the vector,
so changes inside the function don't affect the original vector.*/
int main() {
vector<Account> accounts;
/*vector<Account> means a vector (dynamic array) where each element is of type Account.
accounts is the name of the variable that holds the vector.*/
int choice;
do{
cout<< "\n - - - Bank System Menu - - - \n\n";
cout<<"1. Create Account\n2. Get Customer List\n3. Login\n4. Exit\n\nEnter your choice: \n";
cin>>choice;
switch(choice) {
case 1:{
createAccount(accounts);
break;
}
case 2:{
getCustomerList(accounts);
break;
}
case 3:{
int index=login(accounts);
if (index != -1){
Account ¤tAccount = accounts[index];
int subChoice;
do{
cout<<"\n - - - Account Menu - - - \n";
cout<<"1. Check Balance\n2. Deposit Money\n3. Withdraw Money\n4. Transfer Money\
n5. Apply Interest\n6. Logout\n\nEnter your choice: \n";
cin>>subChoice;
switch (subChoice){
case 1:
checkBalance(currentAccount);
break;
case 2:
depositMoney(currentAccount);
break;
case 3:
withdrawMoney(currentAccount);
break;
case 4:
transferMoney(accounts, currentAccount);
break;
case 5:
applyInterest(currentAccount);
break;
case 6:
cout<<"Logging out . . .\n";
break;
default:
cout<<"Invalid choice. Try again."<<endl;
else{
cout<<"Invalid account number or password."<<endl;
}
break;
}
case 4:
cout<< "Exiting the program. Thank you!\n";
break;
default:
cout<<"Invalid choice. Try again."<<endl;
return 0;
}
cout<<"Please Enter Your Name (It is recommended if you enter till your grandfather's name)\n";
getline(cin, newAccount.accountHolderName);
while (true){
cout << "\nYou have created a new account successfully.\n";
cout << "1. Return to Home Page\n2. Exit\nEnter your choice: ";
int choice;
cin >> choice;
if (choice == 1) {
return; // Return to the home page (caller function handles this)
} else if (choice == 2) {
exit(0); // Exit the program
} else {
cout << "Invalid choice. Please try again.\n";
}
}
}
void getCustomerList(const vector<Account> &accounts) {
if (accounts.empty()) {
cout << "\nNo customers registered yet.\n\n";
return;
}
cout << "\n**********************************\n\n";
cout << "*** Customer List ***\n\n";
cout << "**********************************\n\n";
}
int login(const vector<Account> &accounts){
if (monthsElapsed>=1){
for(int i=0; i<monthsElapsed; i++){
double monthlyInterestRate = account.interestRate / (12 * 100);
account.balance += account.balance * monthlyInterestRate;
}
account.lastInterestApplied = currentTime;
cout<<"The Interest is applied successfully! Your New balance is: "<<account.balance<<"
Birr"<<endl;
}
else {
cout<<"Not enough time has passed to apply interest."<<endl;
}
}