9.7k views
0 votes
2. 32 LAB: Musical note frequencies On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12). Given an initial key frequency, output that frequency and the next 4 higher key frequencies. Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 440. 0 (which is the A key near the middle of a piano keyboard), the output is: 440. 00 466. 16 493. 88 523. 25 554. 37

User Rambles
by
8.5k points

1 Answer

0 votes

Answer:

int main() {

double f0;

const double r = pow(2, 1.0/12);

cout << "Enter start frequency: ";

cin >> f0;

cout << fixed << setprecision(2);

for(int n=0; n<5; n++) {

cout << f0*pow(r, n) << " ";

}

return 0;

}

Step-by-step explanation:

In the description, some to-the-power notations were dropped, see code on how to resolve.

User Jskinner
by
8.2k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.