Expected Values and CDF I have a piecewise function and I have to find the expected value of $x$ and the cdf. If I have three different pieces for the function, how do I find the expected value? Do I integrate each piece over its domain, then divide each answer by the length of its specific domain, and add them up?
And for the cdf, if I have to find the cdf of the middle piece, do I have to integrate the first piece over its domain, and add it to the cdf of the middle piece, which is integrated over the domain lower limit to some value $x$?
What if we have two random variables? For the expected value of $y$, I have to find the marginal density of $y$ and then find the expected value?

The Expectation:
For the expectation, it is easier than that. Let $X$ have density function $f(x)$. Then 
$$E(X)=\int_{-\infty}^\infty xf(x)\,dx.\tag{1}$$
At the level of Formula (1), no distinction is made between piecewise defined functions and those that are not. 
It is when do the actual integration that we have to take the definition of the function into account. As an example, let $f(x)$ be piecewise defined as follows. Note that there are $5$ pieces.  
$f(x)=0$ for $x\lt 0$;
$f(x)=\frac{x}{6}$ for $0\le x\lt 2$;
$f(x)=\frac{1}{2}-\frac{x}{12}$ for $2\le x\lt 4$;
$f(x)=\frac{1}{6}$ for $4\le x\lt 5$;
and $f(x)=0$ for $x\ge 5$. 
To find the expectation, we use Formula (1). To evaluate, it is best to split the integral into integration over $5$ subintervals. The subintervals $(-\infty,0)$ and $([5,\infty)$ contribute nothing, so we won't write down a sum of $5$ integrals. But the middle three intervals are live. We get
$$E(X)=\int_0^2 x\cdot\frac{x}{6}\,dx+\int_2^4 x\left(\frac{1}{2}-\frac{x}{12}\right)\,dx+\int_4^5 x\cdot \frac{1}{6}\,dx.$$
In the post. there is a reference to integrating each piece over its domain, dividing by length and adding up. That does not seem to me a good description of what went on above. It looks more like a possible description of finding the expectation of a sum of random variables.
We could view the above random variable as such a sum. That is, we could find random variable $U$, $V$, and $W$ which are non-zero respectively in the intervals $[0,2]$. $[2,4]$, and $[4,5]$, such that our $X$ is a weighted sum of $U$, $V$, and $W$. But the way the density function of $X$ was described, such an approach would involve extra work.
The cdf: In the OP there is a question about the cdf of the middle piece. There is a single cdf $F(x)$. It just so happens that $F(x)$, like the density function, is given by different expressions in different parts of the world. For example, let us see what the cdf $F(x)$ is for $2\le x\lt 4$. 
In general, we have
$$F(x)=\int_{-\infty}^x f(t)\,dt.$$
In our particular case, for $x$ between $2$ and $4$, we have
$$F(x)= \int_0^2 \frac{t}{6}\,dt+\int_2^x \left(\frac{1}{2}-\frac{t}{12}\right)\,dt.$$
This happens to simplify to $\frac{x}{2}-\frac{x^2}{24}-\frac{1}{2}$.
Two random variables: 
The questions on two random variables are a little too unspecific to answer. If joint density is given by a piecewise defined function, then calculation of marginal densities could involve breaking up an integral into parts.
As to the expectation of a random variable $Y$, again one would need an explicit question. If we have the joint density function, it is often best to find $E(Y)$ by a direct two-variable integration, instead of going through the marginal density.
