inputing data into classes

I have a file that contains thousands of numeric entries sorted into four columns. The structure of the data looks something like the following:

\\ {Energy, x-position, y-position, z-position}
3 0.2 0.5 6.2
4 0.1 0.6 6.2 //Track 1
2 0.8 0.5 0.6

2 0.6 0.5 0.4
1 0.8 0.4 2.1 //Track 2
2 0.5 0.4 2.4
4 0.6 0.8 2.5

2 0.3 0.1 0.9 //Track 3
8 0.6 0.8 0.7

The data is grouped into tracks where a new track starts after each line break as shown above (in the actual data there are thousands of tracks). Notice that each track has a varying number of lines. Each line contains four entries that correspond to Energy, x-position, y-position and z-position. I am trying to write a program that will take this data and sort it into a group of three classes using composition. The three classes will be written as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Step
{
public:
	float m_energy;
	float m_xpos;
	float m_ypos;
	float m_zpos;
}

class Tracks
{
	Step *m_steps;
	int m_num_steps;
}

class DB
{
	Tracks *m_tracks;
	int m_num_tracks;
}


The first class will contain the lines which are composed of energy, and the x,y and z positions. The second class (Tracks) will contain a collection of the lines which form the tracks. The final class (DB), the full data base class, will contain the entire data set which is the collection of the tracks. I am very new to object oriented programming so any ideas on how to approach this problem would be greatly appreciated.
Last edited on
Have you ever looked at a vector?
http://cplusplus.com/reference/stl/vector/

(they're dynamic containers of data =])

You could make a vector of class objects that hold the three individual data elements.

Topic archived. No new replies allowed.