Question
The following C++ program currently matches the notes (keys) on a piano with a number. The notes/keys on a piano are numbered as follows: C
The following C++ program currently matches the notes (keys) on a piano with a number. The notes/keys on a piano are numbered as follows: C = 1, C# = 2, D = 3, D# = 4, E = 5, F = 6, F# = 7, G = 8, G# = 9, A = 10, A# = 11 and B = 12. As you can see, there are exactly twelve different notes that make up a series of notes on the piano called an octave. On a keyboard, once this octave series of C, C#, D...B is completed, it repeats again an octave higher. The next octave would begin again at C = 13, C# = 14, D = 15all the way to B = 24. The next octave above that would have C = 25, and so on. Each note repeats itself in numeric intervals of 12. We indicate the starting/fundamental octave as C, the next octave above that as C, the next one above that as C, and so forth.
Currently, the program provides a command for a user to enter any number and then displays the corresponding note name for it. For example, if a user entered 27, the note D would display. (The corresponding octave does not need to be named hereonly the letter of the note. If youre wondering why the term octave is used for a span of 12 notes, although there are 12 notes in an octave, 8 of these consist of white keys and 4 of black keys. The entire interval from C to B is named an octave in honor of the white keys. The complete 12-tone series, however, is formally called a dodecaphonic series.)
Using this program, please provide additional code that also allows the user to enter any range of numbers and then displays, for each note, how many times it appears within that range. For example, if the user enters a range from 1-27, the program displays: C = 3, C# = 3, D = 3, D# = 2, E = 2, F = 2, F # = 2, G = 2, G# = 2, A = 2, A# = 2, B = 2.
#include
#include
#include
double number;
using namespace std;
int main()
{
long long int number;
// reading the number
cout << "Enter a number:" << endl;
cin >> number;
while (number>12) { number -= 12; } switch (number) { case 1: cout << "C "; break; case 2: cout << "C# "; break; case 3: cout << "D "; break; case 4: cout << "D# "; break; case 5: cout << "E "; break; case 6: cout << "F "; break; case 7: cout << "F# "; break; case 8: cout << "G "; break; case 9: cout << "G# "; break; case 10: cout << "A "; break; case 11: cout << "A# "; break; case 12: cout << "B "; break; }
system("pause");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started