CS 220 01/Zelle Winter 2022

OOP and Intro Data Structures

Assignments

Read Sections 1.1, 1.2

Reminder: Quiz #1 is Friday, 1/14)

The quiz will be over Section 1.1 ("programming in the large") and what we have covered in class (syllabus and Python Review).

(due 1/21) craps.py

Complete the craps simulation that we discussed in class. The input to the program is the number of games of craps to simulate. The output is the number of games won and the winning percentage.

In addition to main, Your program should define the following functions:

	 print_intro()
	 sim_n_games(n)
	 sim_craps()
	 roll_dice()
	 roll_for_point(point_to_make)

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.

Game Rules: The player rolls the pair of dice (called the "come out roll"). If the come out roll is 7 or 11, the player wins. If the come out roll is 2, 3, or 12, the player loses. Any other value becomes the "point value to make". The player then continues to roll the dice until either rolling that point value or 7. If the sequence of rolls ends by rolling the point value, then the player wins. If it ends by rolling a 7, the player loses.

Reminder: MLK schedule (1/17)

Class is from 10:45--11:35 pm 1/17 to accomodate MLK day activities on campus.

Reminder: Quiz #2 is Friday, 1/21

The quiz will be over Section 1.2 and our continued Python review.

Read Section 1.3

(due 1/26) Chapter 1 Review Questions

Do the T/F and multiple choice questions at the end of Chapter 1 (pp 33--35). Put your answer on paper suitable for hand-in.

(due 2/2) 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."

Reminder: Quiz #3 is Friday, (1/28)

The quiz will be over Section 1.3

Start Reading Chapter 3

Reminder: Quiz #4 is Friday (2/4)

This quiz will be over the tonelib project and sections 2.1--2.3.

Finsih Reading Chapter 2 (due 2/7)

(due 2/9) Chapter 2 Review Questions

Do the T/F and Multiple Choice Questions at the end of Chapter 2 (pp 68--70). Have your answers on paper suitable for hand-in at the beginning of class.

Announcement: Exam 1 (2/11)

Our first example was originally scheduled for 2/9 (per the syllabus). I am delaying it until Friday (2/11). The exam will cover chapters 1 and 2 as well as the craps and tonelib projects.

Additional note: I've posted the quizzes we've had so far under the handouts tab on Socrates.

(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/16) Chapter 3 Reading

Read 3.1--3.3.

(due 2/21) More Chapter 3 Reading

Read Sections 3.4 and 3.5.

(due 2/21) Chapter 3 Short-Answer #1

Do Short-Answer Question #1 on Page 102. Have your answers on paper ready at the start of class.

Important Update on SoundWave

The quick algorithm that I gave in class for the __add__ operation did not take into account that the two sample lists could have different lengths. Here is pseudocode for a more general approach that fixes it:

	 let s1 and s2 be the samples from self and the parameter, respectively.

         if len(s1) < len(s2):
	     swap s1 and s2  # this makes sure that s1 is the longer of the two
	     
	 samples = list(s1)  # makes a new list that is a copy of s1
         loop through s2
             add s2[i] to samples[i]		      
	 return SoundWave(samples)

Finish Reading Chapter 3

You may safely skip the extended Markov chain example for dictionaries.

(due 3/14) Project: synthesizers and keyboards

Building on what we did in class on 2/25, our next two projects involve building components to allow us to "play" synthesized notes from a musical keyboard. To accomplish this we will be developing two related classes. You can find starter code and test code for these classes in our handouts folder under synth_keyboard.

The first class is WaveSynth (see wavesynth.py and test_synth.py). This is a simple class for synthesizing tones. You can think of a WaveSynth as an instrument for producing musical notes. We can set certain properties of the instrument (waveform, volume, and sustain), and then use it to produce notes of varying frequency and duration. The properties are set with the three methods starting with the name "set_" and notes (SoundWaves) are generated with the synthesize method.

You should be able to figure out the code by studying the method specifications. Your class will require 3 "private" instance variables. I suggest naming them _wavfunc. _volume, and _sustain. This class can easily be completed using functions available in the tonelib. The test_synth.py file contains testing code that produces numerous ".wav" files (synth_test1--4). In the assignment folder, there is a test_results subfolder that has correct "reference" files that you can compare (by ear) to your results to make sure your synthesizer class is working.

