Page 1 of 2 12 LastLast
Results 1 to 12 of 13

Thread: funtions help (lecture)

  1. #1
    knowldge_hunter is offline Senior Member+
    Last Online
    19th February 2010 @ 12:52 AM
    Join Date
    26 Oct 2009
    Posts
    44
    Threads
    4
    Credits
    945
    Thanked: 1

    Default funtions help (lecture)

    aslmolikum

    i want to take lecture on FUNTIONS

    plz learn me ........

  2. #2
    Join Date
    24 Jun 2009
    Location
    Lahore
    Age
    33
    Posts
    220
    Threads
    9
    Thanked
    10

    Default

    very beautiful , very nice

  3. #3
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default

    Quote daniyaliqbal said: View Post
    very beautiful , very nice
    there is nothing nice about it,
    us ne aap ko question kia aur
    agar aap ans nahi de sakte to
    atleast post ko spam mat karo,

    and its not only you, i have seen many
    people doing this around, i think ITD
    should ban people like these...

    anyway lets get down to topic;

    Quote knowldge_hunter said: View Post
    aslmolikum

    i want to take lecture on FUNTIONS

    plz learn me ........


    bhai waise to mein recommend karta hoon
    k aap koi book parho lekin here is a tut:

    Code:
     Functions
    Now that you should have learned about variables, loops, and conditional statements it is time to learn about functions. You should have an idea of their uses as we have already use them and defined one in the guise of main. cin.get() is an example of a function. In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. 
    
    Functions that a programmer writes will generally require a prototype. Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four. 
    
    For example: 
     
    #include <cstdlib>   // Include rand()
    
    using namespace std; // Make rand() visible
    
    int a = rand(); // rand is a standard function that all compilers have
    Do not think that 'a' will change at random, it will be set to the value returned when the function is called, but it will not change again. 
    
    The general format for a prototype is simple: 
     
    return-type function_name ( arg_type arg1, ..., arg_type argN ); 
    There can be more than one argument passed to a function or none at all (where the parentheses are empty), and it does not have to return a value. Functions that do not return values have a return type of void. Lets look at a function prototype: 
     
    int mult ( int x, int y );
    This prototype specifies that the function mult will accept two arguments, both integers, and that it will return an integer. Do not forget the trailing semi-colon. Without it, the compiler will probably think that you are trying to write the actual definition of the function. 
    
    When the programmer actually defines the function, it will begin with the prototype, minus the semi-colon. Then there should always be a block with the code that the function is to execute, just as you would write it for the main function. Any of the arguments passed to the function can be used as if they were declared in the block. Finally, end it all with a cherry and a closing brace. Okay, maybe not a cherry. 
    
    Lets look at an example program: 
     
    #include <iostream>
    
    using namespace std;
    
    int mult ( int x, int y );
    
    int main()
    {
      int x;
      int y;
      
      cout<<"Please input two numbers to be multiplied: ";
      cin>> x >> y;
      cin.ignore();
      cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
      cin.get();
    }
    
    int mult ( int x, int y )
    {
      return x * y;
    }
    This program begins with the only necessary include file and a directive to make the std namespace visible. Everything in the standard headers is inside of the std namespace and not visible to our programs unless we make them so. Next is the prototype of the function. Notice that it has the final semi-colon! The main function returns an integer, which you should always have to conform to the standard. You should not have trouble understanding the input and output functions. It is fine to use cin to input to variables as the program does. But when typing in the numbers, be sure to separate them by a space so that cin can tell them apart and put them in the right variables. 
    
    Notice how cout actually outputs what appears to be the mult function. What is really happening is cout is printing the value returned by mult, not mult itself. The result would be the same as if we had use this print instead 
     
    cout<<"The product of your two numbers is "<< x * y <<"\n";
    The mult function is actually defined below main. Due to its prototype being above main, the compiler still recognizes it as being defined, and so the compiler will not give an error about mult being undefined. As long as the prototype is present, a function can be used even if there is no definition. However, the code cannot be run without a definition even though it will compile. The prototype and definition can be combined into one also. If mult were defined before it is used, we could do away with the prototype because the definition can act as a prototype as well. 
    
    Return is the keyword used to force the function to return a value. Note that it is possible to have a function that returns no value. If a function returns void, the retun statement is valid, but only if it does not have an expression. In otherwords, for a function that returns void, the statement "return;" is legal, but redundant. 
    
    The most important functional (Pun semi-intended) question is why do we need a function? Functions have many uses. For example, a programmer may have a block of code that he has repeated forty times throughout the program. A function to execute that code would save a great deal of space, and it would also make the program more readable. Also, having only one copy of the code makes it easier to make changes. Would you rather make forty little changes scattered all throughout a potentially large program, or one change to the function body? So would I. 
    
    Another reason for functions is to break down a complex program into logical parts. For example, take a menu program that runs complex code when a menu choice is selected. The program would probably best be served by making functions for each of the actual menu choices, and then breaking down the complex tasks into smaller, more manageable tasks, which could be in their own functions. In this way, a program can be designed that makes sense when read. And has a structure that is easier to understand quickly. The worst programs usually only have the required function, main, and fill it with pages of jumbled code.
     
    Note: This tut is copy and paste from cprogramming.com
    its not mine and i dont get any credits for this tut.
    so all credits to cprogramming for providing such a
    nice tut.

    -Saif

  4. #4
    knowldge_hunter is offline Senior Member+
    Last Online
    19th February 2010 @ 12:52 AM
    Join Date
    26 Oct 2009
    Posts
    44
    Threads
    4
    Credits
    945
    Thanked: 1

    Default

    functions sey related kuch progrmas hain ageryeh solve ker key samjha dein kiuon key jo oper apne smjha wo mujy clear nahi hua

  5. #5
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default

    Quote knowldge_hunter said: View Post
    functions sey related kuch progrmas hain ageryeh solve ker key samjha dein kiuon key jo oper apne smjha wo mujy clear nahi hua

    sure post em here i will try my best...

  6. #6
    knowldge_hunter is offline Senior Member+
    Last Online
    19th February 2010 @ 12:52 AM
    Join Date
    26 Oct 2009
    Posts
    44
    Threads
    4
    Credits
    945
    Thanked: 1

    Default

    write function that will allow floating point number to be raised to an integer power y=x (power n) where y& x are flaoting point& n is an integer variables


    write program using max- function that calculates the max of five numbers enterd



    write a program of four function calculatotr using four function sum () subtraction() division() and product()......

  7. #7
    SufyanGujar is offline Senior Member+
    Last Online
    29th December 2010 @ 10:59 PM
    Join Date
    10 Oct 2009
    Location
    England, UK
    Age
    34
    Posts
    157
    Threads
    10
    Credits
    0
    Thanked
    7

    Default

    Quote knowldge_hunter said: View Post
    write function that will allow floating point number to be raised to an integer power y=x (power n) where y& x are flaoting point& n is an integer variables


    write program using max- function that calculates the max of five numbers enterd



    write a program of four function calculatotr using four function sum () subtraction() division() and product()......
    1) OK now u got me confused... can u break it down in simple words?
    i am kinda not on dat level to understand all dat, as i aint doing a
    programming course its just one of my hobbies...

    2) somethn like this:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main () {
        int var1, var2,var3;
        cin >> var1 >> var2;
    var3 = max(var1,var2);
    
    cout << var3;
    
    
    system("PAUSE");
    
      return 0;
    }

  8. #8
    Ganxtr's Avatar
    Ganxtr is offline Advance Member
    Last Online
    5th July 2019 @ 09:15 AM
    Join Date
    15 Nov 2009
    Location
    CRIME CITY
    Posts
    1,740
    Threads
    18
    Credits
    83
    Thanked
    100

    Default

    Great
    your thread is very nice, thanks 4 sharing with us!

  9. #9
    *Tamraiz*'s Avatar
    *Tamraiz* is offline Advance Member+
    Last Online
    29th August 2022 @ 08:08 AM
    Join Date
    26 Nov 2010
    Location
    Sialkot
    Gender
    Male
    Posts
    16,583
    Threads
    1051
    Credits
    1,207
    Thanked
    1738

    Default

    Nice

  10. #10
    Shining Star's Avatar
    Shining Star is offline Senior Member+
    Last Online
    25th November 2011 @ 10:38 PM
    Join Date
    02 Dec 2010
    Gender
    Male
    Posts
    201
    Threads
    2
    Credits
    0
    Thanked
    2

    Default

    Quote daniyaliqbal said: View Post
    very beautiful , very nice

    kya chiz????????

  11. #11
    waqas naseer is offline Senior Member+
    Last Online
    30th May 2011 @ 12:21 PM
    Join Date
    25 Nov 2010
    Age
    32
    Gender
    Male
    Posts
    33
    Threads
    3
    Credits
    0
    Thanked
    0

    Default

    bohot hi acha hai janab

  12. #12
    waqas naseer is offline Senior Member+
    Last Online
    30th May 2011 @ 12:21 PM
    Join Date
    25 Nov 2010
    Age
    32
    Gender
    Male
    Posts
    33
    Threads
    3
    Credits
    0
    Thanked
    0

    Default

    Quote SufyanGujar said: View Post
    there is nothing nice about it,
    us ne aap ko question kia aur
    agar aap ans nahi de sakte to
    atleast post ko spam mat karo,

    and its not only you, i have seen many
    people doing this around, i think ITD
    should ban people like these...

    anyway lets get down to topic;





    bhai waise to mein recommend karta hoon
    k aap koi book parho lekin here is a tut:

    Code:
     Functions
    Now that you should have learned about variables, loops, and conditional statements it is time to learn about functions. You should have an idea of their uses as we have already use them and defined one in the guise of main. cin.get() is an example of a function. In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. 
    
    Functions that a programmer writes will generally require a prototype. Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four. 
    
    For example: 
     
    #include <cstdlib>   // Include rand()
    
    using namespace std; // Make rand() visible
    
    int a = rand(); // rand is a standard function that all compilers have
    Do not think that 'a' will change at random, it will be set to the value returned when the function is called, but it will not change again. 
    
    The general format for a prototype is simple: 
     
    return-type function_name ( arg_type arg1, ..., arg_type argN ); 
    There can be more than one argument passed to a function or none at all (where the parentheses are empty), and it does not have to return a value. Functions that do not return values have a return type of void. Lets look at a function prototype: 
     
    int mult ( int x, int y );
    This prototype specifies that the function mult will accept two arguments, both integers, and that it will return an integer. Do not forget the trailing semi-colon. Without it, the compiler will probably think that you are trying to write the actual definition of the function. 
    
    When the programmer actually defines the function, it will begin with the prototype, minus the semi-colon. Then there should always be a block with the code that the function is to execute, just as you would write it for the main function. Any of the arguments passed to the function can be used as if they were declared in the block. Finally, end it all with a cherry and a closing brace. Okay, maybe not a cherry. 
    
    Lets look at an example program: 
     
    #include <iostream>
    
    using namespace std;
    
    int mult ( int x, int y );
    
    int main()
    {
      int x;
      int y;
      
      cout<<"Please input two numbers to be multiplied: ";
      cin>> x >> y;
      cin.ignore();
      cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
      cin.get();
    }
    
    int mult ( int x, int y )
    {
      return x * y;
    }
    This program begins with the only necessary include file and a directive to make the std namespace visible. Everything in the standard headers is inside of the std namespace and not visible to our programs unless we make them so. Next is the prototype of the function. Notice that it has the final semi-colon! The main function returns an integer, which you should always have to conform to the standard. You should not have trouble understanding the input and output functions. It is fine to use cin to input to variables as the program does. But when typing in the numbers, be sure to separate them by a space so that cin can tell them apart and put them in the right variables. 
    
    Notice how cout actually outputs what appears to be the mult function. What is really happening is cout is printing the value returned by mult, not mult itself. The result would be the same as if we had use this print instead 
     
    cout<<"The product of your two numbers is "<< x * y <<"\n";
    The mult function is actually defined below main. Due to its prototype being above main, the compiler still recognizes it as being defined, and so the compiler will not give an error about mult being undefined. As long as the prototype is present, a function can be used even if there is no definition. However, the code cannot be run without a definition even though it will compile. The prototype and definition can be combined into one also. If mult were defined before it is used, we could do away with the prototype because the definition can act as a prototype as well. 
    
    Return is the keyword used to force the function to return a value. Note that it is possible to have a function that returns no value. If a function returns void, the retun statement is valid, but only if it does not have an expression. In otherwords, for a function that returns void, the statement "return;" is legal, but redundant. 
    
    The most important functional (Pun semi-intended) question is why do we need a function? Functions have many uses. For example, a programmer may have a block of code that he has repeated forty times throughout the program. A function to execute that code would save a great deal of space, and it would also make the program more readable. Also, having only one copy of the code makes it easier to make changes. Would you rather make forty little changes scattered all throughout a potentially large program, or one change to the function body? So would I. 
    
    Another reason for functions is to break down a complex program into logical parts. For example, take a menu program that runs complex code when a menu choice is selected. The program would probably best be served by making functions for each of the actual menu choices, and then breaking down the complex tasks into smaller, more manageable tasks, which could be in their own functions. In this way, a program can be designed that makes sense when read. And has a structure that is easier to understand quickly. The worst programs usually only have the required function, main, and fill it with pages of jumbled code.
     
    Note: This tut is copy and paste from cprogramming.com
    its not mine and i dont get any credits for this tut.
    so all credits to cprogramming for providing such a
    nice tut.

    -Saif
    thanks......

Page 1 of 2 12 LastLast

Similar Threads

  1. 1 min Lecture...
    By gulmac in forum Sunnat aur Hadees
    Replies: 5
    Last Post: 24th March 2015, 08:31 AM
  2. FSC 2nd Year Lecture
    By Dil_Shah in forum Educational Help
    Replies: 9
    Last Post: 16th January 2012, 05:27 PM
  3. Some Java Tags & Funtions >> Class 2nd
    By Abdul Moeed in forum Courses
    Replies: 39
    Last Post: 26th August 2011, 03:31 PM
  4. Need new Lecture
    By do_rrr_die in forum Tajaweez aur Shikayat
    Replies: 4
    Last Post: 21st June 2007, 05:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •