  We derive self-similar solutions including cooling and heating in an Einstein
de-Sitter universe, and investigate the effects of cooling and heating on the
gas density and temperature distributions. We assume that the cooling rate has
a power-law dependence on the gas density and temperature,
$\Lambda$$\propto$$\rho^{A}T^{B}$, and the heating rate is
$\Gamma$$\propto$$\rho T$. The values of $A$ and $B$ are chosen by requiring
that the cooling time is proportional to the Hubble time in order to obtain
similarity solutions. In the region where the cooling rate is greater than the
heating rate, a cooling inflow is established, and the gas is compressed and
heats up. Because the compression is greater in the inner region than in the
outer region, the temperature becomes an increasing profile toward the center.
In particular, when a large infall velocity is produced due to an enormous
energy loss, the slope of the density approaches a value that depends on $A$,
$B$, and the velocity slope, and the slope of the temperature approaches $-$1.
On the other hand, in the region where the heating rate is greater than the
cooling rate, the infall velocity is suppressed, compression of the gas is
weakened, and the gas cools down. The slope of the density becomes shallow due
to suppression of the contraction, and the temperature is lower than that
without heating. The self-similar collapse presented here gives insights to the
effects of cooling and heating on the gas distributions in galaxies and
clusters of galaxies.
