Due: Monday, August 7 by 1pm (not 6pm as has been usual). This earlier time allows us to start doing review meetings Monday afternoon.
There is one set of problems for everyone on this assignment. However, the second segment of programming problems (labeled below) is directed at those aiming for As in the course. If you are not trying to get an A, you can focus on the first set of programming problems and skip the second.
Collaboration Policy: You must do this assignment on your own. Include a collaboration statement attesting to this.
Put your answers to this in a text file called tracing.txt
Here is part of a program for managing orders in an online store. There is a class for the Items for sale, as well as a catalog of all items. There is a tuple for Orders, which capture the name of a customer and a list of items that the customer wants to buy. There are also two versions of a function to update the price of an item in the catalog.
At the bottom of the file is a sequence of expressions to evaluate. There are four comments in the code marked Memory point. Show the contents of memory (environment and store) at each of these four points.
You can write these in a text file or draw (and scan to PDF) pictures of memory drawn on paper. Just make the information for each memory point is clearly labeled so we see which memory layout goes with each point.
Put your answers to this in a text file called scheduling.txt
A university wants to set up data structures and programs to manage how students enroll for courses. There is a master catalog that contains the course names(numbers), and descriptions for all approved courses. Separately, there is a schedule for each semester that indicates which courses are being offered and at what times. You may assume that all offered courses are part of the catalog.
In addition to the schedule of offered classes, individual students also have their personal schedules. A student’s personal schedule consists of a collection of 3-5 courses, none of which should be meeting at the same time.
Answer the following questions about how you would design the data structures, choose concrete data types, and design key functions in a Python program to implement the scheduling system. (Don’t write any actual code for this – this is a conceptual exercise, not a coding one.)
Consider the time at which courses are offered. The university may need to change the time when a particular course is offered after the schedule is created. In light of this should times be a Tuple or a Class? Which of these could you use? Which do you think is better? Justify your answers in a couple of sentences.
Assume that every student takes four courses every semester, and that students may change which courses they are taking until a couple of days into the semester. In light of this, should a student’s schedule be a class, a tuple, a list, or a dictionary? Briefly defend your choice, including options that you ruled out. (It is okay to rate multiple options as acceptable, as long as your answers explain the tradeoffs between the options – my goal here is to see how well you understand these different data structures.)
The problem statement said that students cannot be registered for multiple courses that meet at the same time. Imagine that you were writing functions to let students add and drop courses (from their personal schedules), and to let the university change the times of courses. Your function to add courses raises an error if students add a course whose time conflicts with an existing course. Is this enough to avoid time clashes? Either justify that it is or give a couple of sentences explaining what else your code would need to do.
Your overall goal is to write several programs that handle basic operations at a bank. The bank offers both checking accounts and savings accounts. Each type of account has a (unique) id number, the name of the customer who owns the account, and the current balance. In addition, savings accounts have an interest rate (a float, like .01 for 1% – use .01 as the default/initial interest rate). Checking accounts are limited to three withdrawals per month, so these accounts also track how many withdrawals remain (for the given month).
Create classes, tuples, variables, etc as needed for managing accounts, then write the following programs:
open_account, which takes the type of account to open (either "checking" or "savings"), the name of the customer who wants the account, and the initial balance for the account (a float). As long as the initial deposit is not negative, the function returns a new account of the given type that contains the given data, as well as an id number that has not yet been assigned to any other account opened through this function. Raise an error if the initial balance is negative.
deposit, which takes the id of the account to deposit into and the amt to deposit (a float) and adds the given amount to the account balance as long as the deposit amount is positive. Raise an error if the deposit amount is not positive.
withdraw, which takes the id of the account to withdraw from and the amt to withdraw (a float) and deducts the given amount from the account balance as long as the balance is at least as large as the withdraw amount. For checking accounts, the number of withdrawals should also decrease by 1. Raise an error if the withdraw amount is larger than the balance.
new_month, which takes your data structure for a collection of accounts and adjusts each one for the start of a new month. Checking accounts get their number of allowed withdrawals reset to 3. Savings accounts get their balances increased by the interest rate.
This next part is for those aiming for As in the course
Now that the basic banking features are working, the bank manager asks you to add a way to remember the history of transactions (operations) made on accounts. The manager wants your code to remember every account creation, deposit, and withdrawal action that was taken. The bank wants to use this information for two purposes: first, to let account holders see a history of their transactions, and second, to let the bank create reports on activity across all of the accounts.
Extend your existing data structures as needed to track transactions on accounts. You get to decide where to put this information, what data structure/data type to use, etc. Write a few sentences justifying your choices.
Provide a function account_history, which takes an account id and returns a list of all transactions on the account, from most recent to least recent.
Provide a function total_deposits, which returns the total (sum) of all deposits made at the bank over all time (across all accounts).
Get your solutions to the first set of programming problems done and working before you add the transactions histories. This way, if you don’t get transactions histories done, you still have a solid piece of work to bring to your review meeting. You may want to save a copy of your work on the initial programming problems as a separate Python file in your project (not required).
As the final assignment, this is your chance to pull together what you have learned about data structures, coding, organizing code (into helpers), and testing. We’ll be looking at all of these when we do your in-person review of this project.
If you’ve been struggling in the course, we’ll focus on the basic banking functions in your review rather than the transactions history. You can pass the course/assignment without doing the transactions histories, but those aiming for As should do the transactions histories as well.
Submit a zip file with your files from this assignment. Your Pycharm project can be a separate zip within this overall zip.