If you have any query feel free to chat us!
Happy Coding! Happy Learning!
Problem: Write a monolithic program that simulates a simple banking system. The program should allow users to create accounts, deposit and withdraw funds, and check their account balances.
cppCopy code
#include <iostream>
#include <string>
// Structure representing a bank account
struct BankAccount {
std::string accountNumber;
std::string accountHolderName;
double balance;
};
// Function to create a new bank account
void createAccount(BankAccount& account) {
std::cout << "Enter account number: ";
std::cin >> account.accountNumber;
std::cout << "Enter account holder name: ";
std::cin.ignore();
std::getline(std::cin, account.accountHolderName);
std::cout << "Enter initial balance: ";
std::cin >> account.balance;
}
// Function to deposit funds into an account
void deposit(BankAccount& account, double amount) {
account.balance += amount;
std::cout << "Deposit successful.\n";
}
// Function to withdraw funds from an account
void withdraw(BankAccount& account, double amount) {
if (account.balance >= amount) {
account.balance -= amount;
std::cout << "Withdrawal successful.\n";
} else {
std::cout << "Insufficient balance. Withdrawal failed.\n";
}
}
// Function to check the account balance
void checkBalance(const BankAccount& account) {
std::cout << "Account Number: " << account.accountNumber << std::endl;
std::cout << "Account Holder Name: " << account.accountHolderName << std::endl;
std::cout << "Account Balance: " << account.balance << std::endl;
}
int main() {
BankAccount account;
int choice;
double amount;
while (true) {
std::cout << "\n--- Bank System ---\n";
std::cout << "1. Create Account\n";
std::cout << "2. Deposit\n";
std::cout << "3. Withdraw\n";
std::cout << "4. Check Balance\n";
std::cout << "5. Exit\n";
std::cout << "Enter your choice: ";
std::cin >> choice;
switch (choice) {
case 1:
createAccount(account);
break;
case 2:
std::cout << "Enter amount to deposit: ";
std::cin >> amount;
deposit(account, amount);
break;
case 3:
std::cout << "Enter amount to withdraw: ";
std::cin >> amount;
withdraw(account, amount);
break;
case 4:
checkBalance(account);
break;
case 5:
std::cout << "Exiting program...\n";
return 0;
default:
std::cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}
In this example, we implement a monolithic program that simulates a simple banking system. The program defines a BankAccount
structure to represent a bank account with attributes such as account number, account holder name, and balance.
The program includes functions to create an account, deposit funds, withdraw funds, and check the account balance. These functions operate on a BankAccount
object passed as a reference.
In the main
function, a menu-driven loop allows users to choose options such as creating an account, depositing funds, withdrawing funds, checking the balance, or exiting the program.
By running the program, users can interact with the banking system by creating accounts, depositing and withdrawing funds, and checking their balances.
Start the conversation!
Be the first to share your thoughts
Quick answers to common questions about our courses, quizzes, and learning platform