Page 73 - DCAP404 _Object Oriented Programming
P. 73

Object-oriented Programming




                    Notes          know about a function is two  ways – by defining  it before  you call  it or by specifying the
                                   function prototypes before you call it.

                                   3.7 Keywords


                                   Function: The best way to develop and maintain a large program is to divide it into several
                                   smaller program modules of which are more manageable than the original program. Modules
                                   are written in C++ as classes and functions. A function is invoked by a function call. The function
                                   call mentions the function by name and provides information that the called function needs to
                                   perform its task.
                                   Function Declaration: Statement that declares a function’s name, return type, number and type
                                   of its arguments.

                                   Function Overloading:  In C++, it is possible to define several function with the same name,
                                   performing different actions. The functions must only differ in their argument lists. Otherwise,
                                   function overloading is the process of using the same name for two or more functions.

                                   Function Prototype: A function prototype declares the return-type of the function that declares
                                   the number, the types and order of the parameters, the function expects to receive. The function
                                   prototype enables the compiler to verify that functions are called correctly.
                                   Inline Function: A function definition such that each call to the function is, in effect, replaced by
                                   the statements that define the function.
                                   Reference: Alias name of a variable.
                                   Return: The C++ keyword return is one of several means we use to exit a function. When the
                                   return 0 statement is used at the end of main function, the value 0 indicates that the program has
                                   terminated successfully or returns NULL value to the operating system.
                                   Scope: The program part(s) in which a function or a variable is accessible.

                                   3.8 Review Questions


                                   1.  What is function prototyping? Why is it necessary? When is it not necessary?
                                   2.  What is purpose of inline function?
                                   3.  Differentiate between the following:
                                       (a)  void main()
                                       (b)  int main()

                                       (c)  int main(int argn, char argv[])
                                   4.  In which cases will declare a member function to be friend?
                                   5.  Write a program that  uses overloaded  member functions  for converting  temperature
                                       from Celsius to Kelvin scale.
                                   6.  To calculate the area of circle, rectangle and triangle using function overloading.
                                   7.  Do inline functions improve performance?

                                   8.  How can inline functions help with the tradeoff of safety vs. speed?








          66                                LOVELY PROFESSIONAL UNIVERSITY
   68   69   70   71   72   73   74   75   76   77   78