Complete the short exact sequence $0\to \mathbb Z\to A\to Z_n \to 0$ I want to find all possible $A$ in the following SES:

$$0\to \mathbb Z\to A\to Z_n \to 0$$

I know by structure theorem of finite generated abelian groups, $A\cong \mathbb Z\oplus \mathbb Z_d$. Then how can we find the relation between $d$ and $n$? What are two maps in the middle?
Since this is an exercise in Hatcher's book at the beginning section of homology theory, a solution without using Ext will be much better.
 A: Since I don't know what we can assume, let's classify all those extensions by brute force. Since it's a problem in a chapter about homology, $A$ is probably meant to be abelian but let's go ahead and do the general case. I'll outline a proof in the form of exercises. At the end, I outline the relationship between the explicit constructions and the cohomological argument.
First, name the arrows in the exact sequence: $i: \mathbf Z \rightarrow A$ and $p: A \rightarrow \mathbf Z_n$.
Let $a = i(1)$ and let $b \in A$ such that $p(b) = 1$.

Exercise 1: $a$ and $b$ generate $A$

So, $$A = \langle a, b : \text{ some relations we need to find}\rangle$$

Exercise 2: $b^n = a^r$ and $bab^{-1} = a^s$ for some integers $r$ and $s$.

Hint: What are the images of $bab^{-1}$ and $b^n$ under $p$?.

Exercise 3: $a^{s^n} = a$ and thus $s = \pm 1$.

Hint: use the relations we have so far. For the last part, recall that $a$ is the generator of a copy of $\mathbf Z$ in $A$.

Exercise 4: Suppose $s = 1$. Let $t = \gcd(n, r)$ and write $$1 = \alpha \frac n t + \beta \frac r t,$$ for suitable $\alpha, \beta \in \mathbf Z$. Then, $$A \cong \mathbf Z \times \mathbf Z_t,$$ with $i': \mathbf Z \rightarrow \mathbf Z \times \mathbf Z_t$ and $p': \mathbf Z \times \mathbf Z_t \rightarrow \mathbf Z_n$ given by $$i'(1) = (n/t,-\beta)\\ p'(1,0) = \beta \\ p'(0,1) = n/t.$$

