Name: hashir khan
Code 1:
Code 2:
Output:
Code 3:
using namespace std;
void createAccount(string &name, int &accountID, double &balance) {
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your account ID: ";
cin >> accountID;
balance = 0.0;
cout << "Account created successfully. Initial balance: $" << balance << endl;
}
void depositMoney(double &balance) {
double amount;
cout << "Enter the amount to deposit: $";
cin >> amount;
if (amount > 0) {
balance += amount;
cout << "Deposit successful. New balance: $" << balance << endl;
} else {
cout << "Invalid deposit amount. Please enter a positive amount." << endl;
}
}
void withdrawMoney(double &balance) {
double amount;
cout << "Enter the amount to withdraw: $";
cin >> amount;
if (amount > 0 && amount <= balance) {
balance -= amount;
cout << "Withdrawal successful. New balance: $" << balance << endl;
} else {
cout << "Insufficient funds or invalid withdrawal amount." << endl;
}
}
void checkBalance(double balance) {
cout << "Your current balance is: $" << balance << endl;
}
int main() {
string name;
int accountID;
double balance = 0.0;
int choice;
while (true) {
cout << "\nBank Account Management System\n";
cout << "1. Create Account\n";
cout << "2. Deposit Money\n";
cout << "3. Withdraw Money\n";
cout << "4. Check Balance\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
createAccount(name, accountID, balance);
break;
case 2:
if (balance > 0) {
depositMoney(balance);
} else {
cout << "Please create an account first." << endl;
}
break;
case 3:
if (balance > 0) {
withdrawMoney(balance);
} else {
cout << "Please create an account first." << endl;
}
break;
case 4:
if (balance > 0) {
checkBalance(balance);
} else {
cout << "Please create an account first." << endl;
exit(0);
default:
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}
}
Code 4:
Output: