I assume you're primarily interested in whether or not you should capitalise these words. "Sir" and "Madam" usually function as someone's title (as in your example, when addressing someone thus), and as such I would capitalise these words. If you're referring generically to "ladies" or "gentlemen" then you shouldn't capitalise (for example, "This washroom is for ladies only").
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
AnonymousI want you to do this, Sir.I want to do this, sir. ('Sir' should not be capitalised.)
If the name of the person can be used to replace the sir or ma'am, it should be capitalized. If no name is known to the reader or writer, then either lower or upper case is fine (and debated often, lol)