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 as follows:System.out.printf("%.2f", yourValue);
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
Note: Use one statement to compute r = 2(1.0/12.0) using the pow function. Then use that r in subsequent statements that use the formula fn = f0 * rn with n being 1, 2, 3, and finally 4.
import java.util.Scanner; public class LabProgram { public static void printKeys(double inputKey) { double r = Math.pow(2.0, 1.0/12.0); double key; double n; for (n = 1.0; n <= 4; n++) { key = inputKey * Math.pow(r, n); System.out.printf(" %.2f", key); } } public static void main(String[] args) { double inputKey; Scanner scnr = new Scanner(System.in); inputKey = scnr.nextDouble(); System.out.printf("%.2f", inputKey); printKeys(inputKey); System.out.print("\n"); } }
#Taking the n value as input
note=float(input("Please Enter the value of n: "))
#value of power is 2^(1/12)
power=2**(1/12)
frequency1=note*power
frequency2=frequency1*power
frequency3=frequency2*power
frequency4=frequency3*power
print("{:.2f} {:.2f} {:.2f} {:.2f} {:.2f}".format(note,frequency1,frequency2,frequency3,frequency4))
Code in Coral please 2.17 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 as follows: print('{:.2f}...
4.16 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* r, 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 as follows: print('%0.2f %.2f %0.2f %0.2f %.2f' %...
What beat frequencies result if a piano hammer hits three strings that emit frequencies of 659.3, 293.6, and 440.0 Hz? (Enter your answers from smallest to largest.) You and a friend frequently play a trombone duet in a jazz band. During such performances it is critical that the two instruments be perfectly tuned. Since you take better care of your trombone, you decide to use your instrument as the standard. When you produce a tone that is known to be...
Write an M-file to produce a desired note, expressed in piano key number, for a given duration. Your M-file should be in the form of a function called key2note.m. Your function should have the following form: function xx = key2note(X, keynum, dur, fsamp) % KEY2NOTE Produce a sinusoidal waveform corresponding to a % given piano key number % % usage: xx = key2note (X, keynum, dur) % % xx = the output sinusoidal waveform % X = complex amplitude for...
3.14 LAB: Driving cost - methodsWrite a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.Output each...
6.26 LAB: Driving cost - methodsWrite a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.Output...
Problem 1 Consider the following asymptotic Bode plots. Note that the frequencies are in Hz. For each frequency response shown in (a)-(d), do the following: 1. Determine the transfer function H(s). 2. Synthesize H(s) using the RC circuits shown in Tables 3.4, 4.2 and 4.3 of the handout. Use as few opamps, resistors and capacitors as possible to simplify your design. Note: If you prefer, you can down-scale (by a frequency scaling factor ky) the original frequency response to work...
Lab 2 (ADTs) 1) LockADT – Show the interface and all abstract methods LockDataStructureClass – Show the following methods: default constructor, overloaded constructor, copy constructor, setX, setY, setZ, alter (change the lock’s combination to the numbers passed) turn (use for loops to show the dial turning), close (locks the lock), attempt (tries to unlock the lock – calls turn( ), inquire (locked or unlocked), current (returns the number the dial is pointing to), toString LockClientDemoClass – You should have a...
Hi-fi audio amplifiers are usually built as discrete operational amplifiers with a relatively large gain (g ? 500) and with feedback that reduces the closed-loop gain to a smaller value k = 32. Since loudspeakers predominatly act like a resistor (nominal impedance: 8 ) with an inductor in series, the feedback network can be used to improve the frequency response in the audio range up to 20 kHz. We are primarily concerned with gain and frequency response of the amplifier....
I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...