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

Write a program that prompts a user for a filename of an existing file that cont

ID: 3630338 • Letter: W

Question

Write a program that prompts a user for a filename of an existing file that contains 10 lines of student names. Assume that names are of equal length and they are inserted into a file based on the order of the student’s ID. The IDs are from 1-10 and thus the order of the student in the file is his/her ID. Next, the program reads the filename, reads the student ID and then seeks to the line that contains the student name, reads it byte by byte and writes it into a new output file.
(Note: create the input file before you run the program)


I solve this question with seek function and i have an errors so help me plz . .


#include
#include
#include

using namespace std ;

// main function

void main ()
{
ifstream infile ;
ofstream outfile ;
char c ;
long begin,end;

infile.open("text.txt" , ios::in );
outfile.open( "output.txt",ios::out );
int n ;
int id ;

int length = 5 ;

cout <<" please enter the student id: "< cin >> id ;

n = id*(length + 1);



infile.unsetf(ios::skipws) ;
infile.seekg(n,ios::beg) ;


infile.read(&c , 1);

while ( !infile.fail())// && n {
outfile<<(end-begin)< infile>>c;
}

outfile.close();
infile.close();


}

Explanation / Answer

Dear Friend here is the solution using our algorithm #include #include #include using namespace std ; // main function void main () { ifstream infile ; ofstream outfile ; char c ; string line; long begin,end; infile.open("test.txt" , ios::in ); outfile.open( "output.txt",ios::out ); int n ; int id ; int length = 5 ; cout id ; n = id*(length + 1); infile.unsetf(ios::skipws) ; infile.seekg(n,ios::beg) ; infile.read(&c , 1); while ( !infile.fail()) { getline(infile,line); outfile
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