9. (Inventory) Create an ASCII file with the following data, or use the shipped.
ID: 3706035 • Letter: 9
Question
9. (Inventory) Create an ASCII file with the following data, or use the shipped.dat file available on this book's Web site. The headings aren't part of the file but indicate what the data represents. Tracking Number D50625 First Name James Janet Bill Diane Helen Shipped Date 04/12/11 Part Number 74444 75255 74477 74470 75155 Last Name Lehoff Lezar McHenry Kaiser Richardson NapTime Company Rotech Rotech Rotech Rotech 04/1211 D60752 04/12/11 04/12/11 04/12/11 D40295 D23745 D50892 The format of each line in the file is identical, with fixed-length fields defined as follows: Field Position Starting Col. No. Ending Col. No. Field Name Field Length Shipped Date Tracking Number 12 Part Number First Name Last Name Compan 8 6 17 26 35 48 64 2 31 39 51 10 14 6 Using this data file, write a C++ program that reads the file and produces a report listing the shipped date, part number, first name, last name, and company name.Explanation / Answer
As per your requirement the below one is solution please follow it step by step
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
ifstream fp;
string line;
string details[6];
int col;
fp.open("shipped.dat", ios::in);
while(!fp.eof())
{
getline(fp, line);
stringstream ss(line);
col = 0;
while(ss >> details[col])
col++;
cout<<details[0]<<" "<<details[2]<<" "<<details[3]<<" "<<details[4]<<" "<<details[5]<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.