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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <cmath>

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.