Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <cmath>
- #include <cctype>
- using namespace std;
- class Account {
- private:
- double money;
- static int accessCount;
- public:
- Account(){
- //accessCount = 0;
- this->money = 0;
- }
- Account(double money){
- if(money > 0){
- ++accessCount;
- this->money = money;
- } else {
- this->money = 0;
- }
- }
- double in(double money){
- if (money > 0)
- accessCount++;
- //cout << money << " " << this->money << " " << ::money << endl;
- this->money += money;
- return this->money;
- }
- double out(double money){
- double t = min(money, this->money);
- this->money -= t;
- if(t > 0){
- accessCount++;
- }
- return t;
- }
- double get(){
- return money;
- }
- static int getAccessCount(){
- return accessCount;
- }
- void print(){
- cout << "Account: " << money << " EUR " << endl;
- }
- };
- int Account::accessCount = 0;
- int main(){
- Account account1(0);
- account1.print();
- double a1 = account1.in(100);
- cout << "Total " << a1 << endl;
- account1.print();
- double b1 = account1.out(0);
- cout << "Took out " << b1 << endl;
- account1.print();
- cout << "Total " << account1.get() << endl;
- cout << "Total transactions " << Account::getAccessCount() << endl;
- cout << endl << endl;
- Account account2(0);
- account2.print();
- double a2 = account2.in(100);
- cout << "Total " << a2 << endl;
- account2.print();
- double b2 = account2.out(0);
- cout << "Took out " << b2 << endl;
- account2.print();
- cout << "Total " << account2.get() << endl;
- cout << "Total transactions " << Account::getAccessCount() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement