Where does the factor of $x$ come from in this formula for expectation value? 
Given the normalised ground-state wave-function: $$\Psi(x, t)=\begin{cases}  \sqrt\frac{2}{d}\cos(\frac{\pi x}{d})e^\frac{-i\hbar\pi^2t}{2md^2}  & \ \lvert x\rvert<\frac{d}{2}, \\ 0 & \text{otherwise.} \end{cases}$$
  for a particle of mass $m$ confined to potential well of form:
  $$V(x)=\begin{cases}  0  & \ \lvert x\rvert<\frac{d}{2}, \\ \infty & \text{otherwise.} \end{cases}$$
  show that $\langle x\rangle =0$

I'm told that the correct answer is $$\langle x\rangle=\int_{-\frac{d}{2}}^\frac{d}{2} x\frac{2}{d}\cos^2\biggl(\frac{\pi x}{d}\biggr)\mathrm{d}x=0$$ as the integrand is an odd function. But I don't understand why the integrand takes this form. Could some please explain it to me? I would like to know where the $x$ comes from? Thanks.
Expectation of $x$ is the position of the particle and by my logic this is $\langle x\rangle = \int\psi^*(x)\psi(x)dx=\int_{-\frac{d}{2}}^\frac{d}{2} \frac{2}{d}\cos^2\biggl(\frac{\pi x}{d}\biggr)\mathrm{d}x$ basically without the factor $x$ as shown above which was my reason for asking about it.  
 A: The definition of the expectation value of an operator A is
\begin{equation}
\langle A\rangle=\int{\psi^* (x) A(x) \psi (x) dx}
\end{equation}
(because it represents "the value of the variable" $A(x)$ times "the probability of being in that configuration" $P(x)=\psi^* (x) \psi (x)$)
and for the particular case of the expectation value of the position operator
\begin{equation}
\langle x\rangle=\int{x \psi^* (x) \psi (x) dx}
\end{equation}
that is the origin of your extra $x$.
A: $$\int_{-\frac{d}{2}}^{\frac{d}{2}}\psi^*(x)\psi(x)dx$$
is the probability of finding particle between $-\frac{d}{2}$ and $\frac{d}{2}$.
Expectation value is :
$$\langle x\rangle=\langle \psi|\hat{x}|\psi\rangle$$
$|\psi\rangle$ is the summation of probability amplitude times given basis kets
$$|\psi\rangle = \sum_i c_i |{e_i}\rangle$$
$$c_i=\langle{e_i}|\psi\rangle$$ 
probability is ${c_i}^2=({c_i}^*)c_i=(\langle{e_i}|\psi\rangle^*)\langle{e_i}|\psi\rangle=\langle\psi|{e_i}\rangle\langle{e_i}|\psi\rangle$.
if you want expectation value, you need "value times probability". An example is casting a dice, expectation value is 1*1/6+2*1/6+3*1/6+4*1/6+5*1/6+6*1/6.
back to the particle in a box, you need $x_i \times \langle \psi|x_i\rangle\langle x_i|\psi\rangle$, $|x_i\rangle$ is the state of the particle located at $x_i$. you need to add up all "x * prob of the particle located at x" from -d/2 to d/2. since position is continuous, you need to do integration.
