Create a C++ program to do the following: 1. Using ofs, functions, output file o
ID: 3873396 • Letter: C
Question
Create a C++ program to do the following:
1. Using ofs, functions, output file only
2. Create each one of the three Loops.
3. Each loop should be in its own function named as follows: a. whl = while loop b. doo = Do loop c. forr = For loop
4. Each Loop type should use a counter, and count to 10 while printing 1 thru 10 in the output file. [on the same line per loop]
5. Each Loop print should have a title for what type of loop is printed
6. Each count print should be on a separate line.
7. All numbers should be aligned with all three print types.
Explanation / Answer
3 functions to print 1 through 10 on an output file named "FileName.TXT".Please change the name as per your requirement:
void forr()
{
ofstream fout;
fout.open("FileName.TXT");
fout<<For loop is printed:<<endl;
int counter=1;
for(counter=1;counter<=10;counter++)
fout<<counter<<endl;
fout.close();
}
void whl()
{
ofstream fout;
fout.open("FileName.TXT");
fout<<While loop is printed:<<endl;
int counter=1;
while(counter<=10)
fout<<counter<<endl;
fout.close();
}
void doo()
{
ofstream fout;
fout.open("FileName.TXT");
fout<<Do While loop is printed:<<endl;
int counter=1;
do
{
fout<<counter<<endl;
}
while(counter<10);
fout.close();
}