Skip to content

Instantly share code, notes, and snippets.

@nahiyan
Created November 23, 2020 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahiyan/7c51fb1ad3fc311c7171bc592972264c to your computer and use it in GitHub Desktop.
Save nahiyan/7c51fb1ad3fc311c7171bc592972264c to your computer and use it in GitHub Desktop.
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