/* lab06.cpp 7/6/2005 CIS 150 David G. Klick Solution to lab #6 (functions). */ #include using std::cout; void displayName(); double average(double x1, double x2, double x3); int fib(int n); int magicBox(int n1, int n2=0, int n3=0); double magicBox(double n1, double n2=1.0, double n3=1.0); int main(void) { int i; displayName(); cout << average(14.1, 7.8, 9.3) << '\n'; for (i=0; i<=10; i++) { cout << "Fibonacci(" << i << ") = " << fib(i) << '\n'; } cout << magicBox(3) << '\n'; cout << magicBox(3, 4) << '\n'; cout << magicBox(3, 4, 5) << '\n'; cout << magicBox(3.0) << '\n'; cout << magicBox(3.0, 4.0) << '\n'; cout << magicBox(3.0, 4.0, 5.0) << '\n'; return 0; } void displayName() { cout << "Dave\n"; } double average(double x1, double x2, double x3) { return (x1 + x2 + x3) / 3.0; } int fib(int n) { if (n < 0) return 0; if (n < 2) return n; return fib(n-1) + fib(n-2); } int magicBox(int n1, int n2, int n3) { return n1 + n2 + n3; } double magicBox(double n1, double n2, double n3) { return n1 * n2 * n3; }