C++ programming labs
1: Project 15: Speed of Sound. Sound
travels through air as a result of collisions between the molecules
in the air. The temperature of the air affects the speed of the
molecules, which in turn affects the speed of sound. The velocity
of sound in dry air can be approximated by the formula:
velocity = 331.3 + 0.61
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cout << "Enter number to compute the square root
of: ";
cin >> n;
double guess = n / 2;
if (n < 0) {
cout << "Can't find square
root of a negative number" << endl;
}
else {
double pctDiff = 555555;
double lastGuess = guess;
while (abs(pctDiff) >= 0.01)
{
double r = n /
guess;
guess = (guess +
r) / 2;
pctDiff =
((guess - lastGuess) / lastGuess);
lastGuess =
guess;
}
cout << "The estimate of the
square root of " << n << " is " << guess <<
endl;;
}
return 0;
}
_______________________________________________________________________________________________
#include <iostream>
#include <iomanip>
using namespace std;
double velocity(int t){
return 331.3 + (0.61 * t);
}
int main(){
int sTemp, eTemp;
cout << "Enter the starting temperature, in
degrees Celsius: ";
cin >> sTemp;
cout << "Enter the ending temperature, in
degrees Celsius: ";
cin >> eTemp;
cout << setprecision(1) << fixed;
if (sTemp < eTemp) {
for (int i = sTemp; i <= eTemp;
++i) {
cout <<
"At " << i << " degrees Celsius the velocity of sound
is " << velocity(i) << " m/s" << endl;
}
}
return 0;
}
Note: (1) Project 15 and (3) Project 15 questions are same:
C++ Program Code:
//Header file section
#include<iostream>
using namespace std;
//Program begins with main function
void main()
{
//Declare variables
int startTemp, endTemp;
//Prompt and read input from the user
cout<<"\nEnter the starting temperature, in degrees Celsius:
";
cin>>startTemp;
cout<<"Enter the ending temperature, in degrees Celsius:
";
cin>>endTemp;
cout<<endl;
while(startTemp<=endTemp)
{
//Display the temperature and the corresponding
//velocity in one degree increments
cout<<"At
"<<startTemp<<" degrees Celsius the velocity of sound
is "<<(331.3 + 0.61 *startTemp);
cout<<" m/s"<<endl;
startTemp++;
}
//Pause system for a while
system("pause");
}
Output:
---------------------------------------------------------------------------------------------------------------
2) Project 12:
C++ Program Code:
//Header file section
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
//Program begins with main function
int main()
{
//Declared variables
int n;
double guess,previousguess,r;
//Prompt and read input from the user
cout<<"Enter number to compute the square root :";
cin>>n;
//Calculating value of guess
guess = (double) n/2;
while( guess*guess < 0.99*(double)n ||
guess*guess > 1.01*(double)n)
{
previousguess = guess;
r = (double) n/guess;
guess = (double)(guess+r)/2;
}
//Display the output as a double
cout << "The estimate of the square root of " <<
n
<< " is = " << guess << "\n";
//Pause system for a while
system("pause");
}
Output:
C++ programming labs 1: Project 15: Speed of Sound. Sound travels through air as a result...
A 33 kHz sound wave travels in air at v=355 m/s; what is the temperature of the air through which it travels? b) What is its velocity and wavelength? c) Two sound waves arrive at an observer; one is -30 dB quieter than the other which is at 1000 mW/m2. What is the intensity of the quieter one in mW/m2?
Intreductien: This assignment helps you to reinforce the topics discussed in the class including a) Variables and data types, constants, arithmetic operations b) Data input and output Important: This is an individual assignment. Please do not collaborate. Crading policy: We will check a) The correctness of your program/solution b) Variable naming (self describing), using constants appropriately c) Appropriate commenting and Indentation Part I [11 points I. 4 Peints] Sound eravels through air as a result of collision betwoen the molecules...
Problem 1: A sound wave of the form s = Smax cos(kx - wt+ 0) travels at 343 m/s through air in a long horizontal tube. At one instant, air molecule A at x = 2.000 m is at its maximum positive displacement of 6.00 nm and air molecule B at x = 2.070 m is at a positive displacement of 2.00 nm. All the molecules between A and B are at intermediate displacements. (a) What is the wavelength of...
A.) The speed of sound in dry air at 20 °C is 343.5 m s-1, and the frequency of the sound from the note D above middle C on the piano is 293.6 s-1 (according to the American standard pitch scale). Calculate the wavelength of the sound and the time it will take to travel 40.1 m across a concert hall. Wavelength = __________ m Time = __________ s 2.)A stretched string with fixed ends has a length of 98.1...
1) As light travels from water to air, its speed increases. Its wavelenght would a) increase b) decrease c) remain the same d) none of the above 2) For free fall, the gain in speed for a falling rock is the same as the gian in speed for a falling ping pong ball. a) Yes, they both get the same gain in speed during a free fall b) No, they don't have the same gain in speed during free fall...
1. The speed of sound in an alcohol at a temperature of 20°C is 1260 m/s. The density of the alcohol at that temperature is 650 kg/m^3. At a temperature of 20°C, find the bulk modulus of the alcohol. 1030 MPa 1080 MPa 1140 MPa 1190 MPa 1240 MPa 2. During a thunderstorm, you hear the sound 4 s after you see the lightning flash. How far did it fall? Assume the temperature outside is approximately 20 1.324 km 1.372...
1. (relative humidity) The partial pressure of water vapor in air is usually less than the equilibrium vapor pressure (or saturation pressure) at the ambient temperature; this is why a cup of water will spontaneously evaporate. The ratio of the partial pressure of water vapor to the equilibrium vapor pressure (at the same temperature) is called the relative humidity. Saturated air, at 100% relative humidity, would be in equilibrium with a cup of liquid water. The saturation pressure depends strongly...
O Search 13. Ranking Task #172 6. If a wave travels at a speed of 8 m/s and has a wavelength of 2 m, what is its frequency? O 6 Hz O 16 Hz o 4 Hz O 10 Hz Simple Resistor Circuits-Voltage Drop12 All the resistors in the circuits below are identical t 2 each. The batteries are ideal with voltages of 6 or 12 volts as shown. All connecting wires have negligible resistance Rank the voltage at the...
9,10,11,12,13,14, and 15 please a syringe is filled with 40. mL. of air at room temperature (22°C) in the lab and then this syringe is placed into a boiling water bath. After S minutes, the volume of gas in in the syringe (still at lab pressure) should be close to which volume? 9. Which of these is a true statement about a below a tube that is filled with a liquid such as mercury b. The weight of the liquid...
1. Wet solids pass through a continuous dryer. Hot dry air enters the dryer at a rate of 400 kg/min and mixes with the water that evaporates from the solids. Humid air leaves the dryer at 50°C containing 2.44 wt% water vapor and passes through a condenser in which it is cooled to 10°C. The pressure is constant at 1 atm throughout the system. a. At what rate (kg/min) is water evaporating in the dryer? b. Use the psychrometric chart...