Part 1

Part 2

Part 3

The procedure for deriving the equation for the discharging capacitor is similar, though you have to use i = -dq/dt because dq/dt is negative for a discharging capacitor, by definition.