Hello guys!
I treed to solve the problem coding for Doppler shift, and look what I have done:
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
double x;
double y;
double v;
double c;
float i;
x = x+i;
y = y+i;
v = v+i;
// x = wavelength (sound or lıght) when object is static.
// y = wavelength (sound or lıght) when object is moving.
// v = source speed
// c = wave speed
// l = limit
cout << " Wavelenght of static object is...";
cin >> x;
cout << " Wavelenght of moving object is ...";
cin >> y;
cout << " The object speed is...";
v = (1-(c*y)/x);
cin >> v;
y = y+i;
c = 300000000;
cout << "The object speed ıs ...";
system ("pause");
return 1;
}
I coded it by Dev-C++, and when I execute it Pass by console, insert the wavelength value for static object, insert wavelength value for moving object,
but I haven't calculation and program give me the answer without any value.
I noted c = 300000000 for light speed, how can choose between sound speed (340 m/s) and light speed ?
#include <cstdlib> //You don't need this
#include <iostream>
usingnamespace std;
int main ()
{
double x; //You can use 'double x, y, v, c;' instead of these 4 lines.
double y;
double v;
double c;
float i;
x = x+i; // You haven't set x or i yet. This does nothing
y = y+i; // You haven't set y or i yet. This does nothing
v = v+i; // You haven't set v or i yet. This does nothing
cout << " Wavelenght of static object is...";
cin >> x;
cout << " Wavelenght of moving object is ...";
cin >> y;
cout << " The object speed is...";
v = (1-(c*y)/x); //You haven't set c yet.
cin >> v; //You just overwrote your calculation
y = y+i; //What is i? It hasn't been set
c = 300000000; //You're finally setting c, but you don't use it after this point. Do this earlier.
cout << "The object speed ıs ..."; //Do you expect to see anything after this?
//cout << v; //Put this here.
system ("pause");
return 1; //return 0 is standard, 1 ussually means an error.
}
Regarding c, use an 'if' statement to determine the value:
1 2
if ("light speed is required") c = 300000000;
else c = 340;
Replace the condition in the if statement with something meaningful.
Since this means it's not homework here's your solution. Study what I did here. You need to ensure that EVERY variable gets set before you use it and follow the flow of your program from start to finish as order matters.
From the first post:
AldaBIG wrote:
w1 = w0*( 1 - v/c0 ) is the formulae.
w0 = wavelength of stable source (sound or light)
w1 = wavelength (of sound or light while moving toward source)
v = speed of movement toward source
c0 = speed of light 300000000 m/s or sound's speed 340 m/s
Here is how I would calculate the wavelength of the moving source. Modify it to calculate the velocity instead: