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 aftertrue∗ 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
Reviews
There are no reviews yet.