Home › Forums › C Programming › C++ Data files
- This topic has 1 reply, 2 voices, and was last updated 14 years, 8 months ago by GWILouisaxwzkla.
- AuthorPosts
- 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. “
thank you#include “stdafx.h”
#include
#include
#includeusing namespace std;
int main()
{
//Declare and initialize objectsint 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;rocket1.open(filename.c_str());
if(rocket1.fail())
{
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";}
rocket1.close();
report.close();return 0;
}
- March 5, 2010 at 11:23 pm #3641GWILouisaxwzklaParticipant
Could you post your data file?
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.