Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that you have the following statements: ofstream outfile; double distanc

ID: 3682414 • Letter: S

Question

Suppose that you have the following statements: ofstream outfile; double distance = 375; double speed = 58; double travelTime; Write C++ statements to do the following: a. Open the file travel.dat using the variable outfile. b. Write the statement to format your output to two decimal places in fixed form. c. Write the values of the variables day, distance, and speed in the file travel.dat. d. Calculate and write the travelTime in the file travel.dat. e. Which header files are needed to process the information in (a) to (d)?

Explanation / Answer

c++ program:

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
   double distance=375,speed=58;
ofstream outfile;
outfile.open ("travel.dat");
outfile <<"Distance="<<distance<<" ";
outfile <<"Speed="<<speed<<" ";
outfile.precision(3);
outfile <<"TravelTime="<<distance/speed<<" ";
outfile.close();
return 0;
}

travel.dat file:

Distance=375 Speed=58 TravelTime=6.47

a &d need #include <fstream> header file.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote