Program / Task Name:

   Music

Level:

 

 Novice / Advanced

Point Value:

 

 6

 

Task Description

On a piano keyboard, if one begins at middle-C, then the sequence of half-steps from middle-C to B is listed in the following table.  Since two different terminologies for naming the notes can be used, two different terminologies are shown, a “sharp” terminology and a “flat” terminology.  All notes in the same row are identical.

Sharp terminology

Pronunciation

Flat terminology

Pronunciation

C

 

C

 

C#

“C-sharp”

D

“D-flat”

D

 

D

 

D#

“D-sharp”

E

“E-flat”

E

 

E

 

F

 

F

 

F#

“F-Sharp”

G

“G-flat”

G

 

G

 

G#

“G-sharp”

A

“A-flat”

A

 

A

 

A#

“A-sharp”

B

“B-flat”

B

 

B

 

“#” and “” are known generically as an “accidentals.”

Immediately following the B is another identical sequence going from C to B through each of the notes above.  Each of these sequences, when going from C to C, is called an octave.  On an 88-key piano, this pattern repeats 4 times from middle-C to the highest C on the piano, and the highest note on the piano is a C.  Thus, pattern stops at C, exactly 4 octaves above middle C.

A major chord is created by playing three notes together.  The bottom note is the chord name.  Thus if the bottom note is a C, then the chord is called C major.  The other two notes are derived by moving 4 half steps up to get one note and then 3 half-steps up from there to get the other note.  Thus, a C-major chord is C-E-G. 

A minor chord is also created by playing three notes together.  Again, the bottom note is the chord name, and if the bottom note is a C, for example, the chord is called C minor.  To get the second note with a minor chord, one moves 3 half steps up; the third note is derived by moving 4 half steps up from there.  Thus, a C-minor chord is C-D#-G (or C- E-G).

Write a program that reads the input file of individual notes and either the word, “major,” or “minor,” and outputs the three-note combination for the appropriate major or minor chord based on each note.  Since the ““ symbol is a complex Unicode character, your input file will use a lower-case “b” to represent flat; your output file should do the same.  Your output must use the flat-names (e.g. “Eb”) whenever an accidental must be expressed if the input also used a flat name.  If the input used neither flat nor sharp (e.g. “C”) or used a sharp name (e.g. “C#”), then all derived notes must use the sharp terminology whenever an accidental must be expressed.  Use a hyphen (“-“) to separate notes in the output and place each output on its own line.

Program Input

The input file (prob07.in) consists of the individual notes.  Exactly one space will separate the note specification from the word major or minor.  A newline character (\n) will follow the word major or minor in each case.  The number of lines of input is not specified for you.  You must read until the end of file is reached.  Except with regard to the “b” symbol that is used to indicate flat, your program must read the input data in a case-insensitive fashion.

C major
gb minor
Bb major
d# minor

Program Output

Output the three-note combination for the appropriate major or minor chord to a file (prob07.out):

C-E-G
Gb-A-Db
Bb-D-F
D#-F#-A#

 

   
  (c) 2004 Hewlett-Packard Company