Just a note on something I found out yesterday which I didn't previously know, ls has an option to hide backup files (those ending in ~):
Having said that, find is probably better in this case because it's easier to exclude object files, library files etc, as haertig described.
It may be that there are so many files found that xargs invoked multiple instances of wc, and then your total will be split. Also, some files may contain spaces in which case wc will think one file is two filenames and fail to count them. Therefore, this might be a little more robust:
find /path/to/code/dir -type f -regex ".*[c|cpp|h]" -print0 |xargs -0 cat |wc -l