CS 220 01/Zelle Winter 2020

OOP and Intro Data Structures

Assignments

Read Sections 1.1, 1.2

Elapsed Days functions (due 1/13)

You should try your hand at implementing these functions, which will be useful for the elapsed days problem that we are tackling in class.

	 def make_date(datestring):
	     """ Convert string to date.
	         datestr is a date in month/day/year form (e.g. "1/10/2019").
	         Returns 3 ints: day, month, and year, representing the date.
	     """
	 
	 def days_in_year(year):
	     """
	         Calculate days in year.
	         year is an int. 
	         Returns the number of days in year.
              """


	 def is_leap_year(year):
	     """
	         Determine whether year is a leap year
                 year is an int.
	         Returns a Boolean indicating leap year status of year
	     """
	 

Note: You will not be handing in this code yet, but I will ask for volunteers to put some code on the boards for us to discuss.

Elapsed Days program (due 1/20, midnight)

Implement and test the complete elapsed days program that we have been designing in class. The input to the program is two dates entered by the user. The output is the total elapsed days between the two dates. Here are the rest of the function specifications from our design:

	    def days_in_month(month):
	        """
	            Calculate number of days in month.
	            month is an int in range(1, 13) representing a month number.
	            Returns the number of days in the month in a non-leap year.
	        """

	    def day_number(date):
	        """
	           Calculate the ordinal day number of the date
	           date is a triple of ints (day, month, year) representing a date.
	           Returns an int in range(1, 367) that corresponds to the ordinal
	               position of date in year. For example, January 1st produces 1, 
	               and December 31 produces 365 or366, depending on whether it 
                       is a leap year or not.
	        """

	    def elapsed_days(start_date, end_date):
	        """
	           Calculate number of days between start_ and end_date.
	           Both parameters are triples of ints (day, month, year).
	           Returns an int, which is the elapsed time in days.
	        """
	  

You have considerable latitude in how to implement each function in this design, including your main program, but you must implement the 6 functions as specified. If you have any questions about the design, ask for clarification.

You should strive to adhere to the guidelines for good program design that you learned in CS 120. Use descriptive variable names, good explanations/prompts for your users, and readable code layout. Use functions to avoid code duplication, and be sure to include descriptions of the functions as docstrings (see specifications above for help with that). You do not need to express these descriptions as pre- and post- conditions (ala Section 1.2 of our tetbook), but you certainly may do that if you want to.

(due 1/17, classtime) pre-post homework

Finish the functions in from the prepost.py file that is posted under handouts. Once you think you have correctly implemented the functions, test them using the program fractal.py also available in the handouts/prepost folder. Then turn in a written report detailing:

Your report is due at the beginning of Friday's class.

(due 1/22) Chapter 1 revew (part 1)

Do Chapter 1 Review Exercises (p 33): T/F 1--5, Multiple Choice 1--3.
have these on-paper suitable for hand-in at the start of class.

(due 1/29) wavefns.py and tonelib.py

Complete and test the implementation of the functions in wavefns.py and tonelib.py from the handouts/tonelib folder. The standard waveforms should look like this.

You will have to test your tonelib functions "by ear."

(due 1/31) Chapter 1 Review (part 2)

Finish reading Chapter 1 and do Chapter 1 Review Exercises (p 33): T/F 6--10, Multiple Choice 4--10.
have these on-paper suitable for hand-in at the start of class.

(due 2/5) Read Chapter 2

(due 2/7) piano.py modifications

This is the second part of the pianolab. We will handle this in class on 2-7, so don't be concerned about that link on Socrates :-).

(due 2/12) Chapter 2 Review Questions

Answer the T/F and multiple choice questions at the end of Chapter 2. Have your answers on paper suitable for hand-in at the start of class.

(due 2/14) Rational Lab

Complete the Rational.py and test_Rational.py classes such that all Rationals are stored in simplified form (reduced with positive denominator) and implement addition and subtraction. We will spend some time in class on 2/12 working on this.

(due 2/14) Chapter 3 Reading

Read 3.1--3.3.

(due 2/21, midnight) soundwave.py

You are to write a SoundWave class as discussed in class. The basic idea is to encapsulate our list of audio samples in a class so that we can add operations that are useful for creating and playing sounds.

Rather than working from detailed specifications, for this project you will be working from a file of testing code that exercises the various features of the SoundWave class. You can find the test file here. Most of that file has been "commented out" by putting it in triple quotes. You should work on getting the tests to work one at a time. Once you get a test working, move the triple quote down below the next test, and get it working.

(due 2/24) read section 3.6 -- dictionaries

Read the first part of the optional section of Chapter 3. You may safely skip the extended Markov chain example.

(due 2/24) keys and frequencies

Read this wikipedia page: Piano Key Frequencies.

(due 2/28) synth.py

Complete the synth.py file to pass the tests in testsynth.py. Note: you will have to listen to the files that are created by the tests to determine whether they all "passed." You can find the see files here.