A cylinder containing $1 \mathrm{~kg}$ of ammonia has an externally loaded piston. Initially the ammonia is at $2 \mathrm{MPa}$ and $180^{\circ} \mathrm{C}$. It is now cooled to saturated vapor at $40^{\circ} \mathrm{C}$ and then further cooled to $20^{\circ} \mathrm{C},$ at which point the quality is $50 \% .$ Find the total work and the heat transfer for the process, assuming a piecewise linear variation of $P$ versus $V$.