205k views
1 vote
Help needed in C++ programming!

On a piano, each key has a frequency, and each subsequent key (black or white) is a known amount higher. Ex: The A key above middle C key has a frequency of 440 Hz. Each subsequent key (black or white) has a frequency of 440 * rn, where n is the number of keys from that A key, and r is 2(1/12). Given an initial frequency, output that frequency and the next 3 higher key frequencies. If the input is 440, the output is: 440 493.883 523.251 554.365.

Note: Include one statement to compute r = 2(1/12) using the pow function, then use r in the formula fn = f0 * rn. (You'll have three statements using that formula, different only in the value for n).

2 Answers

2 votes

Answer:

This program is executed in C++ using dev C++, The explanation of the code is given below. However, the expected result of this program after running is attached

Step-by-step explanation:

#include <iostream>

#include <cmath>

#include<bits/stdc++.h>

using namespace std;

int main ()

{

double key=5;//it will generate next three keys from A;

double freq=440;//frequency ;

cout<<freq<<" ";//output the frequency

for(double i=2;i<key;i++)//loop to show next three frequency

{

float value = (1.0/12);// store value of (1/12)

double r=pow(2.0,value);//store value of r=2^(1/12);

double n=i;//number of ith iteration (number of next key)

double power=pow(r,n);//calculating r^n;

double result= freq* power;//function i.e. fn=f0*rn

cout<<result<<" ";//displaying result

}

}

Help needed in C++ programming! On a piano, each key has a frequency, and each subsequent-example-1
User Fringley
by
4.3k points
1 vote

Answer:

#include <iostream>

#include<conio.h>

using namespace std;

void main()

{

float freqk, freqsk1, freqsk2, freqsk3;

cout<<"Enter the Frequency of a Key = "

cin>>freqk;

freqsk1 = freqk * (1) * (1/6);

freqsk2 = freqk * (2) * (1/6);

freqsk3 = freqk * (3) * (1/6);

cout<<"\\Frequency of Key = "<<freqk<<endl;

cout<<"\\Frequency of Subsequent Key 1 = "<<freqsk1<<endl;

cout<<"\\Frequency of Subsequent Key 2 = "<<freqsk2<<endl;

cout<<"\\Frequency of Subsequent Key 3 = "<<freqsk3<<endl;

getch();

}

Step-by-step explanation:

There are four variables required to store the frequency value of a key and its subsequent keys. All variable are in float values so that answer should calculated in decimal format. With the help of formula calculate the frequency of all subsequent keys with the help of given frequency of key.

User Rwyland
by
4.9k points