How the consumer price index (CPI) is constructed

How the consumer price index (CPI) is constructed and why it is an imperfect measurement of the cost of living.