Sine Wave generator with DAC
Read the Wikipedia article on sampling (the article focuses on conversion of analog to digital, you perform opposite converting digital samples to set of dots comprising the wave). Then take a piece of paper (or some drawing application software on your PC) and draw the period of the sine wave with timing on the X axis. Then divide the drawn sine wave onto the samples, and decide how many samples you want to have (= how smooth your wave will be).

Then you look into the datasheet of your components - DAC and processor, and identify if they actually can produce this sampling rate (generate proper analog voltage at the output of DAC within the sampling period you identified on your drawn sine graph).

In your example: you want 40 kHz sine wave with 50 points per period. This means sine wave will appear 40000 times within the second, thus 40000*50 samples per second must be output. It equals to 2 MHz sampling rate. With 25 samples per period you will have to use 1 MHz sampling rate, but the output sine wave will be more "edgy" per your definition.

In any case, your output will hardly be the ideal sine wave, it will be more or less the ladder. You will need to use electronic filters to smooth the wave at the specific chosen frequency (you set it to 40 kHz).