Hi,
I am writing a program that allows to keep track of some racing records and to do this I need to be able to save objects on a external file and then load them with next startup of the program. As I am just a beginner I need your help to do so.
I did some research read about persistence and serialization. Kinda know the concept and implementation, however I'm not sure. I dont exactly know how to preserve the pointers and pointees and just pull it off.
I have two classes, driver and team class, I want to save their objects on an external file to load it on the next use. Please help.
driver.h
#ifndef DRIVER.H
#def DRIVER.H
#include "team.h"
class CDriver
{
private:
int driver_id;
char fname[20];
char lname[20];
short unsigned int new_point_system;
short unsigned int old_point_system;
short unsigned int place_point_system;
unsigned int driver_championships;
unsigned int last_racepoints;
bool hide_driver;
bool reserve_driver;
CTeam* pTeam;
public:
//-------------------------------constructors------------------------------------------------
CDriver();
CDriver(int theDriver_id, char theFname[], char theLname[], unsigned int theDriver_championships, bool theReserve_driver);
//-------------------------------destructors-------------------------------------------------
~Cdriver();
~CDriver(int theDriver_id, char theFname[], char theLname[], unsigned int theDriver_championships, bool theReserve_driver);
//-------------------------------methods-----------------------------------------------------
void setDriver_id(int theDriver_id); //set id number of the driver, id comes assigned
int getDriver_id();
void setFname(char theFname[]); //sets the first name of the driver
char* getFname(); //returns the first name of the driver
void setLname(char theLname[]); //sets the last name of the driver
char* getLname(); //returns the last name of the driver
char* getTeam_name(CTeam* pTeam); //outputs the name of the team
void addNew_system_points(int finished_place); //adding points to new base system
int getNew_system_points(); //displaying the points of new base system
void addOld_system_points(int finished_place); //adding points to old base system
int getOld_system_points(); //displaying the points of old base system
void addPlace_system_points(int finished_place); //adding points to place base system
int getPlace_system_points(); //displaying the points of place based system, function mailnly used for charts, records, etc.
void setDriver_status(bool theHide_driver); //sets if the driver's career is true or false (if still driving or nor)
bool getDriver_status(); //outputs if true or false
void setReserve_status(bool theReserve_driver); //sets if the driver's career is true or false (if beeing reserve drivaer or not)
bool getReserve_status(); //outputs if true or false
void addChampionship(bool driver_championship); //increments the driver championships count
int getChampionship();
void setLast_racepoints(int points); //sets the value for last race points, used in team class
int getLast_racepoints();
};
#endif
team.h
#ifndef TEAM.H
#def TEAM.H
#include "driver.h"
class CTeam
{
private:
int team_id
char team_name[50];
char car_name[20];
unsigned int constuctor_championships;
unsigned int constructor_points;
CDriver* pDriver1, pDriver2, pDriver3, pDriver4;
public:
//----------------------------------constructors----------------------------------------------------
CTeam();
CTeam(int theTeam_id, char theTeam_name[], char theCar_name[], unsigned int theConstructor_championships, unsigned int theConstructor_points, CDriver* thepDriver1, CDriver* thepDriver2);
//----------------------------------destructors-----------------------------------------------------
~CTeam();
~CTeam(int theTeam_id, char theTeam_name[], char theCar_name[], unsigned int theConstructor_championships, unsigned int theConstructor_points, CDriver* thepDriver1, CDriver* thepDriver2)
//----------------------------------methods---------------------------------------------------------
void setTeam_id(int theTeam_id); //set id number of the team, id comes assigned
int getTeam_id();
void setTeam_name(char theTeam_name[]); //sets the name of the team
char* getTeam_name(); //returns the name of the team
void setCar_name(char theCar_name[]); //sets the name of the car
char* getCar_name(); //returns the name of the car
void addConstructor_championships(bool first_place); //adding a constructor champ count
int getConstructor_championships();
void addConstructor_points(CDriver* pDriver1, CDriver* pDriver2); //adding a constructor champ count
int getConstructor_points();
};
#enddif
I dont have the main done as yet, as I want to make sutre that I have the save/load part done.
thx for help