I'll show you how to count connected components using repeated DFS calls. Run DFS from any unvisited vertex. All vertices reached in that DFS call belong to the same component. You mark them all as visited, then find the next unvisited vertex and repeat.
Each DFS call discovers one complete component. Count how many times you call DFS. When there are no unvisited vertices left, you have found all components. The count equals the number of separate DFS calls you made.