Hint (so it doesn't look like magic): $s = 1$ implies $A$ abelian and the relation $b^n = a^r$ can then be rewritten as $1 = (b^{n/t}a^{-r/t})^t$. In fact, $t$ is the order of $b^{n/t}a^{-r/t}$ in $A$. Show that $b^{n/t}a^{-r/t}$ and $b^{\beta}a^{\alpha}$ generate $A$ and consider the homomorphism $\varphi: \mathbf Z \times \mathbf Z_t \rightarrow A$ given by $\varphi(1,0) = b^{\beta}a^{\alpha}$ and $\varphi(0, 1)=b^{n/t}a^{-r/t}$. It sits in the commutative diagram
$\require{AMScd}$
\begin{CD}
0 @>>> \mathbf Z @>{i'}>> \mathbf Z \times \mathbf Z_t @>{p'}>> \mathbf Z_n @>>> 0\\
& @V{=\,}VV @VV{\varphi}V @VV{\, =}V \\
0 @>>> \mathbf Z @>>{i}> A @>>{p}> \mathbf Z_n @>>> 0\end{CD}

Exercise 5: Suppose $s = -1$. Then, $n$ is even, $r = 0$ and $$A \cong \mathbf Z \rtimes_\sigma \mathbf Z_n,$$ where $\sigma: \mathbf Z_n \rightarrow \operatorname{Aut}(\mathbf Z)$ is given by $\sigma(1)(1) = -1$. The maps $i': \mathbf Z \rightarrow \mathbf Z \rtimes \mathbf Z_n$ and $p': \mathbf Z \rtimes \mathbf Z_n \rightarrow \mathbf Z_n$ are given by $$i'(1) = (1,0)\\ p'(1,0) = 0 \\ p'(0,1) = 1.$$

Hint: in this case $ba^rb^{-1} = a^{-r}$ and $a^r = b^n$, so $r = 0$ and $b^n = 1$. Conclude that $A$ is isomorphic to $\mathbf Z \rtimes \mathbf Z_n$ and classify all homomorphisms $\mathbf Z_n \rightarrow \operatorname{Aut}(\mathbf Z)$. Note that $\mathbf Z$ has only two automorphisms and, by exercise 3, $n$ is even when $s = -1$.

What's going on in cohomological terms?
$\operatorname{Ext}(\mathbf Z_n, \mathbf Z)$ classifies the extensions of $\mathbf Z_n$ by $\mathbf Z$ as $\mathbf Z$-modules or, in other words, as abelian groups. To compute $\operatorname{Ext}(\mathbf Z_n, \mathbf Z)$, one would usually apply $\operatorname{Hom}(\cdot, \mathbf Z)$ to the "multiplication by $n$" sequence $$0 \rightarrow \mathbf Z \rightarrow \mathbf Z \rightarrow \mathbf Z_n \rightarrow 0$$ to get $\operatorname{Ext}(\mathbf Z_n, \mathbf Z) = \mathbf Z/n\mathbf Z$.  Exercise 4 makes this equality explicit. The class of $r$ in $\operatorname{Ext}(\mathbf Z_n, \mathbf Z) = \mathbf Z/n\mathbf Z$ corresponds to the extension $\mathbf Z \times \mathbf Z_t$ with maps $p'$ and $i'$ as in the statement of exercise 4.
Non-abelian group extensions of $\mathbf Z_n$ by $\mathbf Z$ are not detected by $\operatorname{Ext}(\mathbf Z_n, \mathbf Z) = H^2(\mathbf Z_n, \mathbf Z)$. To detect more general extensions, one could look, for example, at $H^3$ (see here). IMO Exercise 5 is a more down to earth way of treating this case.
A: This is a nice exercise for a beginning section of homology theory, since doing this without Ext will make you really appreciate the machinery homological algebra has to offer.
I do not think, that I will go through all details, but let us start:
First of all, we have the case $\mathbb Z_d = 0$ (one could refer to this as $d=1$), i.e. a short exact sequence
$$0 \to \mathbb Z \to \mathbb Z \to \mathbb Z_n \to 0.$$
Of course the first map is given by $\cdot m$ for some $m \in \mathbb Z$ and by looking at the cokernel, we get that $m = \pm n$. The second map is given by $1 \mapsto e$, where $e$ is co-prime to $n$.
The much more involved case is the case $d \geq 2$, i.e. where the summand $\mathbb Z_d$ actually occurs.
Call the first map $g: \mathbb Z \to \mathbb Z \oplus \mathbb Z_d$ and the second map $f: \mathbb Z \oplus \mathbb Z_d \to \mathbb Z_n$. Denote the kernel of $f$ by $K$. By exactness we get $K \cong \mathbb Z$.
Note that $f(0,n)=0$. $K$ is torsion free, but $(0,n) \in \mathbb Z \oplus \mathbb Z_d$ is of course torsion (annihilated by $d$), hence we have $(0,n)=(0,0)$, i.e. $d|n$.

So we have all possibilites for $A$, namely $A \in \{\mathbb Z \} \cup
\{\mathbb Z \oplus \mathbb Z_d ~ | ~ d \geq 2,d | n\}$.

We still have to figure out the maps in the second case:
Of course $g$ is given by $g(1) = (m,e)$ for some $m,e \in \mathbb Z, 0 \leq e <d$. Let us call the cokernel $C_{m,e}$.
$C_{m_e}$ is generated by $e_1=(1,0),e_2=(0,1)$ and we have relations $me_1+ee_2=0$ and $de_2=0$, thus $C_{m_e}$ is presented by $$\begin{pmatrix}m&0\\e&d\end{pmatrix}.$$ Upto multiplication in $SL_2(\mathbb Z)$, this should be equal to $$\begin{pmatrix}n&0\\0&1\end{pmatrix}$$, i.e. by looking at fitting ideals, we get that
$$md=\pm n ~~ \text{ and } ~~ (m,e,d)=(1).$$
Thus we have found all possibilities for $g$. To find $f$, note that we have the following commutative diagram of exact sequences:
$$\require{AMScd}
\begin{CD}
0 @>>> \mathbb Z^2 @>\begin{pmatrix}m&0\\e&d\end{pmatrix}>> \mathbb Z^2 @>>> C_{m,e} @>>>0\\
@VVV @VXVV @VVYV @VVV @VVV \\
0 @>>> \mathbb Z^2 @>>\begin{pmatrix}n&0\\0&1\end{pmatrix}> \mathbb Z^2 @>p>> \mathbb Z_n @>>>0
\end{CD}$$
, where $X$ and $Y$ are obtained via the algorithm to determine the Smith normal form.
The map $p \circ Y$ factors through $\mathbb Z \oplus \mathbb Z_d$ and the factorization is $f$.
