Answer to Question #187518 in C++ for Jackie

Question #187518

Write a C++ program to report on a vacation trip by car. The program gets its input from a

text file named vacation.txt and writes its ouput to a report.txt file. The vacation.txt file

will contain a pair of numbers on each line. The first number is the number of miles

travelled along a particular route. The second number on the line is the time (in minutes)

that it took to travel that distance. The two numbers on each line are separated by spaces.

Here is an example of a vacation.txt file, but note well that it is only an example. Other

vacation.txt files might contain fewer or more lines, though you can assume that there is

always at least one line of data. Create several such files for testing your program.

5.3 5.5

12.0 10.5

52.5 61.0



1
Expert's answer
2021-04-30T05:39:18-0400
#include <iostream>
#include <fstream>


using namespace std;


int main()
{
    ifstream input;
    ofstream output;
    string buffer;
    input.open("vacation.txt");
    output.open("report.txt");
    if(input.is_open() && output.is_open())
    {
        while(getline(input, buffer))
            output << buffer << endl;
    }
    else
        exit(0);
    output.close();
    input.close();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS