Question: IN C++ - Starter code given Read the file inFile.txt . Using inFile.txt write the file out.txt but formatted correctly inFile.txt How out.txt should look

IN C++ - Starter code given

Read the file inFile.txt. Using inFile.txt write the file out.txt but formatted correctly

inFile.txt

IN C++ - Starter code given Read the file inFile.txt. Using inFile.txt

How out.txt should look like

write the file out.txt but formatted correctly inFile.txt How out.txt should look

Note:

like Note: inFile.txt to copy: 1 $43.50 12/23/2016 01:12:10 The Dark Tower

inFile.txt to copy:

1 $43.50 12/23/2016 01:12:10 The Dark Tower

2 $23.15 10/05/2014 03:15:10 Lord of the Rings Return of the King

3 $32.34 05/01/2019 01:20:59 Ender's Game

4 $21.50 06/07/2019 10:40:59 Clash of Kings

5 $34.32 09/13/2018 12:12:59 Feast for Crows

6 $28.50 11/18/2002 07:30:40 Hitchhiker's Guide to the Galaxy

What I have so far:

#include

#include

#include

#include

//Using namespace std

using namespace std;

//Main Function

int main(int argc, char *argv[])

{

//Constant declarations

const int ID_WIDTH = 4;

const int TITLE_WIDTH = 27;

const int PRICE_WIDTH = 12;

const int TIME_WIDTH = 33;

//Declaring book id

int id;

//Opwning the input file

ifstream inFS;

inFS.open(argv[1]);

//OPening the output file

ofstream outFS;

outFS.open(argv[2]);

//Setting the locale to US

inFS.imbue(locale("en_US.UTF-8"));

outFS.imbue(locale("en_US.UTF-8"));

//Header

outFS

//While reading in ID succeeds

while(inFS >> id)

{

//Price declared for every iteration of the loop

long double price;

//New title declared for every iteration of the loop

string title;

//Reading the price from file

inFS >> get_money(price);

//Error statement if price is read wrong

if (inFS.fail())

{

cout

}

//Reading in the time and date from the file

tm t = {};

inFS >> get_time(&t, "%d/%m/%Y %H:%M:%S");

//Clearing the stream

inFS.clear();

//Getting the title string using getLine()

getline(inFS, title);

//If the title length is longer than 25 characters, replace character 23-25 with "..."

if(title.length() > TITLE_WIDTH)

{

title.erase(TITLE_WIDTH), string::npos);

title.replace(TITLE_WIDTH, string::npos, 3, .);

}

cout

}

//Closing infile

inFS.close();

//Closing outFile

outFS.close();

return 0;

}

1 $43.50 12/23/2016 01:12:10 The Dark Tower 2 $23.15 10/05/2014 03:15:10 Lord of the Rings Return of the King 3 $32.34 05/01/2019 01:20:59 Ender's Game 4 $21.50 06/07/2019 10:40:59 Clash of Kings 5 $34.32 09/13/2018 12:12:59 Feast for Crows 6 $28.50 11/18/2002 07:30:40 Hitchhiker's Guide to the Galaxy ID 1 2 3 Price Time Title 43.50 Sun 23 Dec 2016 01:12:10 AM EST The Dark Tower 23.15 Sun 05 Oct 2014 01:12:10 AM EST Lord of the Rings Ret... 32.34 Sun 01 May 2019 01:12:10 AM EST Ender's Game 21.50 Sun 07 Jun 2019 01:12:10 AM EST Clash of Kings 34.32 Sun 13 Sep 2018 01:12:10 AM EST Feast for Crows 28.50 Sun 18 Nov 2002 01:12:10 AM EST Hitchhiker's Guide to... 4 5 6 The ID column can be set to a width of 4 characters The Title column can be set to a width of 27 characters The Price column can be set to a width of 12 characters The Time column can be set to a width of 33 characters

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!