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

First Name Last Name 0 or more instances of a plant choice (1-5) and the number

ID: 3614827 • Letter: F

Question

First Name

Last Name

0 or more instances of a plant choice (1-5)
and the number of plants, followed by a zero.

The problem I am having is that not each line is the same so I can't figure out the right way to read it. For example, the first few lines of the file looks like:

JAMES SMITH 0
MARY JOHNSON 3 4 3 16 1 6 4 6 2 16 3 16 0
JOHN WILLIAMS 4 15 4 14 1 1 3 1 4 7 4 8 0
PATRICIA JONES 3 7 1 4 4 3 0
ROBERT BROWN 0
LINDA DAVIS 1 4 4 5 2 8 5 17 5 12 0
MICHAEL MILLER 2 3 2 19 4 16 5 2 5 17 0
BARBARA WILSON 2 1 0
WILLIAM MOORE 1 1 4 9 1 5 5 9 0
ELIZABETH TAYLOR 5 19 5 8 5 5 1 15 1 7 1 16 0


I am supposed to write a function that willreadboth the first and last names from any input file stream. I tried:

bool readData(istream &fin, string &fname, string &lname)
{
   fin >> fname >> lname;
  
   if(fin.good())
   {
       return true;
   }
   else
   {
       return false;
   }
}


but that didn't work. Does anyone have any suggestions or tips on writing a function that works for this input file. I eventually need to take the data and write it into the output file with the following format:

          JAMES          SMITH
                                            Total:                0.00
           MARY        JOHNSON
                             4            Petunias               11.80
                            16            Petunias               47.20
                             6          Carnations               29.70
                             6                Mums               53.70
                            16           Red Roses              207.20
                            16            Petunias               47.20
                                            Total:              396.80
           JOHN       WILLIAMS
                            15                Mums              134.25
                            14                Mums              125.30
                             1          Carnations                4.95
                             1            Petunias                2.95
                             7                Mums               62.65
                             8                Mums               71.60
                    

First Name

Last Name

0 or more instances of a plant choice (1-5)
and the number of plants, followed by a zero.

Explanation / Answer

please rate - thanks This should get you started! using namespace std; bool readData(istream &, string &, string &); int main() {string fname,lname; ifstream fin; bool data; int type,amt; fin.open("input.txt");          //open file if(fin.fail())            //is it ok?    { cout