Exercises 11.13 Exercises
The exercises in this chapter make use of the following datafiles.
Data: poem.txtTwo roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth; Then took the other, as just as fair, And having perhaps the better claim Because it was grassy and wanted wear, Though as for that the passing there Had worn them really about the same, And both that morning equally lay In leaves no step had trodden black. Oh, I kept the first for another day! Yet knowing how way leads on to way I doubted if I should ever come back. I shall be telling this with a sigh Somewhere ages and ages hence: Two roads diverged in a wood, and I, I took the one less traveled by, And that has made all the difference.
Data: class.txtAlex Jones 9 3.4 14 Beth Hamilton 12 3.7 18 Charles White 11 3.5 16 Daniel Kim 10 3.8 16 Ethan Brooks 11 3.9 17 Faith Flemmings 10 3.0 15 Gigi Guerro 9 3.2 14
2.
3.
First Last Grade GPA Age
Hidden code will open the file and read past some number of the lines (determined by the input).
You should add code to continue reading from
inFile and print the first name from the next line in the file. (It is safe to use >> for your input even though the hidden code uses getline).
4.
First Last Grade GPA Age
Hidden code will open the file and read past some number of the lines (determined by the input). You should add code to continue reading from
inFile and print the first name and age (with a space between) of the next line in the file. (It is safe to use >> for your input even though the hidden code uses getline).
5.
First Last Grade GPA Age
Hidden code will open the file and read past some number of the lines (determined by the input). You should add code to continue reading from
inFile and print out the next three first names with a space after each. (It is safe to use >> for your input even though the hidden code uses getline).
Hint 1.
6.
First Last Grade GPA Age
Hidden code will open the file and read past some number of the lines. You should add code to continue reading from
inFile and print out the average of the GPA values for all the rest of the lines. (It is safe to use >> for your input even though the hidden code uses getline).
Note that there is a newline after the last piece of data (the line that starts with
Gigi and ends with 14). You will likely need to check infile for an error after attempting to read in the data for each line before you count the line or do anything with it.
Hint 1.
You have attempted of activities on this page.
