Huda M.

asked • 09/24/16

Write C++ code that collects user input and creates output

Our program will create a brief musical phrase just 6 notes long. For simplicity, the notes will be in the C-Major scale, meaning no sharps or flats, just the base notes C, D, E, F, G, A, and B. The rules that determine each note are listed below. Each of the six rules determines one note in turn. The user will “create” the composition by choosing a seed for the random number generator, and the computer does the rest. After seeding the random number generator with the user’s choice, the program should then generate 6 random integers between 1 and 200 (e.g., 20, 1, 18, 4, 13, 6; or 4, 8, 15, 16, 23, 42). Using these 6 numbers, the notes in the musical phrase are, in order,
Note 1: a) If the 1st number is even, the first note is C. b) If the 1st number is odd, the first note is E.
Note 2: a) If the 2nd number is greater than the 3rd number, then the second note is G. b) If the 2nd number is less than or equal to the 3rd number and is: i. evenly divisible by 5, then the second note is E. ii. not evenly divisible by 5, then the second note is C.
Note 3: a) If the 3rd number is less than 34, the third note is C. b) If the 3rd number is within the range 34 through 66 (inclusive), the third note is B. c) If the 3rd number is greater than 66, the third note is E.
Note 4: a) If the 6th number is bigger than the 1st number AND the 6th number is bigger than the 2nd number, the fourth note is A. b) If the either condition listed above is not true, the fourth note is F.

Note 5: a) If the sum of the 5th number and 6th number is greater than or equal to the sum of the 2nd number and the 4th number OR if the 4th number is greater than or equal to 100, the fifth note is G. b) Otherwise, the fifth note is B.
Note 6: a) If the 6th number is less than 100, the sixth note is the same as the first note. b) If the 6th number is within the range 100 through 150 (inclusive), the sixth note is D. c) If the 6th number is greater than 150, the sixth note is G.
In this assignment, you will develop code that asks the user for an integer, uses that value as a random number generator seed, generates six random integers between 1 and 200, and then outputs to the screen the resulting 6-note musical phrase created by the logic rules described above. When run, the only required output to the screen (after getting the user’s input) is the six letters indicating the notes, as in “C E B A G C”. If you wish, you can also output the six random integers—these may be useful in manually checking that the logic in the code is working correctly.

1 Expert Answer

By:

Patrick B. answered • 10/07/19

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.