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

5. Line Numbers (This assignment could be done as a modification of the program

ID: 3617327 • Letter: 5

Question

5. Line Numbers

(This assignment could be done as a modification of the program inProgramming Challenge 2.)
Write a program that asks the user for the name of a file. Theprogram should display the contents of the file on the screen. Eachline of screen output should be preceded with a line number,followed by a colon. The line numbering should start at 1. Here isan example:

1: George Rolland
2: 127 Academy Street
3: Brasstown, NC 28706

If the file's contents won't fit on a single screen, the programshould display 24 lines of output at a time, and then pause. Eachtime the programs pauses, it should wait for the user to strike thenext 24 lines are displayed.


Explanation / Answer

Hope you will Rate lifeSaver..
Code for Turbo C++ & BorlandC++ Compiler #include<iostream.h> #include<fstream.h> #include<conio.h> int main() { clrscr(); char str[20],data[20]; cout<<"enter file name:"; cin>>str; ifstream infile; infile.open(str); int count=1; while(infile) { infile>>data; cout<<endl<<count<<":"<<data; if(count%24==0) getch(); count++; } infile.close(); getch(); return 0; }
Code for Dev C++Compiler
#include<iostream> #include<fstream> using namespace std; int main() { char str[20],data[20]; cout<<"enter file name:"; cin>>str; ifstream infile; infile.open(str); int count=1; while(infile) { infile>>data; cout<<endl<<count<<":"<<data; if(count%24==0) system("pause"); count++; } infile.close(); system("pause"); return 0; }
#include<iostream> #include<fstream> using namespace std; int main() { char str[20],data[20]; cout<<"enter file name:"; cin>>str; ifstream infile; infile.open(str); int count=1; while(infile) { infile>>data; cout<<endl<<count<<":"<<data; if(count%24==0) system("pause"); count++; } infile.close(); system("pause"); 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