Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

===============

Year

Cargo Capacity

Royal Queen

2015

160

Ocean King

2013

110

2 Cargo Ships

Total Cargo Capability 270

Cruise Ship ================

Year

# of Passengers

Carnival

2016

1600

Royal Prince

2012

2000

Royal Princess

2010

2100

Royal Caribbean

2016

1600

4 Cruise Ships

Total # of Passengers 7300

/* This is what is completed so far. Please help:

#include

#include

#include

#include

#include

using namespace std;

int main()

{

int ship_type[10];

string line;

char fname[20];

char lname[20];

int year[10];

int capacity[10];

int Cap =0;

int i =0;

int count = 0;

int c =0;

ifstream infile;

infile.open("shipRecords.txt");

if(!infile)

{

cout<<"File does not exist"<

return 1;

}

//while(!infile.eof())

while(getline(infile, line))

{

infile>>ship_type[i]>>fname[i]>>lname[i]>>year[i]>>capacity[i];

i++;

count++;

}

for(i=0;i

{

if(ship_type[i]==1)

{

c++;

//Cap = Cap + capacity[i];

cout<

cout<

//cout<

}

if(ship_type[i]==2)

{

c++;

//Cap = Cap + capacity[i];

cout<

cout<

//cout<

}

} //cout<

infile.close();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Which file ( s ) do you need to encrypt? Select all that apply

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago