I have a very big excel sheet(which I will be converting into .txt mode later on by copy-paste :D ) about name of movie, its male lead, its female lead, and the year of release.
Now I want my program to display the list according to user's choice (like if he wishes to see all the movies released in 2014 she/he shall get so) but the problem is that the file is too big and I have no idea how/what to do.
If the list would have been small I would have used a simple struct/class and saved the details... but the file is too big to manually add struct/class
Are you sure it's too big? Text files are small and memories are large. If you have 10k of data on each movie (and that's a lot) and you have details on 10,000 movies, that's still only 100MB.
But perhaps a better questions is "why not use a database?"
(which I will be converting into .txt mode later on by copy-paste :D )
*Facepalm* File -> Save As: Near the bottom of the save dialog box, under the text field where you fill in the file name will be a drop down box. Select either .tab or .csv for a plain text format.
+1 dhayden.
@ OP: The file is large now because Excel is an archival file format, enjoy the irony on that one. Once you have the data as plain text it will be much smaller.
When I said/wrote big excel sheet I meant it had huge database (i.e 1000 movies) I didn't meant about its size in mbs.... sorry for the confusion......
the problem is that I cant create a class for such big(by big I mean 1000 movies, 1000 actors, 1000 actress & 1000 years) file manually as I have a text file which goes somewhat like this
the problem is that I cant create a class for such big(by big I mean 1000 movies, 1000 actors, 1000 actress & 1000 years) file manually as I have a text file which goes somewhat like this
OK, I'm lost. That's not one giant class OP, that's four separate classes and one more to coallate them. Even if it was one giant class, why would the size be a problem?
Always remember that files extensions are arbitrary. They are just the part of the file name that Microsoft chose to use in order to decide what program a file should be opened with. The extension '.csv' is a plain text format, if you right click on the file resulting from my post above and select "Open With" -> "Notepad" you can see what I mean. You can even right click and rename the file to change it's extension if that makes you feel better, it won't make a functional difference.
As for sorting the data, you would just use a loop. That should have been one of the first things you covered in class.
As for sorting the data, you would just use a loop.
I suggest using std::sort(). The wrong sorting algorithm will make it all run too slow.
OP, this is really not that much data. Make your class and then write the code to populate it from the csv or (probably better) tab-delimited file that you create from the excel file. If possible, post a dozen rows or so of the file so we can see exactly what the data looks like.
Text is small. Code is small. Data is small. What's big is media (pictures, music and movies). You're dealing with a small amount of data.
Okay, make a class and write code to read a member from a stream. If you think you might need to write the file then create code to write to a stream also.
Write code to read read members from a file and populate a vector.
You can sort the vector using any key you like. As long as you use a fast sorting algorithm (like std::sort()) you should be able to sort a million or more of these very quickly (like less than 10 seconds).
Sounds like you need to
1. read each line from your txt file
2. tokenise it ( ie break it down to the various data parts )
3. use each token to construct a new object
4. put the objects in a container, map, vector array, whatever
5. process the array
As already indicated above one line is one object (instance) of the class. 1000 lines = 1000 objects, not a big deal.
Actually, if you manage the serialization (reading to/from the file) you can do even better than simple tokenizing. Either way, it's not a hugely difficult proposition.
class pokemon_data
{
int number;
string name;
string type;
public:
getdata();
};
and the data filler function (the function which will get data)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void pokemon_data::getdata()
{
char line[80];
ifstream fin("pok.txt", ios::in);
int count=0;
while(!fin.eof)// 1. reading each line from text file (as said by kemort)
{
//not pretty much sure what to do now but will try my best
fin.getline(line,80,' ');//I think this will definitely divide the excel table into different stuff
//pretty much sure that I am lost now...
}
}
Now what you do is:
1. check that is working OK by printing out each line to make sure the file is being read
2. tokenise each line, look that up in the online help here and use the sample as a guide