To solve the integral
\[
I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{x^2 \cos x}{1 + e^x} \, dx,
\]
we can use the property of definite integrals and the substitution \( x \to -x \).
### Step 1: Substitute \( x \) with \( -x \)
We start by substituting \( x \) with \( -x \):
\[
I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{(-x)^2 \cos(-x)}{1 + e^{-x}} \, (-dx).
\]
Since \( (-x)^2 = x^2 \) and \( \cos(-x) = \cos x \), we can rewrite the integral as:
\[
I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{x^2 \cos x}{1 + \frac{1}{e^x}} \, dx.
\]
### Step 2: Simplify the integral
We can simplify the denominator:
\[
1 + e^{-x} = \frac{e^x + 1}{e^x}.
\]
Thus, we have:
\[
I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{x^2 \cos x \cdot e^x}{e^x + 1} \, dx.
\]
### Step 3: Combine the two expressions for \( I \)
Now we have two expressions for \( I \):
1. \( I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{x^2 \cos x}{1 + e^x} \, dx \)
2. \( I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{x^2 \cos x \cdot e^x}{e^x + 1} \, dx \)
Adding these two equations gives:
\[
2I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} x^2 \cos x \left( \frac{1}{1 + e^x} + \frac{e^x}{e^x + 1} \right) \, dx.
\]
### Step 4: Simplify the expression inside the integral
Notice that:
\[
\frac{1}{1 + e^x} + \frac{e^x}{e^x + 1} = \frac{1 + e^x}{1 + e^x} = 1.
\]
Thus, we have:
\[
2I = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} x^2 \cos x \, dx.
\]
### Step 5: Evaluate the integral \( \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} x^2 \cos x \, dx \)
Now we need to evaluate:
\[
\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} x^2 \cos x \, dx.
\]
Using integration by parts, let:
- \( u = x^2 \) and \( dv = \cos x \, dx \)
- Then \( du = 2x \, dx \) and \( v = \sin x \)
Applying integration by parts:
\[
\int u \, dv = uv - \int v \, du,
\]
we get:
\[
\int x^2 \cos x \, dx = x^2 \sin x \bigg|_{-\frac{\pi}{2}}^{\frac{\pi}{2}} - \int \sin x \cdot 2x \, dx.
\]
Evaluating \( x^2 \sin x \) at the limits:
At \( x = \frac{\pi}{2} \):
\[
\left( \frac{\pi}{2} \right)^2 \cdot 1 = \frac{\pi^2}{4}.
\]
At \( x = -\frac{\pi}{2} \):
\[
\left( -\frac{\pi}{2} \right)^2 \cdot (-1) = -\frac{\pi^2}{4}.
\]
Thus,
\[
x^2 \sin x \bigg|_{-\frac{\pi}{2}}^{\frac{\pi}{2}} = \frac{\pi^2}{4} - \left(-\frac{\pi^2}{4}\right) = \frac{\pi^2}{2}.
\]
### Step 6: Evaluate the remaining integral
Now we need to evaluate:
\[
-2 \int \sin x \cdot x \, dx.
\]
Using integration by parts again:
Let \( u = x \) and \( dv = \sin x \, dx \), then \( du = dx \) and \( v = -\cos x \):
\[
\int x \sin x \, dx = -x \cos x + \int \cos x \, dx = -x \cos x + \sin x.
\]
Evaluating this from \( -\frac{\pi}{2} \) to \( \frac{\pi}{2} \):
At \( x = \frac{\pi}{2} \):
\[
-\frac{\pi}{2} \cdot 0 + 1 = 1.
\]
At \( x = -\frac{\pi}{2} \):
\[
-\left(-\frac{\pi}{2}\right) \cdot 0 - 1 = -1.
\]
Thus,
\[
\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} x \sin x \, dx = 1 - (-1) = 2.
\]
### Step 7: Combine results
Putting it all together:
\[
2I = \frac{\pi^2}{2} - 2 \cdot 2 = \frac{\pi^2}{2} - 4.
\]
So,
\[
I = \frac{\pi^2}{4} - 2.
\]
### Final Result
Thus, the value of the integral is:
\[
\boxed{\frac{\pi^2}{4} - 2}.
\]