Beginner Programming Challenge 13
Beginner Programming Challenge #13
Welcome to the 13th Beginner Programming Challenge!
Hi fora, as the winner of the last beginner programming challenge, I am pleased to present the next challenge.
For the next challenge, let's make a simple banking program that will take the following as input:
transaction_code account_number amount
The transaction codes will be as follows:
wd - withdrawal [money taken out of the account]
dep - deposit [money put into the account]
cred - not what you think it is: [money taken out of the account] YES: this is a withdrawal
deb - not what you think it is: [money put into the account] YES: this is a deposit
fee - this is money taken out of the account, but not given to the accountholder. Although basically a withdrawal, this is the only code that allows a withdrawal if it makes the balance less than zero OR if the balance is already less than or equal to zero.
OK, the program will accept as input in the above-named format and make a record of account numbers and the respective balances. The account can NEVER go negative [from the account-holder's perspective] EXCEPT in the case of a fee. In the event of an "overdraft", the withdrawal/credit will NOT be processed, but a fee will be assessed.
Here's the challenging part: NO existing database or existing hashing sequence can be used. Hint: I would recommend using a hashing technique, but as long as an existing database/MySQL method isn't used, I will allow any implementation.
To simplify what I mean here: the programmer should make everything here from scratch except the container for the data and/or the method of resizing the array. Or in other words. Some languages have an "insert" or "append" entry for arrays. C has remalloc. These are both acceptable or *anything* comparable. If a sort or search method is used, you must make this from scratch. If there is a list.search... you can't use it.
EXTRA CREDIT REQUIREMENTS ONLY: If you want extra credit, make your table with a max number of entries so that your overall array can not be a) resizeable b) greater than xx% greater than the maximum number of entries. At the point that you start using malloc and resize, you would have to sort or redo the whole hash table, which is very inefficient. So, to simplify the task, we'll just set a maximum number of entries at 200. That would make the array's maximum size of 200+200*.xx. Want more credit: find out what the minimal percentage is that still allows an efficient hash search/recall routine.
Please note: regardless of implementation, it will need to accommodate 200 account numbers.
I will submit a file that will contain sample entries. The bank program won't "open" the file, but the file will be redirected as the std input. This file may contain any number of entries to facilitate making a decisive choice on speed. To clarify, the speed factor is just to encourage people to be wary of the method they choose in storage/retrieval of the account # & balance.
Here is how I will be judging the entries:
1) Readability and appropriate commenting. Following standard code formatting will make your code more readable. Although I have a tendency to comment quite a bit, if you use strategic commenting, you would be surprised how little commenting can actually be useful
2) Elegance of design. While not as obvious, consider how a feature is being implemented to see if there is a better way.
3) Overall program speed. To reward those who do this in a way that maximizes speed. Specifically, use whatever implementation you want, but bear in mind that some methods will mean speed sacrifices.
4) Robustness of design. If the program handles all the above-named things without crashing and is able to handle all exceptions this will look very good.
5) Extra credit.
Extra credit section: I will try to make two files, one that has 100% correct entries [as in no invalid transaction codes] and one that has many transaction codes. The format for all the data will be correct and inviolable [you don't have to worry about getting text for the account number or dollar amount of transaction]. The account number will be a number with no leading zeros. It will also be an integer. Assume whole dollar amounts.
Another extra credit will be to see how small a percentage over the max account numbers you can get while still being able to fulfill the maximum account numbers. Or in other words, it should be possible to fit 200 accounts in a 240 entry table.
This challenge may seem daunting, but once you figure out your hashing routine, the rest of the challenge will be much easier.
Good luck
and p.s. until I get a file uploaded, you can test your program with normal input or make up your own file.
The file will be 3 items wide, separated with a space, the lines will be terminated normally.
An example input file would be
dep 11111 25
wd 11111 22599
wd 11111 -2525
Re: Beginner Programming Challenge 13
Quote:
Originally Posted by
texaswriter
transaction_code account_number amount
The transaction codes will be as follows:
wd - withdrawal [money taken out of the account]
dep - deposit [money put into the account]
cred - not what you think it is: [money taken out of the account]
deb - not what you think it is: [money put into the account]
fee - this is money taken out of the account, but not given to the accountholder.
Nice touch! I see what you did there..... :)
Re: Beginner Programming Challenge 13
Quote:
Here's the challenging part: NO existing database or existing hashing sequence can be used. I would recommend using a hashing technique, but as long as an existing database/method isn't used, I will allow any implementation. To simplify what I mean here: the programmer should make everything here from scratch.
I don't quite understand this. So in Python, lists, tuples and dictionaries cannot be used? Or can they?
Re: Beginner Programming Challenge 13
Quote:
Originally Posted by
bunburya
I don't quite understand this. So in Python, lists, tuples and dictionaries cannot be used? Or can they?
That would be a ridiculous restriction; more likely it bars the use of things like SQL- e.g. "real" databases.
Re: Beginner Programming Challenge 13
bunburya> thanks!!
lisati> Those have built-in capabilities that break that rule. That said, a list by itself or something similar WOULD be fine as long as you never resize it or use built-in functions/libraries to fulfill the challenges laid out.
snova> that is the correct interpretation.
Re: Beginner Programming Challenge 13
Quote:
Originally Posted by
texaswriter
bunburya> thanks!!
lisati> Those have built-in capabilities that break that rule. That said, a list by itself or something similar WOULD be fine as long as you never resize it or use built-in functions/libraries to fulfill the challenges laid out.
snova> that is the correct interpretation.
A list in Python is always resizeable. And does the 'from scratch' bit mean I cant use pickle to write a list to file, which would then mean I have to store it in plain textt and write a parser function?
Bodsda
Re: Beginner Programming Challenge 13
Better to bar certain languages rather than train people to program "badly" in them IMHO.
Also: http://dictionary.reference.com/brow...er%27s+Disease
Quote:
C Programmer's Disease definition:
The tendency of the undisciplined C programmer to set arbitrary but supposedly generous static limits on table sizes (defined, if you're lucky, by constants in header files) rather than taking the trouble to do proper dynamic storage allocation. If an application user later needs to put 68 elements into a table of size 50, the afflicted programmer reasons that he or she can easily reset the table size to 68 (or even as much as 70, to allow for future expansion) and recompile. This gives the programmer the comfortable feeling of having made the effort to satisfy the user's (unreasonable) demands, and often affords the user multiple opportunities to explore the marvellous consequences of fandango on core. In severe cases of the disease, the programmer cannot comprehend why each fix of this kind seems only to further disgruntle the user.
@Bodsda: The collections.deque object can be declared fixed size.
Re: Beginner Programming Challenge 13
I don't get this either; are cred and deb supposed to tell you how much money you've removed and put into the account respectively, or are they dep and wd synonyms?
Re: Beginner Programming Challenge 13
IMO, this isn't a beginner challenge anymore .. Good luck to everyone who's taking part of this.
Re: Beginner Programming Challenge 13
Quote:
Originally Posted by
texaswriter
At the point that you start using malloc and resize, you would have to sort or redo the whole hash table, which is very inefficient.
Wouldn't using a linked-list address this?