Cooperative Output Regulation with Applications to Multi-Agent Systems