Question: 1- The program that follows will display a file called myfile.txt containing 6 records with two fields each. The data is as follows. 420 violet
1- The program that follows will display a file called myfile.txt containing 6 records with two fields each.
The data is as follows.
420 violet
470 blue
500 cyan
530 green
580 yellow
620 orange
700 red
The numbers refer to the wavelength, measured in nanometers, of each of the colors shown to the right.
[code]
// DisplayLightWavelength.cpp
#include
#include
#include
#include
using namespace std;
int main() {
//reading from a file
//create file objects
ifstreaminfile;
//need two variables to receive the data
int lambda;
string color;
//associate them with a file
infile.open("myfile.txt");
//make sure the file exists
if (!infile.is_open())//file not found
cout
else
{
//read first value
Infile>> lambda;
while (!infile.eof())
{
//read the rest of the line
infile>> color;
//print what we just read
cout
//read the beginning of the next data record
infile>> lambda;
}
infile.close();
}
return 0;
}
[/code]
When the program is run, the output is FROM myfile.txt:
The wavelength of "violet" is 420 nanometers
The wavelength of "blue" is 470 nanometers
The wavelength of "cyan" is 500 nanometers
The wavelength of "green" is 530 nanometers
The wavelength of "yellow" is 580 nanometers
The wavelength of "orange" is 620 nanometers
The wavelength of "red" is 700 nanometers
I need help witha program
which takes the contents of myfile.txt,
and creates a new file called: results.txt
results.txt is a textfilewhich has the format:
color frequency
color simply refers to the color of the record being processed.
frequency refers to the frequency (given in TeraHertz[THz]) of the color.
Remember that frequency = SpeedOfLight/WaveLength.
Note that although the WaveLengthwas given as an integer, the frequency will need to be given as a double.
Use the following value for the speed of light: 299,792.46 km/sec.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
