Sample C++ Programs
- average.C
- mult.C (multiplication using addition)
- fastmult.C (better algorithm for multiplication)
- more.C (count number of characters and lines in a file)
- merge.C (merge sort)
- grade.C
- grade2.C
- gcd.C (Euclid's algorithm)
- fib.C (Fibonacci numbers)
- fact.C (factorial)
- exp.C (exponentiation using multiplication)
- commute.C (weird behavior from C++ compiler)
- cin.C (more weird C++)
- temp.C (convert temperatures)
- sqrt.C (compute square roots using Newton's method)
- sphere.C (compute distance between cities)
- prime.C (check if a number is prime)
- prime2.C (faster but probabilistic way)
- prime3.C (avoid stupid C++ behavior in case of overflow)
- pp.C (understanding call-by-value and call-by-reference)
- pp2.C (evaluating expressions with side-effects)
- ref.C (example of pass-by-reference)
- oddeven.C (lots of functions)
- 319-1.C (Problem 1, Page 319)
- 319-2.C (Problem 2, Page 319)
- 320-4.C (Problem 4, Page 320)
- rob99.C (Rob. page 99)
- void.C (converting value-returning functions to void functions)
- side.C (bad style, side-effects, value-returning)
- sc.C (understanding scope)
- life.C (understanding life time and scope)
- object.C (understanding the concept of objects)
- telephone.C (Problem 4, Page 500)
- calendar.C (Problem 3, Page 383)
sabry@cs.uoregon.edu