1

I am trying to write a program in c++. 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.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

Can you be more specific about your question?
Try to do it yourself, and ask us if you get stuck with something.

You can create a class Track, and all the tracks maybe contained into a vector of Tracks, or you can also create a class called TrackCollection which will handle all the tracks and all the operations needed for them.

Edited by 3bdelhakeem: n/a

0

is that example the exact format of the file? Or are the track numbers that you put in just comments?

If you're just separating the blocks with a line break, you can use getline to read each line into a string, but check each one and start a new block whenever you find a line with nothing on it (size = 0).

Also, if you only need to display the block on request, you don't have to worry about converting the numbers or anything.

0

If the blocks are in sequential order with no unused numbers then just store then in a vector or array and use the index value as the block number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.