Just so we don't have another @OP deletion from this one:
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
// DisplayLightWavelength.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
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<< "File not found" << endl;
else
{
//read first value
Infile>> lambda;
while (!infile.eof())
{
//read the rest of the line
infile>> color;
//print what we just read
cout<< "The wavelength of " << color << " is "
<< lambda << " nanometers" << endl;
//read the beginning of the next data record
infile>> lambda;
}
infile.close();
}
return 0;
}
|
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 with a 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.
2- AFTER getting the results.txt,
I need to code a program which takes the contents of results.txt, and displays those results so that you can clearly see what the frequency of each of the colors of the spectrum happens to be.
•For each of the colors of the spectrum the output should be of the following format:
The frequency of coloris xxx.xxTHz
3- Expanding on the concepts introduced in parts 1 and 2, prompt the user for the name of an input file and the name of an output file.
I NEED to Make sure to verify that the input file exists,
•Use a loop to validate and get another name.
•I do not have to verify that the output file exists because it will be created.
•BEFORE you start to process the data, MAKE SURE THAT YOU CAN JUST READ AND PRINT ALL THE DATA IN THE FILE!
•The program should work for a file with any number of records without modifying your code.
SO I need code a program to process employee pay increases.
•The data will be in a file with the following format:
•Employee_namecurrent_salarypercent_increase.txt
•Here is the content of datafile.txt which you will make (note 1 space only twixt entries):
Miller,Andrew 63700 5.5
Green,Shelia 55025.75 6.2
Abrams,Milton57400 6.1
Smith,Stacey72900 5.2
Charles,Ray54095 6.3
Note that there must be NO SPACES in the employee name. As a result, you will be able to read using >>
.•Your program will ask for:
The name of the file to process, and the name of the output file.
•Read the employee name, current salary, and increase.
•Calculate the new pay and write to an output file with employee name and new salary.
•Format the numbers to display 2 decimal places.
Laboratory V Part 3
Format for the output for the output file (here are the first two outputs):
Salary Increase Report:
SalaryIncrease.txt
Employee New Salary
Miller,Andrew $67203.50
Green,Shelia $58437.35
4- Problem 4:
•A program is required to read a series of product sales records from an input file specified by the user.
Each line of the file contains an item name (CANNOT HAVE SPACES), quantity sold, cost of item, and price sold
Item_name qty_sold cost price
Calculate and display the revenueand profiton each item, as well as the total revenue generated by all sales.
I need to Write this information to an output file. the program should prompt for names for both the input and output file.
Here is a sample file to test with, but your program should work with any file that is in this format.
Sample Input Data (inputfile.txt):
keyboard 20 54.95 75.00
mouse 10 22.50 30.00
wifi15 40.00 62.50
Sample Output Results (outputfile.txt)
see this image
https://i.imgur.com/J8OpltI.png