Question: C++ Goal: To learn the basic operations for random access files. Use the functions, such as get(), put(), seekg(), seekp(), tellg(), tellp() and eof(), to

C++

Goal: To learn the basic operations for random access files. Use the functions, such as get(), put(), seekg(), seekp(), tellg(), tellp() and eof(), to manipulate data in files. (You do not need to use all of these functions.)

Task 1:

Implement a function named getFileSize() which returns the number of bytes of a file.

int getFileSize(const std::string &fileName)

Use the function above to check the size of an empty file named empty.txt and display:

There are 0 byte(s) in the file empty.txt.

Use the function above to check the size of an input file named letters.txt and display:

There are 26 byte(s) in the file letters.txt.

Task 2:

Copy the content of letters.txt to an output file named output1.txt.

Task 3:

Copy the letters at the positons of the 1st, 3rd, 5th, 7th, 9th to another file, named output2.txt.

For example, if the content of letters.txt is abcdedghijklmnopqrstuvwxyz, then after the program is executed, the content of output2.txt should be acegikmoqsuwy.

The output should be something like the following:

Task 1:

There are 0 byte(s) in the file empty.txt.

There are 26 byte(s) in the file letters.txt.

Task 2:

The output file is output1.txt.

Task 3:

The output file is output2.txt.

Thank you ahead of time for your help!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!