In the experiment, you can't initially see the coin because it's hidden in the wall behind the wall of the cup. Since this wall is opaque, the light rays from coins (by diffuse reflection) do not pass through.
When water is poured into one of the cups, the light rays from the coin are refracted as it passes from water to air.
Because of the refraction, these rays of light can now reach your eyes and you can see the image of the coin.
Now in the example of the partially submerged pencil we see that it looks crooked. In reality this is only an illusion, which occurs due to the refraction of light rays as they pass from water to air.
Because of refraction, images of submerged objects are distorted. A pool, for example, appears to be shallower than it actually is, and the legs of those in it appear shorter.