Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Account
  6. {
  7.     int id;
  8.     float balance;
  9.     float history[100];
  10.     int transactions;
  11. public:
  12.  
  13.     Account(int newId,float newBalance)
  14.     {
  15.         id=newId;
  16.         balance=newBalance;
  17.         transactions=0;
  18.     }
  19.     float getBalance()
  20.     {
  21.         return balance;
  22.     }
  23.     int getId()
  24.     {
  25.         return id;
  26.     }
  27.     void transaction(float value)
  28.     {
  29.         history[transactions]=value;
  30.         balance+=value;
  31.         transactions++;
  32.     }
  33.     float last()
  34.     {
  35.         return history[transactions-1];
  36.     }
  37.     void showHistory()
  38.     {
  39.         float temp=balance;
  40.         for(int i=transactions;i>0;i--)
  41.         {
  42.             temp=temp-history[i-1];
  43.             cout<<"Transaction number:"<<i<<"   Value transacion:"<<history[i-1]<< "    Balance:"<<temp<<endl;
  44.         }
  45.     }
  46. };
  47.  
  48. int main()
  49. {
  50.     Account account(100,1000);
  51.     account.transaction(1);
  52.     account.transaction(2);
  53.     account.transaction(3);
  54.     account.transaction(4);
  55.     account.transaction(5);
  56.     account.transaction(6);
  57.     account.showHistory();
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement