Question
We also need to do a file in the form of .txt, I don't know how. Input of data from a file Note that the
We also need to do a file in the form of .txt, I don't know how.
Input of data from a file Note that the filename is defined within the code. The program will use the same file every time until the name is changed and the program is recompiled. Note also the format of the input file. It contains two lines of information about how the file is set up. In our class, your input files will always contain one or more lines of text at the top with information on what data is in the file and how it is presented.
Data Files for Input Whenever you are reading data from a file you will need to create the file to use for input. A data file for input can be created in Visual Studio as a .txt file, in a manner similar to creating a .cpp file. You can also create and edit files in Notepad. Both methods are explained below. For the explanations, Ive used Exercise 4 as the example, using ex4data.txt as the file name, but the process extends to any file used in any program, including .cpp files. When running the program, the input file must reside in the same location in the Visual Studio Project file as the .cpp code for this program. If it doesnt you will get incorrect values (aka Garbage!) Format of Input files Every input file you use in the class should have one or more identification (or descriptor) lines consisting of text information at the beginning of the file. These identification lines are used to describe the purpose of the file and how the data in the file is arranged. All lines of information must be read into the program, and are printed as part of the program flow. For Exercise 4 you might use the following two descriptor lines: This file contains input for Exercise 4. File contains: name (a single word), hours worked (float), wage (float, in dollars per hour, no $ sign) You would follow these two lines with all of the data used for input to the program. See examples below.
NOTE: I added these paragraphs above if they are useful to make a file. Thank You.
EGR 126 Exercise 4 - File Input The objective of this Exercise is to demonstrate the use of a file for data input. Write a program for a payroll calculation: given a name, hours worked, and an hourly wage, calculate and print the total amount earned in a sentence. Your output might look something like the following: CH. C:\Windows\system32\cmd.exe Harriette Roadman Exercise 4 Jan 23, 2016 Data is being read from file ex4data.txt File contains: name (single word), hours worked (float), wage (float, in dollars per hour) Samantha worked 24.50 hours at $7.85 per hour and earned $192.32 for the week. Press any key to continue ... This data file was used for input to the program that produced the output shown above: ex4data - Notepad File Edit Format View Help File contains: name (single word), hours worked (float), wage (float, in dollars per hour) Samantha 24.5 7.85 Things to note: Things to note: Please review the documents File Creation and File Input & Output. You will need to create a data file to use for input. You will choose the name of the input file. You might use something like "ex4data.txt". For this Exercise you should set up the input file to contain at least 4 lines of data: First line: information on how the file is set up Second line: a name (either one word, or several words, but must be character data) Third line: a value for hours worked, should be a decimal number Fourth line: a value for hourly wage, no $ included, should be a decimal number Write your code to read the values from the input file, including the first line, calculate the wage, and print the information requested. Your output doesn't need to be identical to what is shown, but it does need to have the same content. The input values are echoed as part of the wage sentence. Be sure to use #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started