In this homework you are a programmer and your supervisors want certain features in their Bank system. Your task is to implement Transaction, Account and Bank systems that are provided you with a header file(You will not edit header files). As situation requested shiny features of the latest C++ is not available to you. Therefore, you have to be careful with your programs memory management.
1Β Β Β Β Β Β Β Β Β Β Β Β Class Definitions
1.1Β Β Β Β Β Β Β Β Β Β Transaction
Transaction is the most basic class in this homework. Basically, it holds a certain amount and date of the Transaction.
class Transaction { private :
double _amount;
time_t _date;
public :
/ββ
β Empty constructor β give β1 to everything
β/ Transaction() ;
/ββ
β Constructor
β
| β @param amount The valueΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transaction (Can be
β @param date Transaction date β/ Transaction( double amount, time_t date) ; /ββ β Copy Constructor . β β @param rhs The Transaction to be copied . β/ Transaction( const Transaction& rhs) ; /ββ β Compare two Transaction based on theirΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β date β β @param rhs Compared Transaction |
negative | or | positive ) | |
| β @returnΒ Β Β Β Β Β Β Β Β Β IfΒ Β Β Β Β Β Β Β Β Β Β Β Β Β currentΒ Transaction happened before returnΒ Β Β Β Β Β Β Β true
β elseΒ Β Β Β Β Β Β Β Β Β Β Β Β returnΒ Β Β Β Β Β false β/ bool operator <(const Transaction& rhs) const ; /ββ β Compare two Transaction based on theirΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β date β β @param date Compared date |
the | given | Transaction ββ | |
| β @returnΒ Β Β Β Β Β Β Β Β Β Β Β IfΒ Β Β Β Β Β currentΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transaction happened after
true β elseΒ Β Β Β Β Β Β Β Β Β Β Β Β returnΒ Β Β Β Β Β false |
the | given TransactionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β returnββ | ||
β/ bool operator >(const Transaction& rhs) const ;
/ββ
β Compare a Transaction with a given date
β
β @param date Compared date
β @returnΒ Β Β Β Β Β IfΒ Β Β Β Β Β currentΒ Β Β Β Β Β Β Β Β Β Β Β Β Transaction happened beforeΒ Β Β Β Β the given date returnΒ Β Β Β Β Β Β Β true
β elseΒ Β Β Β Β Β Β returnΒ Β Β Β Β Β Β false
β/ bool operator <(const time_t date) const ;
/ββ
β Compare a Transaction with a given date
β
β @param date Compared date
β @returnΒ Β Β Β Β Β IfΒ Β Β Β Β Β currentΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Transaction happened afterΒ Β Β Β Β the given date returnΒ Β Β Β Β Β Β Β true
β elseΒ Β Β Β Β Β Β returnΒ Β Β Β Β Β Β false
β/ bool operator >(const time_t date) const ;
/ββ
β Sum the valueΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β of two Transaction amounts
β
β @param rhs The transactionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β to sum over
β @return The output ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β the summation in double format
β/ double operator+(const Transaction& rhs) ;
/ββ
β Sum the valueΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β of a Transaction with another double
β
β @param add The amount to sum over
β @return The output ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β the summation in double format
β/ double operator+(const double add) ;
/ββ
β Assignment operator
β
β @param rhs Transaction to assign β @return this Transaction
β/
Transaction& operator=(const Transaction& rhs) ;
/ββ
β Stream overload
β
β What to stream :
β Transaction amountβtabβtabβhour : minute : secondβday/month/year ( inΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β localtime )
β
β @param os Stream to be used .
β @param transactionΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transaction to be streamed .
β @return the current Stream
β/ friend std : : ostream& operator <<(std : : ostream& os, const Transaction& βtransaction) ;
};
1.2Β Β Β Β Β Β Β Β Β Β Account
The account is defined for a single user and users have their respective ids. Accounts also hold Transaction information of their user in a sorted manner.
class Account { private :
int _id;
Transactionββ _activity; intβ _monthly_activity_frequency;
public :
/ββ
β Empty constructor
β give the id as β1 β give nullptr for pointers
β/ Account() ;
/ββ
Constructor
β Note : The givenΒ Β Β Β Β Β Β Β Β Β Β Β activityΒ Β Β Β Β Β Β Β arrayΒ Β Β Β Β Β willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β have 12 Transactionβ
β Each ofΒ Β Β Β Β Β Β Β theseΒ Β Β Β Β Β Β Β Β Β Β Transactionβ willΒ Β Β represent a month from the 2019
β BasicalyΒ Β Β Β Β Β Β Β Β Β Β activity [0] willΒ Β Β Β represent January activity [11]Β Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β represent February activity [11]Β Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β represent March
. . .
activity [10]Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β Β Β Β Β Β represent November activity [11]Β Β Β Β Β Β Β willΒ Β represent December
| β activity [0]Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β Β Β Β Β Β only containΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transactions happened in January
β However , be careful that Transactions inside of activity [ i ] will not be inβsorted order β For Example : We areΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β certainΒ Β Β Β Β Β Β thatΒ Β Β Β Β Β Β Β Β activity [0]Β Β Β Β Β Β Β Β isΒ Β Β Β Β Β Β containingΒ Β Β Β Β Β Β Β Β Β Β Transactions ββ |
|
| happened in January 2019
β But we are not sure which of them happenedΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β f i r s t . |
Β |
| β IΒ Β Β Β stronglyΒ Β Β Β suggest you to use a sortingΒ Β Β Β Β Β Β Β Β Β Β Β algorithmΒ Β Β Β Β Β Β Β Β Β Β Β Β Β while Transaction to your object . | storingΒ Β Β Β Β Β Β Β Β Β Β these ββ |
| β ( Sorting by the date , So that you canΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β directlyΒ Β Β Β Β Β Β Β Β Β Β Β Β use them
) β (You can use bubbleΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β sort ) β β @param idΒ Β Β Β Β Β Β Β Β Β Β idΒ Β Β Β ofΒ Β Β Β Β Β Β Β this Account |
in stream overloadββ |
| β @param activity 2d Transaction array f i r s t layers lenght month | isΒ Β Β Β Β Β Β Β Β Β 12 forΒ Β Β Β Β Β Β each ββ |
| β @param monthly activity frequency how many transactions
β/ |
made in each month |
Account( int id, Transactionββ const activity,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β int β monthly_activity_frequencyββ
) ;
/ββ
β Destructor
β
β Do notΒ Β Β forgetΒ Β Β Β toΒ Β Β Β Β Β Β Β Β Β Β Β Β freeΒ Β Β Β Β Β Β Β Β the space you have created ( This assignment does not βuse smart pointers )
β/
ΛAccount() ;
/ββ
β Copy constructor (Deep copy)
β
β @param other The Account to be copied
β/
Account( const Account& rhs) ;
/ββ
β Copy constructor (Deep copy)
β
β This copy constructorsΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β takes two time tΒ Β Β Β Β Β Β Β Β Β elements
β Transactions of the old Account will be copied to new Account β i f and only i f they are between these given dates β Given dates will not be included .
β
β @param rhs The Account to be copied
β @param start date Starting date for transaction to be copied . β @param end date Ending date for transactions to be copied .
β/
| Account( const Account& rhs, time_t start_date, time_t end_date) ; | ||||
| /ββ
β Move constructor β |
Β | Β | Β | Β |
| β @param rhs Account which you
β/ Account(Account&& rhs) ; /ββ β Move assignment operator β |
will | move the | resources | from |
| β @param rhs Account which you
β @returnΒ Β Β Β Β Β Β Β Β Β Β Β thisΒ Β Β Β Β Β account |
will | move the | resources | from |
β/
Account& operator=(Account&& rhs) ;
/ββ
β Assignment operator β deep copy
β
β @param rhs Account to assign β @return this account
β/ Account& operator=(const Account& rhs) ;
/ββ
β Equality comparison overload
β
β This operatorΒ Β Β Β Β Β Β Β Β Β Β Β Β Β checks only idΒ Β Β Β Β Β Β Β Β ofΒ Β Β Β Β Β Β the Account
β
β @param rhs The Account to compare
β @return returnsΒ Β Β Β Β Β Β Β Β Β trueΒ Β Β Β Β i fΒ Β Β Β Β Β both idsΒ Β Β Β Β Β Β Β Β Β Β are same falseΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β othervise
β/ boolΒ Β Β Β Β operator==(const Account& rhs) const ; /ββ
β Equality comparison overload
β
β This operatorΒ Β Β Β Β Β Β Β Β Β Β Β Β Β checks only idΒ Β Β Β Β Β Β Β Β ofΒ Β Β Β Β Β Β the Account
β
β @param id to compare
β @return returnsΒ Β Β Β Β Β Β Β Β Β trueΒ Β Β Β Β i fΒ Β Β Β Β Β both idsΒ Β Β Β Β Β Β Β Β Β Β are same falseΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β othervise
β/ bool operator==(int id) const ;
/ββ
| β sum and equalΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β operator
β Add TransactionsΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β of two Accounts |
Β | Β | ||
| β You have to add transactionsΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β inΒ Β Β Β Β Β correctΒ Β Β Β Β Β Β placesΒ Β Β Β Β Β Β Β Β Β in your
β Note : Remember that activity [0] is always January and always December β ( This informationΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β alsoΒ Β Β Β Β Β holdsΒ Β Β Β Β forΒ Β Β Β Β Β Β Β Β every other month) β β You can have Transactions with the same date β β @param rhs Account which take new Transactions from β @return this Account after adding new Transactions β/ Account& operator+=(const Account& rhs) ; /ββ β How much money Account has(Sum ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transaction amounts) β β β @returnΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β total amount ofΒ Β Β Β Β Β Β Β Β Β Β Β the money ofΒ Β Β Β Β Β Β Β Β Β the account β/ double balance() ; /ββ β How much money Account has at the end ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β given date β β Given dateΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β Β Β Β Β Β Β not be included . |
activityΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β array | ββ | ||
| activity [11] | is | |||
| β @param end date You will count the amounts until this inclusive )
β @return Total amount the Account hasΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β untilΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β given date β/ double balance(time_t end_date) ; /ββ β How much money Account between given dates β Given dates will not be included . β |
given | date ( not ββ | ||
β @param end date You will count the amounts between given dates (not βinclusive )
β @return Total amount the Account has between givenΒ Β Β Β Β dates
β You will only count a Transaction amount i f and only i f it occured betweenβgiven dates β/ double balance(time_t start_date, time_t end_date) ;
/ββ β Stream overload .
β
β
β
β What to stream
β Id ofΒ Β Β Β Β Β Β Β Β the user
β Earliest Transaction amountβtabβββtabβhour : minute : secondβday/month/year ( inβlocaltime )
β Second earliest Transaction amountβtabβββtabβhour : minute : secondβday/month/βyear ( in localtime ) β . . .
β Latest Transaction amountβtabβtabβhour : minute : secondβday/month/year ( in βlocaltime ) β
β Note : activity array will only contain dates from January 2019 to βDecember 2019
β Note :Β Β Β Β Β Β Β Β Β Β Β Β Β Β Transactions should be inΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β order by date
β Note :Β Β Β Β Β Β Β eitherΒ Β Β Β Β Β ofΒ Β Β Β Β Β Β Β Β Β Β monthly activity frequencyΒ Β Β Β Β Β Β Β Β Β Β orΒ Β Β Β Β Β Β Β activityΒ Β Β Β Β Β Β isΒ Β Β Β Β Β Β Β Β Β Β Β Β nullptr
β you will just stream β β1
β @param os Stream to be used .
β @param Account to be streamed . β @return the current Stream
β/
friend std : : ostream& operator <<(std : : ostream& os,Β Β Β Β Β Β Β Β Β Β Β Β Β Β const Account& account) ;
};
1.3Β Β Β Β Β Β Β Β Β Β Bank
The bank keeps track of accounts.
class Bank { private :
std : : string _bank_name;
int _user_count;
Accountβ _users; public :
/ββ
β Empty constructor
β give the bank name as βnot definedβ
β give nullptr for pointers β give 0 as users count
β/ Bank() ;
/ββ
β Constructor
β
β
β @param bankname name ofΒ Β Β Β Β Β Β Β Β Β Β Β Β this bank
β @param userspointer to hold users of this bank β @param usercount number of users this bank has β/ Bank(std : : string bank_name, Accountβ const users,Β Β Β Β Β Β Β Β int user_count) ;
/ββ
β Destructor
β
β Do notΒ Β Β forgetΒ Β Β Β toΒ Β Β Β Β Β Β Β Β Β Β Β Β freeΒ Β Β Β Β Β Β Β Β the space you have created ( This assignment does not βuse smart pointers )
β/ ΛBank() ;
/ββ
β Copy constructor (Deep copy)
β
β @param rhs The Bank to be copied
β/ Bank( const Bank& rhs) ;
/ββ
β You should deep copy the contentΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β ofΒ Β Β Β Β Β Β Β the second bank
β Merge two banks
β If both banks has a user with the same id , Transactions of these users βwill be merged in to the same Account β For example :
β Bank1 hasΒ Β Β Β Β Β Β Β [1 ,2]Β Β Β Β Β idΒ Β Β Β Β users
β Bank2 hasΒ Β Β Β Β Β Β Β [2 ,3]Β Β Β Β Β idΒ Β Β Β Β users
β
β Bank1 after += operator will have [1 ,2 ,3] id users β User with id 2 will have its transactions histories merged
β
β Transactions with ofΒ Β Β Β Β Β Β Β Β theΒ Β Β Β Β Β Β Β Β Β users with the same id should be merged and βupdated
β @param rhs Merged Bank β @return this Bank
β/
Bank& operator+=(const Bank& rhs) ;
/ββ
β Add a new account to Bank
β
β IfΒ Β Β Β Β Β Β Β Β Β Β Β the newly added userΒ Β Β Β Β Β Β Β Β Β Β Β alreadyΒ Β Β Β Β Β Β existsΒ Β Β Β Β Β inΒ Β Β Β Β Β this Bank merge their ββ
Transactions
β
β @param new acc new account to add to bank
β @returnΒ Β Β Β Β Β Β Β Β this Bank
β/
Bank& operator+=(const Account& new_acc) ;
/ββ IndexingΒ Β Β Β Β Β Β Β Β operatorΒ Β Β Β Β Β Β overload
β
β Return the Account with the givenΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β id
β
β IfΒ Β Β Β Β Β Β thereΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β is no Account with the givenΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β idΒ Β Β Β Β Β Β return theΒ Β Β Β Β Β Β Β Β Β Β Β Β f i r s t element
β
β @param account idΒ Β Β Β Β Β Β Β idΒ Β Β Β ofΒ Β Β Β Β Β Β the Account
β @returnΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β i fΒ Β Β Β Β Β Β Β Β Β Β Β Β givenΒ Β Β Β Β idΒ Β Β Β Β Β Β Β Β Β Β Β Β existΒ Β Β Β Β Β Β in the bank return the account ,Β elseΒ Β Β Β Β Β Β Β Β return the βf i r s tΒ Β Β Β Β Β Β Β Β Β Β Β Β account
β
β/
Account& operator [ ] ( int account_id) ;
/ββ
| β Stream overload .
βΒ Β Β allΒ Β Β Β Β Β Β Β the accountsΒ Β Β Β Β Β Β Β Β willΒ Β Β Β Β Β Β Β Β Β Β Β be between 01β01β2019 and 31β12β2019 β What to stream β bank nameβtabβnumber ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β users who areΒ Β Β Β Β Β Β Β Β Β Β eligibleΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β for a loanβtabβ total ββ |
||||||||
| Β Β Β Β Β Β Β Β Β balanceΒ Β Β Β Β ofΒ Β Β Β Β Β the bank
β |
Β | |||||||
| β A user is safe for a loan i f and only i f that user did not negative balance for 2 or more consecutive months | have any ββ | |||||||
| β For example ,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β let β s say our bank named as βbananaβ has two | users | Β | ||||||
| β | Β | Β | ||||||
| β User Aβ s balanceΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β forΒ Β Β Β Β Β Β Β Β Β Β Β Β each month is
β β January β 0 β February β 0 β March β 100 β April β β20 β May β β30 β June β 40 β July β 60 β August β 0 β September β 0 β October β 0 β November β 0 β December β 0 β |
as | given | Β | Β | ||||
| β This user is not eligible because negative ( consecutive ) | in | April and May his/her | balance | was ββ | ||||
| Β | Β | Β | ||||||
| β You s t i l lΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β have to add 150 to theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β totalΒ Β Β Β Β Β Β Β Β Β Β Β Β balance | ofΒ Β Β Β Β Β the | bank | Β | Β | ||||
| β User Bβ s balanceΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β for
β β January β 0 β February β 0 β March β 100 β April β β20 β May β 40 β June β β30 β July β 60 β August β 0 β September β 0 β October β 0 β November β 0 β December β 0 β |
each month isΒ Β Β Β Β Β Β Β Β Β Β Β Β Β as given | Β | Β | Β | Β | |||
| β This userΒ Β Β Β Β Β Β Β Β Β Β Β Β isΒ Β Β Β Β Β Β Β Β Β Β Β eligible | because | negativeΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β balances | were | not consecutive | ||||
| β You willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β also add 150
β |
to the | totalΒ Β Β Β Β Β Β Β Β balanceΒ Β Β Β Β ofΒ Β Β Β Β Β the bank | ||||||
| β your outputΒ Β Β Β Β Β Β Β Β Β Β Β Β Β willΒ Β Β Β Β Β be as | ||||||||
β bananaΒ Β Β Β Β Β Β Β Β Β 1Β Β Β Β Β Β Β Β Β 300
β/ friend std : : ostream& operator <<(std : : ostream& os,Β Β Β Β Β const Bank& bank) ;
};
2Β Β Β Β Β Β Β Β Β Β Β Β Extras
You have to check for memory leaks in your code. Any memory leak in certain class will result in point reduction.
You can test your code for any memory leak by using valgrind. (Provided MakeFile has valgrind option)
You can also test your implementation by using transaction test.cpp, account test.cpp, bank test.cpp, and compare your results with provided corresponding example *.txt files. (Some text editors might display tab character in a different format. To look at the output in the best way use gedit in Ubuntu,
TextEdit in Mac or just open it with vi)
Note: You can test your classes with (ouputs of these runs also given to you)
$ make transaction
$ make run
$ make valgrind
$ make account
$ make run
$ make valgrind
$ make bank
$ make run $ make valgrind



