Home › Forums › C Programming › C++ Data files
- This topic has 1 reply, 2 voices, and was last updated 13 years ago by GWILouisaxwzkla.
- March 3, 2010 at 1:47 am #2243Norbert43WParticipant
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. “
using namespace std;
//Declare and initialize objects
int number_of_items, k;
double time, velocity, acceleration, altitude,
cout << "Enter name of the input file ";
cin >> filename;
cerr << "Error opening input file " << filename << endl;
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;
while (altitude>=previous_altitude &&!rocket1.eof())
previous_altitude = altitude;
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";}
- March 5, 2010 at 11:23 pm #3641GWILouisaxwzklaParticipant
Could you post your data file?
- The forum ‘C Programming’ is closed to new topics and replies.