Created
November 23, 2020 08:57
-
-
Save nahiyan/7c51fb1ad3fc311c7171bc592972264c to your computer and use it in GitHub Desktop.
Quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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