Topic: On May 5, 1891, the Music Hall in New York (now known as Carnegie Hall) was officially opened. At the opening, Tchaikovsky, the famous Russian composer, served as a guest conductor.
1. The classical music scale is logarithmic. Describe, in detail, how logarithms speed up computations.
For extra credit: Describe one more event from the history of computing, and how this event influenced the field of computing.
2. In 1891, only a few people could listen to a concert. Nowadays, many performance are recorded, and everyone can easily download the corresponding music files and burn a CD. The cost of the resulting CD consists of the cost of the blank CD plus the cost of the downloads. Write a method called cd that takes as input the price of a blank CD, the price of downloading a single song, and the number of songs, and returns the overall cost of producing the corresponding CD. Trace this method for the case when a blank CD costs $2.00, downloading each song costs $1.00, and you want to have 9 songs on this CD.
Your method should return $2.00 + 9 * $1.00 = $11.00.
For extra credit: describe a GUI design for entering the price of CS, the price of downloading a song, and the number of songs, and for displaying the overall cost of producing the CD.
3. Define a class CD in which each object has three private fields: costOfBlankCD, costPerSong, and numberOfSongs. Your code for defining the class should contain:
4. A student prepared an email bragging about a nice Beatles CD that he compiled but he accidentally misspelled the band's name as Beetles. Write a piece of code that, given a string email that contains the misspelled name Beetles, replaces the first occurrence of this word with the correct spelling Beatles.
For extra credit: write a piece of code which performs the same replacement even when there may be several occurrences of the misspelled word Beatles.
5. A student prepared two classic-rock CDs, with the Beatles and with the Rolling Stones songs, and placed the descriptions of these CDs into two strings named beatles and rollingStones. While working on the CDs, she was enjoying the music so much that she accidentally placed the description of the Beatles CD into the string rollingStones, and vice versa. Write a method that swaps the values of these two global variables. Trace your method on the example when the student placed the words "I like Paul" into the string rollingStones, and the words "Mick Jagger rocks!" into the string beatles.
Hint: your method should work (i.e., swap the values) for all possible values of these two variables, not just the ones used in the example.
6. To simplify his archive of CDs, a student decided to use one-letter abbreviations for commonly used rock groups: B means "Beatles", R means "Rolling Stones", and Q means "Queen". Assuming that the variable abbrev contain one of these abbreviation, write a piece of code that, based on the value of this variable, prints the meaning of the corresponding abbreviation. If the letter is neither B, not R, nor Q, print a blank space.
Write two versions of this code:
For extra credit: what are the relative advantages and disadvantages of using ?: instead of if or switch statements?
7. The student decided to store all the information about his self-made CDs in a file, as follows:
Write a piece of code that asks the user for the name of this file and then places the names of the CDs (from this file) into an array named name and the corresponding number of songs into an array named numberfOfSongs, so that:
8. Write a method that takes as input:
9. In Problem 2, the computer had to add 2 and 9. Use the algorithms that we learned in class to translate 2 and 9 into binary, to add these numbers in binary, and to translate the result back into decimal (to check the correctness of the result).
For extra credit:
10. To prevent people from downloading music for free, the music company uses a special encryption algorithm to store the music files. A group of students cracked the encoding algorithm and placed the easy-to-use decoding algorithm on the web. Is this ethical?
Once the solution is posted, people from all over the world can download the corresponding songs for free. Is this ethical?
For each of these two cases, present:
For extra credit: present more arguments.