Does string theory explain the existence of 3 generations of quarks/leptons? I am wondering whether string theory explains the existence of 3 families of quarks/leptons or not. I have a very limited understanding of string theory, as of now, and I have a mathematical background, so I am asking this question here, so that people with better knowledge of string theory might answer it.
There is a related discussion:
Origin of lepton/quark generations?
and one of users, Andrew Holzner, quoting wikipedia, gave an explanation that CP violation requires at least 3 generations (and there are in that discussion a number of other explanations). This sounds like a reasonable explanation, but my question is more from the point of view of string theory.
 A: Part 1: 
The branch of string theory which actually tries to match experiment is called string phenomenology. The state of the art in string phenomenology is that, starting from different forms of string theory (heterotic string theory, M-theory, F-theory...), it is possible to define space-time geometries, arrangements of branes, background fluxes... such that strings in the defined environment will behave qualitatively like the particles of the standard model. 
The underlying reason why there are three generations in such a model really depends on the nature of its construction. 
In an M-theory model such as those championed by Gordon Kane, the particles in a given generation correspond to states of M2-branes located at specific singular points in the compactification manifold, so the number of such generations is just the number of such singular points. 
In a heterotic model such as those that Brian Greene has written about, it's more complicated. The topology of the compactification manifold permits a specific number of light left-handed fermionic states, and another number of light right-handed fermionic states; then left and right combine to make heavy states; and the generations correspond to the light handed fermionic states that are left over, that didn't pair up with anything. The original numbers of handed light states equal two of the "Hodge numbers" characterizing the topology, so in this case, there are three (or however many) generations because the difference between those two numbers equals three. 
In still other models, the reason for there being three generations would be something else again. 
Part 2:
Since the state of the art in string phenomenology is still just at the level of searching the vast "landscape" of possibilities for models that match experiment, any current explanation for "why three generations?" is going to lead back to contingent properties of the model that happens to be successful, like those that I sketched in Part 1 of this answer. 
In evolutionary biology, they speak of proximate causes and ultimate causes. Why does a flower bend to follow the sun? The proximate cause is the set of molecules that it happens to be made of. The ultimate cause is natural selection - that's the reason why it's made of molecules that react like that, and not in some other way. 
We can look at explanations like those from Part 1 as proximate causes of there being three generations. What are the possible ultimate causes?
One possibility is anthropic. Maybe we live in an eternally inflating universe where different string vacua are realized in different regions, and maybe e.g. the cosmological consequences of the CP violation that requires at least three generations in order to occur, helps make life, or even just stars, possible. 
Another possibility is that it is just random. In genomic evolution, there's a lot of neutral evolution, features of the genome which are just contingent, which don't help the organism survive, but also don't hinder it, so those features aren't eliminated by natural selection. Anthropics can't determine everything, and maybe three generations is just a brute fact about how our corner of reality turned out.
Still another possibility is that it's the product of the natural dynamics of string theory. String phenomenology fixes the geometry of the extra dimensions (etc) and studies the results, but in fact you can have quantum tunneling between different geometries, and there may have been a lot of that in the early universe. The 2007 paper "Triadophilia" speculates that three-generation heterotic manifolds may be favored in this way. 
A: I will address the title question:

does string theory explain the existence of 3 generations of quarks leptons

because of the word "explain".
Physics is about measurements and observations and mathematical models which not only fit the measurements and observations but also have predictive power. Otherwise the model is just a map, not a physics theory.
Newtonian gravitational  theory assumes the 1/r^2 behavior and using classical mechanics with its laws generates the very successful  gravitational model which can predict most astronomical data within errors. Deviations from Newtonian mechanics were predicted by the theory of General Relativity, and the validation of the predictions established GR as an undelying theory from which Newtonian gravity emerges.
The Standard Model of particle physics with its Lagrangian formulation is the analogue of the Newtonian gravitational theory: a large number of measurements and observations went into the SM  to build up the structure, and its predictions have been mostly validated up to now. Candidates for string theory models are where GR was before its validation by not before seen data. 
String theories can accommodate  the group structure in the Lagrangian of the standard model, so there is no problem in envisaging a string theory model, also, and very important, string theories are the only candidate theories that can have quantization of gravity naturally. They also demand supersymmetry to do their magic. In this sense super symmetry is predicted by candidate string theory models, and if supersymmetry  is found at LHC it will be like the validation of GR by predicting the  anomalous perihelion advance of the planet Mercury without any arbitrary parameters
As was stated in the comments there are too many possible theories, and nature/data have to choose for us which is the one that fits the data, in the same way that nature chose for us the standard model lagrangian.
So "explain" is not a good verb, a physical theory fits the data and makes predictions for future measurements.
Now if physics ever reaches the point to have a mathematical Theory of Everything, from a few postulates and few measurement input for constants, then it might be legitimate to say that the TOE "explains" everything. Certainly no physics theory is at that point , more so String Theories which are at the research level.
A: The official string theory website says this:

Theoretical physics has not explained why there are three generations of particles that make up matter. Maybe string theory will come up with an answer for this. 

That's really where it stands. In fact, there's another question on physics SE here, where one of the answers says

The question as to why there are exactly three generations is still an open problem, even in string theory.

Another answer at the same question says

All in all, to answer questions like the number of generations in the SM, the masses of the fermions, etc you need a candidate for a complete theory at high energies and the answers will depend on this candidate. String theory is considered to be the most successful framework for this job and string models do indeed make concrete predictions about (among other things) the number of generations we should be observing. Unfortunately, there are too many models (vaccua) to choose from and no obvious way to make the choice.

To sum up: we have absolutely no idea why there are three generations, even in string theory. Like @CuriousOne said in the comments, string theory has too many possible models of reality with no way to select which one to use for string theory to really explain anything.
Note: 
In the comments below this answer, @CuriousOne made a good point: all of the quoted statements make it sound like this is one of the only problems with string theory. This is not true. There is no experimental evidence for string theory. Describing why there are 3 generations of quarks/leptons is the least of string theory's problems.
