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
#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;
}
Comments
Leave a comment