Your main weapon in organising your data is classes: a class is an object that represents an element of your program. You name it, give it variables and functions, and then create instances of it in your program. The class is responsible for all of its data and can prevent other classes from accessing it.
class foo
{
public:
int iAmAPublicVariable; // <---This variable can be accessed by anyone who has access to an instance of the class
private:
int iAmAPrivateVariable; // <---- This variable can be accessed only from within the class itself.
};
One good technique to control access to your class data is through the use of Getters and Setters. So...
class foo
{
public:
int getImportantData();
void setImportantData(int );
private:
int importantData;
};
int foo::getImportantData()
{
//here I could put some validation to make sure that it's ok to give out importantData;
return importantData; //this will return a copy of importantData, so the original is still safe within the class
}
void foo::setImportantData(int newData)
{
//here I could put some validation to make sure that it's ok to overwrite importantData;
importantData = newData;
}
With this setup the only way that importantData can be accessed is through the get and set methods, and so the class has ultimate control over what happens to it.
Classes should be the foundation of your program; if you've got a huge amount of variables then look at what they're for and what functions use them, and try to break the process down into discrete areas of functionality. Then create classes that represent these areas and give them the variables and methods they need. Your code should end up being smaller, easier to understand, more stable, easier to debug, more reusable, and a better representation of whatever it is you're trying to model.