Using classes to retrieve data

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


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). I am trying to write a program that will allow the user to enter a track number. The program will then output the entire track. For example

Track Number: 3
output:
2 0.3 0.1 0.9
8 0.6 0.8 0.7

I need to write the program using classes. I am trying to write a class: class tracks that will contain all of the tracks. The user should be able to call on the class to output the desired track. I am not quite sure how to approach this problem. Any suggestions would be greatly appreciated.
Hard time getting a reply, eh? Well, still, don't double post..

Which part do you find problematic? Are you unable to find where a track ends? Are you unable to decide what should be in that class?
could you do some think like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
class anyName{
 
         //idea:
         template<int num>
         struct track{
                 double numbers[num][4];

         };

         std::vector<track> allTracks;

}
@Aikon, no, you couldn't. In your code track<1> and track<2> are different types and cannot be stored in one vector.
It's true

but well he could use a vector of vectors of strings

1
2
3
4
5
6
7
8
9

typedef std::vector<std::string> track;

class anyName{


         std::vector< track > allTracks;

};
closed account (zb0S216C)
Considering that the file has thousands of numerical values, it would be smart not to allocate them on the stack, otherwise, you're asking for a stack-overflow. It would be better to dynamically allocate a block of memory to store the extracted data. A vector my be useful. As for the class, I would recommend something like this:

1
2
3
4
5
6
7
class Track
{
    public:
        double _line[ 3 ][ 4 ];
};

vector < Track > tracks;

I'm not going to tell you how to do it, as it's your assignment, not mine. That code should get you going, at least.

Wazzak
Last edited on
Topic archived. No new replies allowed.