### Assignment-Stream&Vector

I am taking a C++ intro class and we are currently learning stream, vectors and we have learned class and function couple weeks ago. I am given this assignment

"In this assignment, we will benchmark (evaluate the performance) of reading and writing some data in plaintext/ASCII mode vs. binary mode. We will measure both the speed and memory performance of the two approaches. Your program should perform the following steps:
1. Ask the user to enter a (positive, whole) number.
2. Ask the user to enter a target filename (e.g. output.txt).
3. Generate a vector of random doubles, where the length of the vector should equal the number entered by the user.
4. Create two strings, filename plain and filename binary. The value of these strings should equal the filename entered by the user, but with either \ plain" or \ binary" inserted immediately before the \." in the fi lename (you can assume the user enters exactly one \." in their input fi lename). (Hint: use member functions of the string class to nd where the \." is located.)
5. Measure the current time, then write the vector's data to the plaintext output le using plaintext
writing mode. Then measure the current time again, and print out the difference to the console. This
is our measurement of how much time it took to write the le in plaintext mode. To measure time, #include <chrono> and use chrono::high resolution clock::now() (see here).
6. Repeat the above step, but write to filename binary and write in binary mode.
7. Clear the vector.
8. Now we will do the opposite. Read from filename plain and measure the time it takes to read all the data into the vector. Print out the measured time.
9. Clear the vector once more and read in from the binary output le instead, again measuring and printing out how long it took to do the read.
10. Now let's compare how big the les are on disk. To measure the size of a le, we must open the file for reading in binary mode (even for a plaintext le). Then, we use ifstream's seekg and tellg functions to get the size, e.g. is.seekg(0, is.end); int length = is.tellg();. Print out the measured sizes of the plaintext and the binary les you wrote earlier."

I have been trying to write understand how to approach this. But I found I am lost. Could someone explain to me in plain English how to break down the logic? In particular, what member functions are needed in string class. Step 4 is my biggest problem. Please help a desperate student out. Thank you very much and sorry for the lengthy post.

 Create two strings, filename plain and filename binary.
 ``12`` ``````string filename_plain; string filename_binary;``````

 The value of these strings should equal the filename entered by the user, but with either \ plain" or \ binary" inserted immediately before the \."

string user_input;
cin >> user_input;

filename_plain = user_input;
filename_binary = user_input;

filename_plain.insert(filename_plain.find("\.") - 1, "\plain");
filename_binary.insert(filename_binary.find("\.") - 1, "\plain");

Using http://www.cplusplus.com/reference/string/string/find/ and http://www.cplusplus.com/reference/string/string/insert/

 ``1234567891011121314151617181920212223242526`` ``````// Example program #include #include using namespace std; int main() { string filename_plain; string filename_binary; cout << "Enter path (MUST contain a \. in it somewhere: "; string user_input; cin >> user_input; filename_plain = user_input; filename_binary = user_input; filename_plain.insert(filename_plain.find("\.") -1 , "\\plain"); filename_binary.insert(filename_binary.find("\.") -1 , "\\binary"); cout << filename_plain << '\n' << filename_binary; } ``````