🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

c++ can be used for making large-scale programs and applications. It is used for developing operating systems,game -programming,software engineering and much more.
c++ programs
c++ code for a simple banking system
#include <iostream>
#include <vector>
#include <string>
class Account {
private:
int accountNumber;
std::string accountHolder;
double balance;
public:
Account(int number, const std::string& holder, double initialBalance)
: accountNumber(number), accountHolder(holder), balance(initialBalance) {}
int getAccountNumber() const {
return accountNumber;
}
std::string getAccountHolder() const {
return accountHolder;
}
double getBalance() const {
return balance;
}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
std::cout << "Deposited $" << amount << " into account " << accountNumber << ".\n";
} else {
std::cout << "Invalid deposit amount.\n";
}
}
void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
std::cout << "Withdrawn $" << amount << " from account " << accountNumber << ".\n";
} else {
std::cout << "Invalid withdrawal amount or insufficient funds.\n";
}
}
};
class Bank {
private:
std::vector<Account> accounts;
int nextAccountNumber;
public:
Bank() : nextAccountNumber(1) {}
void createAccount(const std::string& holder, double initialBalance) {
Account newAccount(nextAccountNumber++, holder, initialBalance);
accounts.push_back(newAccount);
std::cout << "Account created successfully. Account number: " << newAccount.getAccountNumber() << "\n";
}
void deposit(int accountNumber, double amount) {
for (auto& account : accounts) {
if (account.getAccountNumber() == accountNumber) {
account.deposit(amount);
return;
}
}
std::cout << "Account not found.\n";
}
void withdraw(int accountNumber, double amount) {
for (auto& account : accounts) {
if (account.getAccountNumber() == accountNumber) {
account.withdraw(amount);
return;
}
}
std::cout << "Account not found.\n";
}
void displayBalance(int accountNumber) {
for (const auto& account : accounts) {
if (account.getAccountNumber() == accountNumber) {
std::cout << "Account " << accountNumber << " balance: $" << account.getBalance() << "\n";
return;
}
}
std::cout << "Account not found.\n";
}
};
int main() {
Bank bank;
// Create accounts
bank.createAccount("John Doe", 1000.0);
bank.createAccount("Jane Smith", 500.0);
// Perform transactions
bank.deposit(1, 200.0);
bank.withdraw(2, 100.0);
bank.displayBalance(1);
bank.displayBalance(2);
return 0;
Comments
Post a Comment