Your spaces function is wrong, it should cout << ' '; and not cout << n;.
As for diagram 2, think about it. The first row has 0 spaces, then n numbers. The second row has 1 space, then n - 1 numbers. The third row has 2 spaces, then n - 2 numbers. Etc.
For diagram 3, the last row has 0 spaces. The second to last row has 1 space. The third to last row has 2 spaces. Etc.