Skip to content

Instantly share code, notes, and snippets.

@nahiyan
Created Nov 23, 2020
Embed
What would you like to do?
Quiz
#include "Account.h"
#include <cstdio>
Account::Account(string name, int age)
{
this->name = name;
this->age = age;
this->balance = 0;
}
void Account::printAll()
{
printf("Name: %s\nAge: %d\nBalance: %f\n\n", this->name.c_str(), this->age, this->balance);
}
void Account::deposit(float amount)
{
this->balance += amount;
}
void Account::withdraw(float amount)
{
if (this->balance >= amount)
this->balance -= amount;
}
#include <string>
using namespace std;
class Account
{
private:
string name;
int age;
float balance;
public:
Account(string, int);
void printAll();
void deposit(float);
void withdraw(float);
};
#include "Account.h"
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main()
{
// Take input
printf("Enter name and age: ");
string name;
int age;
cin >> name >> age;
// Print all the details
Account account(name, age);
account.printAll();
// Transactions
account.deposit(5000);
account.withdraw(2500);
account.printAll();
account.withdraw(2600);
account.printAll();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment