In this paper we construct certain mock modular forms of weight 1/2 whose Fourier coefficients are given in terms of cycle integrals of the modular $j$-function. Their shadows are weakly holomorphic forms of weight 3/2. These new mock modular forms occur as holomorphic parts of weakly harmonic Maass forms. We also construct a generalized mock modular form of weight 1/2 having a real quadratic class number times a regulator as a Fourier coefficient. As an application of these forms we study holomorphic modular integrals of weight 2 whose rational period functions have poles at certain real quadratic integers. The Fourier coefficients of these modular integrals are given in terms of cycle integrals of modular functions. Such a modular integral can be interpreted in terms of a Shimura-type lift of a mock modular form of weight 1/2 and yields a real quadratic analogue of a Borcherds product.