I've recently started learning about C++ classes and how object-oriented programming is advantageous. I'm now working on rewriting one of my ongoing projects into classes. What I'm looking for is just some general advice on what is generally the better method of dealing with classes and vectors. Before I ask my question, it might help if I explain what I'm tying to achieve:
I have been writing a data editor for an ice hockey management game named Eastside Hockey Manager 2007 (the game's developers have released the structs of each of the database files in order to help people modify the database). I have written an editor that will read in data from a CSV file and will update two of the game's database files based upon this data. This means that I can create a list of player contractual changes in the CSV file and my editor will apply these changes to the game's database.
Each row of data from the CSV file is loaded into the following struct (the SI_DATE mentioned below is itself a struct that stores the day of the year, the year and whether it is a leap year):
struct CONTRACT {
long StaffID;
string FirstName;
string SecondName;
SI_DATE DateOfBirth;
string ClubContractedName;
long ClubContractedID;
string ClubPlayingName;
long ClubPlayingID;
SI_DATE DateJoinedClub;
SI_DATE ContractExpiresClub;
long EstimatedWage;
long EstimatedValue;
};
I have created a vector of this struct to store each line/entry from the CSV file. My editor then carries out various processes on the CONTRACT struct (e.g. checking that the data is valid, calculating the ClubContractedID number based upon the ClubContractedName, etc). The data from the struct is written to two binary database files (because the game's data in relation to players/staff is split across two files) which each have their own different structs.
So in essence I'm dealing with three different structs (one for my CSV update file and two different structs for each of the target database files).
My aim is to write a single STAFF class which deals with the updating of the two database files (because both files relate to staff/player data). I had planned for the class to read in the CSV file, process the data and then write it to the two database files. At present, I have created as a private member of the class a vector of the CONTRACT struct.
My question is whether I have taken the correct approach in creating a struct vector within a class. Is this generally the correct method/approach? Or ought I change my CONTRACT struct to a class and then create a vector of this class?
My concern is that by creating a vector of structs within a class, I'm missing the whole point of having a class.
If I were to go down the route of having a vector of the class, then when it comes to writing each iteration of the class to the target files, presumably the loop would look something like this:
For each iteration of the vector<myClass>: Open file -> write iteration -> close file
Thus with each iteration of the vector, I would be repeatedly opening and closing the file. Would this be a problem/undesirable?
I hope I've made some sense! And thank you in advance.

New Topic/Question
Reply



MultiQuote







|