If asked does a undercover police officer have to tell he is a police officer?

No. An undercover officer, in the performance of his duties, is allowed to deceive you.

Edit: Any police officer is allowed to deceive you if investigating a crime. And they are not necessarily required to provide their name and badge number. If they are unformed, their name is generally on their shirt of jacket, so, it's up to the person asking to figure it out. The officer is in no way required to write it down for you or give you a business card.