Once the WaveSynth class is working, you are ready to tackle the Keyboard class (see keyboard.py and test_keyboard.py. A Keyboard is a "wrapper" around a synthesizer to allow it to play notes from a musical scale. You should be able to understand the various methods by looking at the specifications and studying the testing code. Again, reference ".wav" files (kb_test1--6.wav) can be found in the test_results subfolder.

I have provided solutions to previous phases of the project (tonelib.py, soundwave.py) on which these new classes depend. Feel free to begin this project over break, but you will also have time to complete it once classes are back in session. I am tentatively planning on having WaveSynth due on Friday (3/11), and Keyboard due the following Monday.

Edit: Both are as a single project on 3/14.

Reminder: Quiz 6 is Friday (3/11)

The quiz is over dictionaries.

Read Chapter 4 (Sections 4.1--4.3)

Reminder: Exam 2 is on Friday (3/18)

It will cover Chapters 3 and 4 (emphasizing the portions that were covered in class). Also included are the SoundWave, WaveSynth, and KeyBoard projects.

Read Chapter 4 (Sections 4.5, 4.7)

MCSP Seminar (Extra Credit Opportunity)

On Tuesday, 3/22, our MCSP seminar series will feature (via Zoom) Wartburg alum Eric Stahlberg, who leads Biomedical Informatics and Data Science at the Frederick National Laboratory for Cancer Research. His talk is titled "A Look Ahead - How Computing is Transforming the Future of Biomedical Research." The event is at 11:30 am in SC 134.

Attending this talk and turning in a brief reflection is worth 5 points of extra credit. If you are not available at that time, the presentation will also be recorded for viewing later.

(due April 4) Exam 2 redo

As discussed in class today, I am offering an opportunity to improve your score on Exam 2. Treat the hand-ed back exam as a take-home exam and do all 12 questions. You may, of course, refer to your prior answers, but you should copy-over, redo all work to make a nice complete exam with all 12 questions answered in order. You can use your textbooks, notes, and me as a reference to help you complete the rewrite.

I will average your original exam score wtih the rewrite with the additional proviso that a passing grade on the rewrite guarantees a passing grade overall on the exam.

Announcement: CS 220 Consulting

Also as announced in class today, I will be holding extra office hours in the classroom Mon--Thurs from 6:30 to 7:30 pm. You can come to this time to get help on any work related to CS 220. If no one shows up by 7:00, I will pack it in for the night. This offer holds from 3/21 until 4/1.

Read Sections 5.1 and 5.2

You can safely omit subsection 5.2.5

(due 3/25) posteval.py

The starter code is in handouts/postfix You are to write the postfixeval function so that the posteval.py program correctly evaluates postfix expressions. Note: expressions must be entered with a space separating the parts of the expression.

In its current form, the main porgram will "break" when an improper expression is entered. For bonus points, enhance the program so that improperly formed expressions print out a suitable error message and allow the user to keep entering expressions.

Finish reading Chapter 5

You can safely omit section 5.5.

Reminder: Quiz 6 on Friday (3/25)

The Quiz will cover 5.1--5.3.

(due 3/30) bqueue.py

A BoundedQueue is a queue with a fixed maximum capacity. It is easily implemented using the "circular list" technique that was discussed in class. Complete the BoundedQueue implementation in bqueue.py which is in the handouts/boundedqueue folder. In that folder you will also find test_bqueue.py which contains unit tests for your implementation. Studying and understanding the test code would be a good place to start.

(due 4/4) Project: StringSynth

This project is an application of bqueue.py and is an extension of our audio project. The assignment is to create a new StringSynth class that implements a simple version of the Karplus-Strong algorithm to simulate the physics of the vibration of a plucked string.

Starter code, test code, and example outputs can be found in the folder: handouts/stringsynth. The StringSynth class to complete is in the stringsynth.py file. The testing code makes use of the Keyboard class to produce notes. I have also included wavesynth.py for comparison, but it is not used in this phase of the project. You will only need to turn in the stringsynth.py file.

Looking at the StringSynth class, you can see that it has a syntehsize method and a _volume instance variable similar to our previous WaveSynth class. Instead of sustain, however the StringSynth has a _loopgain attribute that controls sustain in a slightly different way. In the test files, you will see that this setting is usually close to 1 (in the .95 to .999 range).

The following pseudocode describes the Karplus-Strong algorithm to produce a tone with a given frequency. It produces a waveform that sounds similar to a plucked string.

q = a BoundedQueue with capacity of samplerate/freq
fill q to capacity with random float values between -volume/100 and volume/100
samples = []
for the number of samples desired:
    sample = q.dequeue()
    add sample to samples
    avg_sample = (sample + q.front())/2 * loopgain
    q.enqueue(avg_sample) 
return a Soundwave created from samples

Notice the algorithm makes use of a BoundedQueue that is initally filled with random noise having an amplitude limited by the setting of the volume. For example, if the volume is set to 75, the queue is filled with random floats in the range of -0.75 to 0.75. The loopgain value controls the sustain as discussed above. Also note that the queue stays the same size during sample generation, as there is exactly one dequeue and one enqueue each time through the loop.

Read Chapter 6

(due 4/8, midnight) Arrow Fractal arrow.py

Write a program to draw the "arrow" fractal. The generator is a "hump" created by tracing the "outline" of two side-by-side equilateral triangles. This generator is alternated similar to the dragon curve, except the first bump is "in" rather than "out". Here are pictures of the level 1, 2 and 3 curves:

Higher level curves should give you a familiar figure. If you do not recognize it, then you probably have not done it right.

(due 4/19) Wartburg Loyalty

Details of the assignment can be found here. The starter code can be found in handouts/songplayer

RICE Day (extra credit opportunity)

The CS/CIS senior project poster sesstion is from 7:00--9:00pm on the 3rd floor of the Science Center. Attending the poster session and turning in a brief reaction to your 2 favorite posters is worth up to 5 points of extra credit.

Read Chapter 7 (7.1, 7.2, 7.4, 7.5)

Reminder: Final Exam (4/22, 8:30 am)

It will cover Chapters 5, 6, and 7.