I have edited the program and it seems the first Frequency value from my text file is being read and not the rest. How can I create a loop that will keep reading from the text file and display different values for Frequency and Velocity and not same values? For Time, since it is an increment of 100 a loop worked without calling the time from the text file which is not correct as it should read from the text file in a loop. Also, Frequency values are long decimal points not displayed as seen with 9 decimal point since am using double data type. my text file loops like this:
0
100
200
300
400
500
600
5.500000040
5.500000095
5.500000230
5.500001800
5.500000870
5.500000065
5.500000370
Problem:
For a radar transmitting at frequency f (t), the difference in transmitted and received frequencies due to a target moving at speed v (m/s) relative to the radar that is, directly toward or away from the radar is given by
(f (r)- f (t)) / f (t) = 2v/c
where f (r) is the received frequency and c is the speed of light (3x10^8m/s). A weather service station at a major municipal airport is using a C-band Doppler radar f (t) = 5.5GHz). During a severe thunderstorm, the following received frequencies are observed:
Write a program that scans these data and displays a table showing the data along with a third column displaying the Doppler velocities of the winds relative to the radar.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int n;
int Time = 0;
double Frequency;
double Velocity = 0;//size of array more than number of entries in data file
ifstream infile("C:\\My documents\\frequency.txt", ios::in);//open the text file
infile >> Time;
infile >> Frequency;
while (!infile.eof())
{
infile >> Frequency;
Velocity = (((Frequency - 5.5) / 5.5) * 3e+8) / 2;
Frequency++;
}
cout << setw(1) << "Time" << setw(15) << "Frequency" << setw(20) << "Velocity" << endl;
for (Time = 0; Time < 700; Time)//counter loop of the first values from 0 to 600 increment
{
cout << setw(1) << Time << setw(15) << Frequency << setw(20) << Velocity << endl;
Time += 100;//Print out for the table with values.
}
infile.close();//input file is closed.
system("PAUSE");//will wait for the user to end the console
return 0;//End of the main program
}
and hence the program needs to repeatedly read the two values, time and frequency.
As a suggestion, it's not a good idea to change the input file, it's just adding more uncertainty. Try to keep things nailed down firmly and the target will be easier to hit.