CS U216 -- Algorithms and Data Structures for
Engineers
Assignment 5
Due 9 June, 2005
Assignment 5 involves making changes to the music classes that
were discussed in lab. (The source code for these classes is
in the file music.h, available at
http://www.development.ccs.neu.edu/home/peterd/csu215/LabExamples.aspx).
The file you submit should be a header file, such as a modified version of
music.h.
The submitted file should include compiler directives to protect against
multiple inclusions. These compiler directives are already in music.h.
The submitted file should not include the function main().
- Due to my musical ignorance, I did not realize that the term used in music
for a set of pitches which are separated by octaves, for example all of the
"C"s, is a "pitch class". In lab, I called these scale positions, and created
a ScalePosition class.
For this assignment, you should rename the ScalePosition class to be the
PitchClass class.
If you just change the name of the class, you will get
an error when you attempt to build the classes in music.h.
Add a comment to your file that lists all of the places you needed
to change for your classes to build and run correctly.
- Add a new constructor to the PitchClass class, which takes a string
as an argument. The following strings should result in the creation of
"valid" PitchClass objects:
- A string consisting of a single upper case letter A through G
- A string consisting of a single upper case letter A through G
followed by a '#' symbol (for example "C#").
- A string consisting of a single upper case letter A through G
followed by a lower case 'b' (for example "Bb").
The following table gives numeric encoding that should be used for
PitchClass objects that are created with a single letter.
If the argument to the constructor is a string ending in '#', the numeric
encoding of the created object should be 1 greater than the encoding of
an object created with a string without the '#'. For example,
"C#" should create an object with the encoding 4, because "C" creates
an object with the encoding 3.
If the argument to the constructor is a string ending in 'b', the numeric
encoding of the created object should be 1 less than the encoding of the
corresponding object created without the 'b', except that "Ab" should
be encoded as 11, not as -1.
-
Modify the constructor(s) for the Note class, so that only Note objects
created with positive durations are valid. (Only for those notes
will the isValid() method return true).
-
Create a Rest class, which is similar to the Note class, but
has only a duration, and no pitch. The Rest class should have
a play() method, which at this point does nothing.
-
Create a Voice class.
The Voice class should have a play() method,
which at this point does nothing.
The Voice class should have an addNote(Note n) method.
Calls to the addNote(Note n) method should somehow store
the arguments to those calls "within" the object. There are many
ways to do this, and I'm sure we will cover some in class.
One possible implementation, which is very simple, but may not be the
best is for your class to have private member fields
- Note notes[SIZE];
- int nextNoteToRecord;
When a Voice constructor is called (also known as "invoked"),
nextNoteToRecord should be initialized to 0.
Then each call to addNote(Note n) should record its argument
in notes[nextNoteToRecord] if nextNoteToRecord is less than SIZE.
Following that, nextNoteToRecord should be incremented,
Last updated 2 June 2005.