Question: Learn how to use getline() function and many string member functions to process input file one line at a time and display data in groups.
Learn how to use getline() function and many string member functions to process input file one line at a time and display data in groups.
Read ship records from the input file shipRecords.txt
| 1 "Royal Queen" 2015 160 2 "Carnival" 2016 1600 1 "Ocean King" 2013 110 2 "Royal Prince" 2012 2000 2 "Royal Princess" 2010 2100 2 "Royal Caribbean" 2016 1600 |
There are 4 columns in the input file. You can assume that there is no data error in the input file. The number of blank characters between two adjacent data can be any.
| Column | Comments | |
| 1st | Ship type | 1 - cargo ship; 2 - cruise ship. |
| 2nd | Name of the ship | It is enclosed by a pair of double quotes |
| 3rd | The year of the ship | 4 digits |
| 4th | Cargo capacity or number of passengers | The number indicates the cargo capacity for cargo ship, and number of passengers for cruise ship. |
Display a report like the following table. All columns in the report must be lined up properly. The first column Ship Name must be left-adjusted, and the other two columns right-adjusted.
| Cargo Ship ===============
Cruise Ship ================
| ||||||||||||||||||||||||||||||||||||
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
