It is difficult to pass source code because there are innumerable presumptions that would have to be made. Image format, layout of the same in memory ... surely you will use a library to open the image, which has direct impact on any example code.
A pseudo-algorithm that I suggest is as follows:
1) transform each color channel (r, g, b) into a floating point value from 0 to 1 (just divide by 255)
2) manipulate the value by some formula, such as the following example
double r_contraste = 1.0 / (1.0 + exp(-(18.0 * r - 9.0)));
You can play with constants to see different results.
3) Turn the result back to 0..255, and save / display the image.
You can try other formulas of the family "sigmoide function" (it has in Wikipedia).
Changing the contrast is to create a transfer curve between the original value and the final value, trying to keep the extremes (0 turns 0, 1 becomes 1). The contrast is increased by creating an "S" curve, which increases contrast in midtones at the expense of contrast at the ends.)
Changing the brightness is adding or decreasing a constant. Changing the exposure is equivalent to multiplying the value by a constant. In any case, transformed values below 0 or above should be truncated.