Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming Exercise Write a program which asks the user to specify the name of an input/output file (using an fstream object) and an output-only

C++ Programming Exercise

Write a program which asks the user to specify the name of an input/output file (using an fstream object) and an output-only file (using an ofstream object). The program should read the fstream file, and store the contents of the file in an array of structures. (Each line of input text should be placed in one element of the array.) After reading the complete file into this array, output the contents of the array of structures to the output-only file with each line formatted as described below.

struct FileText

{

int lineNumber;

long long fileOffset; // (use long long to prevent compiler warning)

int length;

string contents;

};

After reading the complete fstream file into the array of structs, the program should write the contents of the array to the output-only (ofstream) file. Each line of text in the output file must contain the field values from one FileText structure, in the format specified below:

lineNumber :contents

Notice that each line of the original text is preceded by:

The line number.

The file offset (bytes from the beginning of the file).

Length of the original text for that particular line.

Sample Input File: The Gettysburg Address

Four score and seven years ago our fathers brought forth

on this continent a new nation, conceived in liberty,

and dedicated to the proposition that all men are created equal.

Now we are engaged in a great civil war, testing whether that nation,

or any nation so conceived and so dedicated, can long endure.

We are met on a great battle-field of that war.

We have come to dedicate a portion of that field, as a final resting place

for those who here gave their lives that that nation might live.

It is altogether fitting and proper that we should do this.

But, in a larger sense, we can not dedicate, we can not consecrate,

we can not hallow this ground. The brave men, living and dead,

who struggled here, have consecrated it,

far above our poor power to add or detract.

The world will little note, nor long remember what we say here,

but it can never forget what they did here.

It is for us the living, rather, to be dedicated here to the unfinished work

which they who fought here have thus far so nobly advanced.

It is rather for us to be here dedicated to the great task remaining before us

--that from these honored dead we take increased devotion to that cause

for which they gave the last full measure of devotion

--that we here highly resolve that these dead shall not have died in vain

--that this nation, under God, shall have a new birth of freedom

--and that government of the people, by the people, for the people,

shall not perish from the earth.

Abraham Lincoln

*Sample Output File: lineNumber

1<0,57>: Four score and seven years ago our fathers brought forth

2<59,54>: on this continent a new nation, conceived in liberty,

3<115,66>: and dedicated to the proposition that all men are created equal.

4<183,70>: Now we are engaged in a great civil war, testing whether that nation,

5<255,63>: or any nation so conceived and so dedicated, can long endure.

6<320,48>: We are met on a great battle-field of that war.

7<370,75>: We have come to dedicate a portion of that field, as a final resting place

8<447,66>: for those who here gave their lives that that nation might live.

9<515,61>: It is altogether fitting and proper that we should do this.

10<578,68>: But, in a larger sense, we can not dedicate, we can not consecrate,

11<648,64>: we can not hallow this ground. The brave men, living and dead,

12<714,41>: who struggled here, have consecrated it,

13<757,45>: far above our poor power to add or detract.

14<804,64>: The world will little note, nor long remember what we say here,

15<870,45>: but it can never forget what they did here.

16<917,77>: It is for us the living, rather, to be dedicated here to the unfinished work

17<996,61>: which they who fought here have thus far so nobly advanced.

18<1059,78>: It is rather for us to be here dedicated to the great task remaining before us

19<1139,71>: --that from these honored dead we take increased devotion to that cause

20<1212,54>: for which they gave the last full measure of devotion

21<1268,72>: --that we here highly resolve that these dead shall not have died in vain

22<1342,63>: --that this nation, under God, shall have a new birth of freedom

23<1407,67>: and that government of the people, by the people, for the people,

24<1476,33>: shall not perish from the earth.

25<1511,15>: Abraham Lincoln.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What is the difference between and ? between s and ?

Answered: 1 week ago

Question

11. Suppose f(x)=3x+7 and g(x) = x+ find the value of (fog) (1)

Answered: 1 week ago

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago