Bank Account

Medium Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining a `BankAccount` class supporting deposit and withdrawal operations, then printing the final balance.

Input Format

Initial balance, deposit amount, and withdrawal amount.

Output Format

Print the final account balance.

Constraints

Initial balance >= 0, valid transactions

Sample Input

1000.0 500.0 200.0

Sample Output

Final Balance: 1300.00

Explanation

Encapsulates account state changes through class methods.

Starter Code

#include <iostream>
#include <iomanip>

class BankAccount {
private:
    double balance;
public:
    void setBalance(double b) { balance = b; }
    void deposit(double amount) {
        // Write your code here
    }
    void withdraw(double amount) {
        // Write your code here
    }
    void display() {
        std::cout << "Final Balance: " << std::fixed << std::setprecision(2) << balance << "n";
    }
};

int main() {
    BankAccount acc;
    double init, dep, wit;
    if (std::cin >> init >> dep >> wit) {
        acc.setBalance(init);
        acc.deposit(dep);
        acc.withdraw(wit);
        acc.display();
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used