The purpose of this lab is to familiarize you with the C++ process of parsing and file input/output through the basics of the fstream library. The getline function will be used to manipulate large pieces of data into progressively smaller chunks. Together with the stringstream function, you can swap back and forth to 'tokenize' a large line of input and control where each piece goes.

Your job is to write a program that takes an expected input file named "input.txt" of exact format:

(int), (int), (int)
(string)
(int), (int), (int)
(string)
(int), (int), (int)
(string)
(int), (int), (int)
(string)
(int), (int), (int)
(string)

Your program should then sum the ints of each line and output the immediately following line's string, that many times, seperated by commas such that:

1,2,3 ham

becomes:

ham,ham,ham,ham,ham,ham

NOTE: you may add a trailing comma to the end of the line if that is easier for you.

You might want to use a stringstream for data-handling. Recall that the getline function allows you to set a delimiter, but it only returns string values.

You may also find the atoi() and .c_str() functions useful.

Your final output format should not be the console. Instead, your program should open a second file and write your output to a file named "output.txt" which should be five lines of comma-separated words.

Do not use namespace std.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.