Question: C++ a.) Write a program named Lab3a.cpp . This is an exercise to create a data file from the contents of variables. Complete the program
C++
a.) Write a program named Lab3a.cpp. This is an exercise to create a data file from the contents of variables.
Complete the program according to the following steps. Read the entire instructions before writing code. In order to get 100%, the entire instructions must be followed.
Description
You should include a program description at the top of the program according to the template. You may simply use this sentence, "This program creates a data file in a predefined format to be used by other programs."
Define and Initialize Variables
Define seven string variables and initialize them with the days of a week. Define one variable per line. Use meaningful names for the variables. For example, string day1 = "Sunday"; for the first day of the week.
Define seven double variables and initialize them with the expenses of the week. Define one variable per line. Use meaningful names for the variables. For example, double day1Exp = 45.25; for the expense of the first day.
Create a Data File
Define a named string constant for the file name, expenses.txt. Use a meaningful name for the variable. The name must be in uppercase.
Define an ofstream variable. Use a meaningful name for the variable. For example, outFile.
Use the ofstream variable to open the file using the named string constant defined above.
Use the insertion operator << to insert the variable for the first day and then the variable for the expense of the first day in that order.
Do the same thing for the other six days and expenses.
Close The File
Use the ofstream variable to close the file.
Report
Inform the user that the file expenses.txt has been created.
Use cout to inform the user that the file expenses.txt has been created. You must use the named constant for the file name in the cout statement. That is, the following statement will not be accepted.
cout << "File expenses.txt has been created." << ends;
Run and Check The File
Now the contents of the variables have been saved to the file, expenses.txt. The file is expected to be in the same folder where the executable of the program is.
The saved file should have the following formatted contents when you open it with a text editor.
Sunday 45.25
Monday 49.38
Tuesday 12.75
Wednesday 123.50
Thursday 8.25
Friday 19.95
Saturday 145.70
If the contents are not exactly the same as the above, close the text editor and go back to the insertion statements and insert appropriate manipulators and run the program again. Repeat the steps until the contents are correct.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
