Saturday, January 7, 2012

Multifunction Program


MULTIFUNCTION PROGRAM
One advantage of the C++ language is the use of a function which can behave like a traditional function or a procedure. A function may call one more functions and so on. There is no restriction in C++ for calling the number of functions in a program. It is advisable to break a complex problem into smaller and easily manageable parts and then define a function. Control will be transferred from the calling portion of a program to the called function block. If the called function is executed successfully, then control will be transferred back to the calling portion of a program. In this type of multifunction program, transfer of control between the calling portion and a called function block is always in overhead.
    For example, a multifunction program segment is shown below.
            function1( )
           {
                  void function2 ( );
                  void function4(); // function declaration



                  
                  function2();


 
                  function4()


                  
           }
          function2()
          }
                void function3(); // function declaration


                
           function3 ();


               
         }
        function3()
        {    


                   
       }
       function4()
      {


                  
      }

PROGRAM
A program to demonstrate the transfer of control between the multifunction program.
    // multifunction declaration
   #include <iostream.h>
   void main (void)
   {
       void funct1 (void) ;
        cout << “ inside the main \n” ;
        cout << “ Komputer \n” ;
        funct1 ( ) ;
   }
   void funct1 (void)
   {
       void funct2 (void) ; / / function declaration
       cout << “ inside the function 1 \n” ;
       cout << “ kompu \n” ;
       funct2 ( ) ;
   }
   void funct2 (void)
   {
       cout << “ inside the function 2 \n” ;
       cout << kompu \n” ;
   }
Output of the above program
    inside the main
   komputer
   inside the function 1
   kompu
   inside the function 2
   kompu

2 comments: