C++ Programming Alaska cruise line offers 2 vacation packages. One for Cruise on
ID: 641235 • Letter: C
Question
C++ Programming
Alaska cruise line offers 2 vacation packages. One for Cruise only (cod c) and the other for cruise and land excursion. (Code I). The data for the ship is capture in a text file called ship.txt with the following layout Code c or I Passenger name, cruise ticket price land excursion price The land excursion will be there only for passengers with a code of I (That is a lower case L) Write a ? program to read the file and print individual passengers along with the total for cruise price and land excursion price. See attached output Text File Passenger name, Code cruise ticket price land excursion price Frank Sinatra, c 10000 Nancy Sinatra, c 10000 Jimmy Durante, 1 5000 7000 Rush Hathi, 1 3000 5000 John Doe, 1 6000 4000 Jane Doe, c 4000Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream in("ship.txt");
if(!in) {
cout << "Cannot open input file. ";
return 1;
}
char str[255];
while(in) {
in.getline(str, 255); // delim defaults to ' '
if(in) cout << str << endl;
}
in.close();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.