Sams Teach Yourself C++ in 21 Days

(singke) #1
Organizing into Functions 135

5


Quiz ................................................................................................................



  1. What are the differences between the function prototype and the function
    definition?

  2. Do the names of parameters have to agree in the prototype, definition, and call to
    the function?

  3. If a function doesn’t return a value, how do you declare the function?

  4. If you don’t declare a return value, what type of return value is assumed?

  5. What is a local variable?

  6. What is scope?

  7. What is recursion?

  8. When should you use global variables?

  9. What is function overloading?


Exercises ........................................................................................................



  1. Write the prototype for a function named Perimeter(), which returns an unsigned
    long intand takes two parameters, both unsigned short ints.

  2. Write the definition of the function Perimeter()as described in Exercise 1. The
    two parameters represent the length and width of a rectangle. Have the function
    return the perimeter (twice the length plus twice the width).

  3. BUG BUSTERS:What is wrong with the function in the following code?
    #include
    void myFunc(unsigned short int x);
    int main()
    {
    unsigned short int x, y;
    y = myFunc(int);
    std::cout << “x: “ << x << “ y: “ << y << “\n”;
    return 0;
    }


void myFunc(unsigned short int x)
{
return (4*x);
}
4.BUG BUSTERS:What is wrong with the function in the following code?
#include <iostream>
int myFunc(unsigned short int x);
int main()
Free download pdf