Home Forums C Programming C++ Data files

Viewing 1 reply thread
  • Author
    • #2243

      Hi everyone, I am a student at MCC in CT and i need help getting a file named rocket1.dat to be read and then i need to determine the time at which that rocket is at its peak altitude, my HW questions read as follows ” Assume that the rocket1.dat file contains an inital line that specifies the number of actual lines of data that follow. Write a program that reads each of these dat and determines the time at which the rocket begins falling back to Earth. “
      thank you

      #include “stdafx.h”


      using namespace std;

      int main()
      //Declare and initialize objects

      int number_of_items, k;
      double time, velocity, acceleration, altitude,
      previous_time, previous_altitude;
      string filename;
      ifstream rocket1;
      ofstream report;

      cout << "Enter name of the input file ";
      cin >> filename;


      cerr << "Error opening input file " << filename << endl;
      exit (1);

      report.open (“rocket1.dat”);

      rocket1 >> number_of_items;

      rocket1 >> time >> altitude;

      for (k = 1; k < number_of_items; k++)
      rocket1 >> time >> altitude ;

      if (!(rocket1 >= number_of_items) || number_of_items == 0)
      cout << "no valid data in file" << filename << endl;
      exit (1);

      while (altitude>=previous_altitude &&!rocket1.eof())
      previous_altitude = altitude;
      previous_time= time;
      rocket1 >> time >> altitude >> velocity >> acceleration;

      if (altitude < previous_altitude)
      cout << "time at which the rocket begins to fall is between "
      << previous_time << " seconds and " << time << "seconds n";else
      cout << "no decrease in altiutde detected in data file. n";}

      return 0;


    • #3641

      Could you post your data file?

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.