Programming Exercise #ex5_2
Create a new text file named "ex5_2.cpp" with the following two lines. Be sure to replace the string "YourFullName" with your real full name.
1.
2.
3.
4. /* Filename: ex5_2.cpp
Student: YourFullName */
6. Next to the above two lines, write a C++ program that uses the "#define" directive to define a constant named "I_ZERO" whose value is 10^-12. Then, use the "#define" directive to define a macro named "BETA" that takes one parameter named "P". Be sure to specify that the token-string of the "BETA" macro will perform the calculation according to the "decibel formula" (as shown below), in which Io will get its value from the "I_ZERO" constant. Read the explanation on the right for details.
B = 10 x log(I/Io)
Explanation:
In Physics, the sound intensity in decibels is defined by the "decibel formula", which is the logarithm of the sound intensity. The formula is typically expressed as:
B = 10 x log(I/Io)
ß is sound intensity (in decibels, dB);
I is sound intensity (Watts per square meter, W/m²);
and sound intensity reference intensity Io is a constant known as reference sound intensity. The value is 10^-12.
5. In the "main()" function, call the "BETA" macro to solve the following problem. "The sound intensity inside a car is 6.02×10^7 W/m^2. What is this sound intensity in decibels?"
Make sure the output looks similar to the following.
Developer Comman.....
0
It is approximately 57.796 dB.
X
Programming Exercise #ex5_2
Create a new text file named "ex5_2.cpp" with the following two lines. Be sure to replace the string "YourFullName" with your real full name.
1.
2.
3.
4. /* Filename: ex5_2.cpp
Student: YourFullName */
6. Next to the above two lines, write a C++ program that uses the "#define" directive to define a constant named "I_ZERO" whose value is 10^-2.
Explanation:
In Physics, the sound intensity in decibels is defined by the "decibel formula", which is the logarithm of the sound intensity.
3. Then, use the "#define" directive to define a macro named "BETA".
The formula is typically expressed as:
B = 10 x log(I/Io)
Be sure to specify that the token-string of the "BETA" macro will perform the calculation according to the "decibel formula" (as shown below), in which Io will get its value from the "I_ZERO" constant. Read the explanation on the right for details.
I is sound intensity (in decibels, dB);
I is sound intensity (Watts per square meter, W/m²);
and I is a constant known as reference sound intensity. The value is 10^-12.
5. In the "main()" function, call the "BETA" macro to solve the following problem:
"The sound intensity inside a car is 6.02×10^-7 W/m^2. What is this sound intensity in decibels?"
6. Make sure the output looks similar to the following: