Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, Please provide the source code to compile the following program to be wri

ID: 3667106 • Letter: H

Question

Hello,

Please provide the source code to compile the following program to be written in the C++ programming language. Also, please include good code commenting in the program so that even a beginner would be able to understand what is going on in the program. As you will see, it deals with handling a file and displaying its output. So, if you could provide a basic .txt file or code for one to put into Notepad and test this program runs right, that would be appreciated. I thank you in advance and will give a thumbs up rating if it compiles without errors.

. Assignment 1 File Display Program. Write a program that asks the user for the name of a file. The program should display the content of the file on the screen. If the file's contents won't fit on a single screen, the program should display 24 lines of the output at a time, and then pause. Each time the program pauses, it should wait for the user to strike a key before the next 24 line:s are displayed.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
#include<cstdio>
using namespace std;

/**
* Mimic the 'more' utility and pause every 24 lines.
*/
void more(const char *filename)
{
const int LINES = 24;
fstream file(filename);
if ( file )
{
int lineno = 0;
string line;
while ( getline(file, line) )
{
cout << ++lineno << ": " << line << ' ';
if ( lineno % LINES == 0 ) // if line number is multiple of 24
{
cout << "Press [Enter] to continue..." << flush;
int ch;
           while ( (ch = cin.get()) != ' ' && ch != EOF )
{
// wait for [Enter] keypress
}
}
}
}
else
{
perror(filename);
}
}

int main()
{
   char filename[20];
   cout<<"Enter file name: ";
   cin>>filename;
   //Method to read file
more(filename);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote