Problems assigning value to item in Struct

Hey guys, I am having issues on my homework.
I am suppose to write a program which has two structs. One struct Data, and the other OLDNEW which consists of two variables. The Data struct uses the OLDNEW struct. The program is suppose to open a .txt file, skip the first 14 lines then assign values to the Data.New. Then it is suppose to do some calculations with that data then populate the Data.Old with the current Data.New values. Then the program is suppose to output certain values from the Data struct to Distance.txt file, then update the Data.New values by reading them from the next line of the .txt file.

My program opens the .txt file and assigns the data.New values fine the first time, but after that doesn't seem to update the data.New values again.
I couldn't find any tutorials on structs using other structs, so hopefully you guys can help me.

Here's what it displayed when i had it cout all the old and new values in the Data struct

 ``` Time.New - distance.New - distance.Old - x.New - x.Old - y.New - y.Old - z.New - z.Old 0 0 0 0 0 0 0 0 0 420188.0938 6366333 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.1875 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.3125 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.4062 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.5 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.5938 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.6875 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.8125 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 420188.9062 0 6366333 -1641966.625 -1641966.625 -3664747.25 -3664747.25 4940017 4940017 ```

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158`` ``````#include #include #include #include #include using namespace std; struct OldNew { float Old, New; }; struct Data { OldNew Time,x,y,z,distance,speed; }; void SkipHeaderInfo(ifstream &Traj, int count); void ReadData(ifstream &Traj,Data &data); void WriteDistance(Data data, ofstream &dist); void WriteSpeed(Data data, ofstream &spd); void Distance(Data &data); void UpdateOldStruct(Data &data); void Speed(Data &data); float msTokmh(float max_speed); void MaxSpeed(Data data, float &max_speed, float &TimeOfMaxSpeed); void TimeinTraffice(Data data, float &TimeInTraffic); void Report(float max_speed, float TimeOfMaxSpeed,float Traveltime,float TimeInTraffic,ofstream &rpt); int main() { ifstream Traj; ofstream dist; ofstream spd; string Speed_name="Speed.txt"; ofstream rpt; string Report_name="Report.txt"; Data data; float max_speed=0,TimeOfMaxSpeed=0,TimeInTraffic=0,Traveltime=0; int count=0; data.Time.Old=0; data.Time.New=0; data.distance.Old=0; data.distance.New=0; data.x.New=0; data.x.Old=0; data.y.New=0; data.y.Old=0; data.z.New=0; data.z.Old=0; for(int i=0; i<100; i++) { Traj.open("VehicleTrajectory.txt"); SkipHeaderInfo(Traj, count); count++; ReadData(Traj, data); //fills New spot in struct OldNew Distance(data); //calculates distance from x,y and z UpdateOldStruct(data); //fills old spot in struct OldNew Traj.close(); WriteDistance(data, dist); } WriteSpeed(data, spd); Speed(data); msTokmh(max_speed); MaxSpeed(data, max_speed, TimeOfMaxSpeed); TimeinTraffice(data, TimeInTraffic); Report(max_speed, TimeOfMaxSpeed, Traveltime, TimeInTraffic, rpt); } void SkipHeaderInfo(ifstream &Traj, int count) // This function skips past the first lines of the input file { const int max_skip = 13; for(int i=0; i<(max_skip + count); i++) { Traj.ignore(200,'\n'); } } void ReadData(ifstream &Traj,Data &data) // This function reads one line from the input data file, at the current position of the input file stream and // updates Data.xxx.New { Traj>> data.Time.New; Traj>> data.x.New; Traj>> data.y.New; Traj>> data.z.New; } void UpdateOldStruct(Data &data) //This function updates the values //of xx.Old by replacing them by xx.New { data.Time.Old+= data.Time.New; data.distance.Old+= data.distance.New; data.x.Old= data.x.New; data.y.Old= data.y.New; data.z.Old= data.z.New; } void Distance(Data &data) //This function computes and updates the accumulated distance traveled. { data.distance.New= sqrt(pow((data.x.New - data.x.Old),2) + pow((data.y.New - data.y.Old),2) + pow((data.z.New - data.z.Old),2)); } void WriteDistance(Data data, ofstream &dist) //This function writes one line to the âDistance.txtâ { string Distance_name="Distance.txt"; dist.open(Distance_name.c_str()); for(int i=0; i<100; i++) { dist << data.Time.Old<< " " << data.distance.Old << endl; } dist.close(); } void WriteSpeed(Data data, ofstream &spd) //This function writes one line to the âSpeed.txtâ { } void Speed(Data &data) //This function computes and updates the speed of vehicle by numerically differentiating the âDistanceâ { } float msTokmh(float max_speed) //This function converts (m/s) to (km/h) and returns the value { int KMH=0; return KMH; } void MaxSpeed(Data data, float &max_speed, float &TimeOfMaxSpeed) //This function updates the maximum speed (max_speed) //and its time of occurrence (TimeOfMaxSpeed). { } void TimeinTraffice(Data data, float &TimeInTraffic) //This function updates the TimeInTraffic //which is the duration of time for which //the speed of the vehicle < 0.05 m/s { } void Report(float max_speed, float TimeOfMaxSpeed,float Traveltime,float TimeInTraffic,ofstream &rpt) // This function generates the âReport.txtâ //Note that an output file //stream object (rpt) is passed //to this function as an argument. { } ``````

Here is a sample of the first few lines in the VehicleTrajectory.txt file:

 ``` Project: Vahid_14Jun12 Program: Inertial Explorer Version 8.30.2105 Profile: GeoVahidXYZ Source: GPS Epochs(Smoothed TC Combined) Datum: WGS84, (processing datum) Master 1: Name E1_V3_Ba, Status ENABLED Antenna height 0.000 m, to L1-PC (Generic) Position 51 04 47.83266, -114 08 01.36056, 1118.502 m (WGS84, Ellipsoidal hgt) Remote: Antenna height 0.000 m, to L1-PC (Generic) GPSTime X-ECEF Y-ECEF Z-ECEF Longitude Latitude H-Ell (sec) (m) (m) (m) (Deg) (Deg) (m) 420188.10 -1641966.612 -3664747.324 4940016.963 -114.134460451 51.0803178892 1097.715 420188.20 -1641966.612 -3664747.324 4940016.963 -114.134460453 51.0803178928 1097.715 420188.30 -1641966.612 -3664747.323 4940016.963 -114.134460453 51.0803178986 1097.714 420188.40 -1641966.611 -3664747.322 4940016.963 -114.134460449 51.0803179075 1097.714 420188.50 -1641966.611 -3664747.323 4940016.967 -114.134460438 51.0803179249 1097.717 420188.60 -1641966.614 -3664747.325 4940016.961 -114.134460462 51.0803178703 1097.715 420188.70 -1641966.613 -3664747.324 4940016.962 -114.134460461 51.0803178783 1097.714 420188.80 -1641966.612 -3664747.323 4940016.962 -114.134460458 51.0803178915 1097.714 420188.90 -1641966.611 -3664747.321 4940016.963 -114.134460451 51.0803179102 1097.713 420189.00 -1641966.610 -3664747.321 4940016.966 -114.134460440 51.0803179318 1097.715 420189.10 -1641966.610 -3664747.322 4940016.964 -114.134460440 51.0803179188 1097.714 420189.20 -1641966.610 -3664747.322 4940016.963 -114.134460440 51.0803179156 1097.713 420189.30 -1641966.610 -3664747.320 4940016.963 -114.134460443 51.0803179202 1097.712 420189.40 -1641966.609 -3664747.317 4940016.962 -114.134460446 51.0803179366 1097.709 420189.50 -1641966.607 -3664747.316 4940016.965 -114.134460433 51.0803179695 1097.711 420189.60 -1641966.605 -3664747.316 4940016.965 -114.134460404 51.0803179760 1097.709 420189.70 -1641966.605 -3664747.316 4940016.963 -114.134460404 51.0803179651 1097.709 420189.80 -1641966.606 -3664747.317 4940016.962 -114.134460414 51.0803179452 1097.708 420189.90 -1641966.607 -3664747.317 4940016.960 -114.134460420 51.0803179378 1097.708 420190.00 -1641966.606 -3664747.317 4940016.962 -114.134460411 51.0803179437 1097.709 420190.10 -1641966.605 -3664747.316 4940016.963 -114.134460409 51.0803179632 1097.708 420190.20 -1641966.605 -3664747.315 4940016.962 -114.134460407 51.0803179634 1097.707 420190.30 -1641966.605 -3664747.315 4940016.961 -114.134460408 51.0803179606 1097.706 420190.40 -1641966.605 -3664747.315 4940016.960 -114.134460414 51.0803179563 1097.706 420190.50 -1641966.606 -3664747.316 4940016.962 -114.134460409 51.0803179534 1097.708 420190.60 -1641966.605 -3664747.316 4940016.962 -114.134460406 51.0803179585 1097.708 420190.70 -1641966.605 -3664747.316 4940016.961 -114.134460402 51.0803179562 1097.707 420190.80 -1641966.605 -3664747.315 4940016.960 -114.134460406 51.0803179534 1097.706 ```
Topic archived. No new replies allowed.