Saturday, 22 December 2012

Hi all this page is for your Class work on arrays, functions ands Structures

277 comments:

  1. lets learn C++ in the next generation way.........

    ReplyDelete
  2. Thank u for the efforts sir we are easily usig the site to interact with u

    ReplyDelete
  3. Give your gmail id to my gamil id

    ReplyDelete
  4. Today's Topic is Functions , their use and their types with examples

    ReplyDelete
  5. Well are you all ready for the class

    ReplyDelete
  6. Functions are the User defined Datatype used for special works

    ReplyDelete
  7. eg
    lets take an example that we need to take five inputs of marks float and find their avg, max , min and sort them and print them.
    and we need to this for all the classes and all section. what wil we do

    ReplyDelete
  8. sir we will declare an array like a[5] and then put the marks of one class in it

    ReplyDelete
  9. Now for this problem either we can use the cin for all the inputs and then do all the calculations. or we can use a small code for doing all the calculations. and use that code again and again for the calculations of all the classes

    ReplyDelete
  10. the fuctions are datatypes defined in C++ for the reusability of code or the function can be reused again and again.

    ReplyDelete
  11. the function can be called in the main function using calling code
    and the function is called a called function.
    eg

    #include

    int add(int a,int b) //called function
    {
    int c= a+b;
    return c;
    }

    void main()
    {
    int x,y;

    cin>>x;
    cin>>y;
    cout<<(x,y);

    //again addtions
    cin>>x;
    cin>>y;
    cout<<(x,y); //calling function

    //again addtions
    cin>>x;
    cin>>y;
    cout<<(x,y); //calling function

    }

    ReplyDelete
  12. Now the called fuction is a user defined datatype so it will have some return datatype. the return datatype is predefined datatype.
    like void, int, char

    ReplyDelete
  13. Function a datatype with 4 parts in it
    1. name of the function
    2. return type
    3. signature of the function
    4. function body or function defination.

    ReplyDelete
  14. in the above example

    int add(int a, int b) // int-> return type add->fuction name (int a,int b)->function signature
    {
    //anything inside it is fucntion body or defination
    }

    ReplyDelete
  15. now if you see the function properly the return keyward used inside the fuction body also have the variable with the same datatype as the datatype written before the name of the fuction
    means
    int add(int a, int b)
    {return c;}
    c is also of int datatype

    ReplyDelete
  16. problem rewirtten


    #include "iostram.h"

    int add(int a,int b) //called function
    {
    int c= a+b;
    return c;
    }

    void main()
    {
    int x,y;

    cin>>x;
    cin>>y;
    cout<>x;
    cin>>y;
    cout<>x;
    cin>>y;
    cout<<add(x,y); //calling function

    }

    ReplyDelete
  17. #include
    #include

    int avg(int a,int b,int c) //called function
    {
    int d= (a+b+c)/3;
    return d;
    }

    void main()
    {
    int x,y,z;

    cin>>x;
    cin>>y;
    cin>>z;
    cout<>x;
    cin>>y;
    cin>>z;
    cout<>x;
    cin>>y;
    cin>>z;
    cout<<avg(x,y,z);//calling function
    }

    ReplyDelete
  18. #include
    int avg(int a,int b,int c) //called function
    {
    int d= (a+b+c)/3;
    return d;
    }
    void main()
    {
    int a,b,c;

    cin>>a;
    cin>>b;
    cin>>c;
    cout<<avg(a,b,c);//calling function
    }

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  19. Avg of three numbers using float variable:-

    #include
    float avg(float a,float b,float c) //called function
    {
    float d= (a+b+c)/3;
    return d;
    }
    void main()
    {
    float a,b,c;

    cin>>a;
    cin>>b;
    cin>>c;
    cout<<avg(a,b,c);//calling function
    }

    ReplyDelete
  20. Sorry...sir...Today I did not get time. But i will be present tommorow for sure


    ReplyDelete
  21. Today is the second day of the remedia class

    ReplyDelete
    Replies
    1. mee tooooooo do you have any idea till when is the remedial classes

      Delete
  22. sir.. before u start one thing serious
    ankan has not returned home and his mom has been calling me
    over and over

    ReplyDelete
  23. OK Good evening
    Now todays class is on the functions using call by value and call by refrence

    ReplyDelete
  24. OK all the students please confirm

    ReplyDelete
  25. ok..... bt sir each time we have to publish smthing we have do that human verfication process..... how can we avoid it??????

    ReplyDelete
  26. sir can u pls come online for a moment on
    gmail.

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. do v have to come online in gmail?????

    ReplyDelete
  29. Functions with call by value use the parameter and signature to copy the variable value of parameter to signature

    ReplyDelete
  30. Function with call by ref. use the parameter and signature but the varible address of parameter is copied to the signature or function for calculations

    ReplyDelete
  31. call by value

    #include

    int add(int a,int b)
    {
    return(a+b);
    }

    void main()
    {
    int x,y;
    x=1;
    y=2;
    cout<<add(x,y);
    }

    ReplyDelete
  32. call by ref

    #include

    int add(int &a,int &b)
    {
    a=a+b;
    }

    void main()
    {
    int x,y;
    x=1;
    y=2;
    add(x,y);
    cout<<x;
    }

    ReplyDelete
  33. in the later program the function doesnot returns any value to the main calling function rather the value of x is in itself modified

    ReplyDelete
  34. it is because the variable x with its address is passed to the function and not the value in x i.e. &a holds the address of x and &b holds the address of y

    ReplyDelete
  35. int add(int a,int b)
    int add(int &a,int &b)
    what is the difference between the two?

    ReplyDelete
  36. sir wat is the difference betwn call by reference and return by reference????

    ReplyDelete
  37. so the call by value uses four variable like x,y,a,b
    but call by ref. uses two variables like x,y only and the address to x,y i.e &a,&b

    ReplyDelete
  38. this theory states that use of call by ref is better then call by value as it uses less memory and is much faster as less variables are used

    ReplyDelete
  39. sir if we want to work with moore than two variables cant we use call by reference???????//

    ReplyDelete
  40. This comment has been removed by the author.

    ReplyDelete
  41. now lets look in the few more programms

    ReplyDelete
  42. Q. we have three variables to input say a,b,c and we need to put them in acending order. write the program to do so?

    ReplyDelete
  43. sir, can't we write this "int add(int a, b)" instead of "int add(int a,int b)"

    ReplyDelete
  44. ok the answar is

    #include "iostream.h"
    void asc(int a,int b, int c)
    {
    int temp;
    if(a>b)
    {
    if(a>c)
    {
    temp=a;
    a=c;
    }
    else
    {
    temp=a;
    a=b;
    b=a;
    }
    }
    else
    {
    if(b>c)
    {
    temp=b;
    b=c;
    c=temp;
    }
    }
    cout<>a;
    cin>>b;
    cin>>c;
    acs(x,y,z);
    }

    ReplyDelete
  45. now there the code used will pass the values from main to asc but the three numbers in acsending cannot called but from asc function to main function

    this problem of passing more than one function from called to calling function is done by call by ref.

    ReplyDelete
  46. OK all we will continue after 9:00 PM

    ReplyDelete
  47. sir, can we say that a,b and c are in the scope of asc?

    ReplyDelete
  48. sir cant v write if((a>b)&&(a>c)) instead of ariting it in 2 steps????

    ReplyDelete
  49. sir, from where the "temp" came from????

    ReplyDelete
  50. Good evening Sir, sorry couldn't be present from 4-5pm.

    ReplyDelete
  51. sir, where is the function endeing?????


    ReplyDelete
  52. #include "iostream.h"
    void asc(int a,int b, int c)
    {
    int temp;
    if(a>b)
    {
    if(a>c)
    {
    temp=a;
    a=c;
    }
    else
    {
    temp=a;
    a=b;
    b=a;
    }
    }
    else
    {
    if(b>c)
    {
    temp=b;
    b=c;
    c=temp;
    }
    }
    void main()
    {
    int a,b;
    cin>>a;
    cin>>b;
    cin>>c;
    acs(a,b,c);
    }

    ReplyDelete
    Replies
    1. sir if v hve given all d condotions like the if-else loop for defining d values of the variables, within d void main function, thn wat would hve d difference?

      Delete
  53. the programm corrected. now the question can the variable a,b,c be defined in void main and acs function
    the answer is big NO as asc has a public scope means all the varibales of asc are public if defined in the function defination

    ReplyDelete
  54. sir i believe in this function the greatest number is sent to the bottommost and hence the order is formed..... am i right???????

    ReplyDelete
  55. second question temp is a varible for swaping and needed to be declaired in asc function

    ReplyDelete
  56. now there is a very silly mistake in the solution can anybody tell it to me

    ReplyDelete
  57. the function in acs has a problem please wirte the same code in your C++ compiler and then say the error

    ReplyDelete
  58. Sir, how can i chat with you? Google talks about circles and i cannot find you or my friends.....

    ReplyDelete
  59. you have called asc and are calling acs

    ReplyDelete
  60. guys please make your friend on your gmail chat list... my gmail id: adijinu2010@gmail.com......

    ReplyDelete
  61. @jishnu I think i added you....... my email is potatosaur108@gmail.com

    ReplyDelete
  62. in this question
    1. we need to get three variable values to the function
    2. then put the values foo the three varibles in sequence
    3. then return them back to the main function
    OK

    ReplyDelete
  63. what are these points sir?????

    ReplyDelete
    Replies
    1. for the function for three numbers in ascending order

      Delete
  64. can you all wirte a program for simply put three numbers in ascending order.
    we have done it already
    please post the program

    ReplyDelete
  65. #include "iostream.h" //call by value
    void asc(int a,int b, int c)
    {
    int temp;
    if(a>b)
    {
    if(a>c)
    {
    temp=a;
    a=c;
    }
    else
    {
    temp=a;
    a=b;
    b=a;
    }
    }
    else
    {
    if(b>c)
    {
    temp=b;
    b=c;
    c=temp;
    }
    cout<>a;
    cin>>b;
    cin>>c;
    acs(a,b,c);
    }

    ReplyDelete
    Replies
    1. you have to change the the program
      #include "iostream.h" //call by value

      void asc(int a,int b, int c)
      {
      int temp;
      if(a>b)
      {
      if(a>c)
      {
      temp=a;
      a=c;
      }
      else
      {
      temp=a;
      a=b;
      b=a;
      }
      }
      else
      {
      if(b>c)
      {
      temp=b;
      b=c;
      c=temp;
      }
      cout<>x;
      cin>>y;
      cin>>z;
      acs(x,y,z);
      }

      Delete
    2. Where have we defined x, y, z variable in the above program??

      Delete
  66. #include "iostream.h" //call the ref
    void asc(int &a,int &b,int &c) //called function
    {
    int temp;
    if(a>b)
    {
    if(a>c)
    {
    temp=a;
    a=c;
    }
    else
    {
    temp=a;
    a=b;
    b=a;
    }
    }
    else
    {
    if(b>c)
    {
    temp=b;
    b=c;
    c=temp;
    }
    }

    void main()
    {
    int x,y,z;
    cin>>x;
    cin>>y;
    cin>>z;
    acs(x,y,z); //calling function
    cout<<x<<y<<z; //for output
    }

    ReplyDelete
    Replies
    1. Sir, it is giving two errors in my computer:-
      1. declaration syntax error in function(int& ,int&, int&)
      2. declaration missing ; in function(int& ,int&, int&)

      and there will be another third bracket at the end of the program

      Delete
  67. #include
    #include
    void main()
    {
    int arr[3],i,j,temp;
    for(i=0;i<3;i++)
    cin>>arr[i];
    for(i=2;i>1;i++)
    {
    for(j=1;j<=i;j++)
    {
    if(arr[j]<arr[j-1])
    {
    temp=arr[j];
    arr[j]=arr[j-1];
    arr[j-1]=temp;
    }
    }
    cout<<"\n";
    for(i=0;i<3;i++)
    cout<<arr[i]<<"\n";
    }
    }
    sir check this out there may be mistakes but the logic is same as u have taught us......

    ReplyDelete
    Replies
    1. Dear very nice and you have array in it. it is abit confusing to the new ones. but your program is right

      Delete
    2. yes sir it is a bit confusing.... can you please explain it?????

      Delete
    3. first for loop i-- not i++

      Delete
    4. sir can u xplain d program......i didn't understand it

      Delete
    5. correct program


      #include
      #include
      void main()
      {
      int arr[3],i,j,temp;
      for(i=0;i<3;i--)
      cin>>arr[i];
      for(i=2;i>1;i++)
      {
      for(j=1;j<=i;j++)
      {
      if(arr[j]<arr[j-1])
      {
      temp=arr[j];
      arr[j]=arr[j-1];
      arr[j-1]=temp;
      }
      }
      cout<<"\n";
      for(i=0;i<3;i++)
      cout<<arr[i]<<"\n";
      }
      }

      Delete
  68. Now that function are been discussed in the class should we revise

    ReplyDelete
    Replies
    1. y r v putting iostream.h wiyhin "" and nt in <>? in d above program?

      Delete
  69. y r v putting iostream.h wiyhin "" and nt in <>????????

    ReplyDelete
    Replies
    1. its not intentional....... the blogger dont accept<> thats y......

      Delete
    2. bhai mujhe apne circles main ad kar.... my id is adijinu2010@gmail.com

      Delete
    3. plz add me too.......
      this is my id- mitashri16tikli@gmail.com

      Delete
  70. sorry for being late sir......

    ReplyDelete
  71. OK mitashri jishnu is using the array sort program done the the previous week for 10 digits in an arry remember

    ReplyDelete
  72. Jishnu has uesd the array to sort the three values. But what if you have to do the sorting for more then 10 times in the main program then

    ReplyDelete
    Replies
    1. then we need the function to pass the three values in the function and sort them and then pass them back to the main fucntion

      Delete
  73. sir is there will any cls 2morow in schl?

    ReplyDelete
  74. Dear all students i have avery bad night i as haveing feaver & tomach pain so i am doing to doctor, kindly come to the evening class as no class now at 8

    ReplyDelete
  75. Good morning Every one. Wish u all
    !!!!!!!MERRY CHRISTMAS!!!!!!!

    ReplyDelete
  76. #include
    #include
    void main()
    {
    int a,b,c,i;
    cin>>a>>b>>C;
    for(i=0;i<=500;++i)
    {
    if(i==a)
    cout<<a<<endl;
    else
    {
    if(i==b)
    cout<<b<<endl;
    else
    {
    if(i==c)
    cout<<c;
    }
    }
    }
    getch();
    }

    ReplyDelete
    Replies
    1. nice concept dude......... tera dimaag is always outstanding....

      Delete
    2. Nice concept well done by if number are 500,5001,502 then

      Delete
  77. Sir...now i m just studying about fuctions and need to study more....
    so i did not use functions and just loop but it works..

    ReplyDelete
  78. good evening sir..& merry christmas as well!

    ReplyDelete
  79. .....****MERRY CHRISTMAS TO EVERYONE****......

    ReplyDelete
  80. #include
    void swap(int &x, int&y)
    {
    int temp=x;
    x=y;
    y=temp;
    }
    void main()
    {
    int a,b,c;
    cin>>a>>b>>c;
    if (a>b)
    {
    {
    if (a>c)
    swap(a,c);
    {
    if (a>b)
    swap(a,b);
    }
    }
    }
    else
    {
    if (b>c)
    swap(b,c);
    {
    if (a>b)
    swap(a,b);
    }
    }
    cout<<a<<","<<b<<","<<c<<"\n";

    }
    another programme..........

    ReplyDelete
  81. merry christmas guys n gals........

    ReplyDelete
  82. All of you belated MERRY CHRISTMAS
    Today is the final day for function please the doubts only

    ReplyDelete
    Replies
    1. What is a funtion & define two types fo function

      Delete
    2. what is the syntex to define a function

      Delete
    3. Do writing any fucntion requires any special syntex other then a normal function name

      Delete
    4. void func(int a,int b) is it a declaration of function

      Delete
  83. 1) function is a programme that returns a value and ats as a data or info to the main programe...
    types:
    user defined
    predefined
    2) name of thee function;
    type of return value
    function signature
    body/definition
    3)dont kno???:-p
    4)yes sir

    ReplyDelete
    Replies
    1. return datatype function name ( signature)

      Delete
  84. A function is a group of statements that together perform a task. For example: void main()

    Two types: Pre defined and user defined

    syntax:
    function name(name and dataype of variables)
    {
    body

    }

    Yes func(int a,int b)is a declared function

    ReplyDelete
    Replies
    1. aman send me request on gmail my id is adijinu2010@gmail.com

      Delete
    2. second question
      two types
      call by value and call by refrence

      rest are right well done

      Delete
    3. aman mujhe bhi accept kar my ID: arkopal0111@gmail .com

      Delete
  85. then wat is user defined and pre defined functions?????????

    ReplyDelete
    Replies
    1. User defined fucntions are the functions we create and we are talking of User defined Functions only there

      per defined functions are defined in the header files given with the C++ library. And we use them without defining them

      eg. gets()->stdio.h ,strlen()->string.h, clrscr-> conio.h>

      Delete
    2. we are talking to user defined fucntion only OK

      Delete
    3. This comment has been removed by the author.

      Delete
  86. i mean if types of functions are call by reference and call by value, then what will we call user defined functions n predefined function????????

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  87. Is main a user defined or predifined function

    ReplyDelete
  88. Replies
    1. No a defualt function but is of user defined type as the declaration of main is done as per the program means any thing written in main is written by the programmer well tried

      Delete
    2. sir can u give some more example of programs using functions.

      Delete
    3. Ok give some questions from the text book and we will discuss

      Delete
  89. A program to check whether a given character is contained in a string or not and also find its position

    ReplyDelete
    Replies
    1. First you take a charactor array
      then use gets to fill it with string
      then use strlen to check the lenght of the string
      then use for loop from 0 to stelen-1 to find the search charactar
      if found the first time use goto to get out of the loop and print the loop variable+1 for position
      else
      print not found

      Delete
    2. #include "iostream.h"
      #include "string.h"
      #include "stdio.h"
      #include "conio.h"

      void main()
      {
      char name[20],s;
      int i;
      clrscr();
      cout<<"Get the String";
      gets(name);
      cout<<"get the char to search";
      cin>>s;
      for(i=0;i<strlen(name);i++)
      {
      if(name[i]==s)
      {
      cout<<"Match Found at " <<i+1;
      goto x;
      }
      }
      cout<<"MATCH nOT fOUND";
      x:
      }

      Delete
    3. in the above program stelen and clrscr and gets are predefined functions
      and we have not given any user defined function except main in the porgram

      Delete
  90. Brilliant...thanks sir got it.. In the book its a bit tough program but i got the idea how to it

    ReplyDelete
  91. OK thanks some more questions

    ReplyDelete
  92. I think you have an idea of Functions and their types
    OK

    ReplyDelete
    Replies
    1. there are mainly two types of functions
      1. predefined functions.
      2. user defined functions.(twp types)
      2.a.Call by value
      2.b.Call by refrence

      Now we have defined about user defined functions


      Delete
    2. Next is a small topic of per defined fucntions.

      Delete
    3. per defined functions on the basis of what type of data they work on are defined as
      1. char/string functions
      2. Numeric functions
      3. Arithemetic functions
      4. graphic functions
      5. logical functions
      etc

      Delete
  93. eg strlen is a string function
    sqrt is a mathmetic functions arithemetic fuctions are sub part of mathemetic functions
    goto(x,y) is a graphic function
    if() is a logical function also called as conditional construct

    always remember any name followed by (brackets) are function
    OK

    ReplyDelete
  94. Sir what to do if the char comes more than once at different places in the string for the problem u had given

    ReplyDelete
    Replies
    1. then there will be modification in the program ok

      Delete
    2. #include
      #include
      #include
      #include

      void main()
      {
      char name[20],s,flag;
      int i;
      clrscr();
      cout<<"Get the String";
      gets(name);
      cout<<"get the char to search";
      cin>>s;
      for(i=0;i<strlen(name);i++)
      {
      if(name[i]==s)
      {
      cout<<"Match Found at " <<i+1;
      flag='T';
      }
      }
      if(flag!='T')
      cout<<"MATCH nOT fOUND";
      }

      Delete
    3. Sir how did this happen????

      What is flag and what is the use of it?????

      Delete
    4. flag is a variable to check if char matched or not
      if found once flag becomes T else F OK

      Delete
    5. sir T and F stands fr true and false???????

      Delete
  95. sir can there be function within another function like nested loops and if else?

    ReplyDelete
    Replies
    1. sure
      inside a user defined functions we use pre defined fucntions
      OK

      Delete
  96. Q. c++ program of least coomon divisor of two integers

    #include
    #include
    main()
    {int a,b,i=2,k=-1;
    cout<<"Enter a: ";
    cin>>a;
    cout<<"Enter b: ";
    cin>>b;

    while(k==-1 && i<(a+b)){
    if(a%i==0 && b%i==0)
    k=i;
    i++;
    }

    if(k=-1)
    cout<<"Least common divisor: "<<k<<"\n";
    else cout<<"No common divisor\n";

    }

    sir this program is nt runnin in my computer sir plz show the fault

    ReplyDelete
  97. sir what is the use of function prototype?? eesha

    ReplyDelete
    Replies
    1. as we know to use any datatype we need to declare it first as a variable.
      now the user defined function is a datatype created by the user so user need to define the return datatype, name, signature and declaration code of the function to use it
      if the function is only declared in the main function with return type name and signature only it is called function prototyping

      we declare the code after the prototype is used eg

      void main()
      {
      int a,b;
      a=1;
      b=2;
      cout<<add(a,b); //will give error that function not declared
      }

      int add(int x,int y);
      {
      retunr (x+y);
      }



      but if you used prototype

      void main()
      {
      int a,b;
      int add(int,int); ///function prototype
      a=1;
      b=2;
      cout<<add(a,b);
      }

      int add(int x,int y);
      {
      retunr (x+y);
      }

      Delete
  98. sir....cn more thn 1 user defined funtions be use in 1 program?

    ReplyDelete
  99. m back home...and i have missed so much!!...n abhi sab dimag k upar se jaa raha hai....God!!... >:( ;(

    ReplyDelete
  100. Hello Good Morning..... Any1 dere????

    ReplyDelete
    Replies
    1. ami jokhon ashi tokhon keu ashena...>:(
      morning..

      Delete
  101. Has there been any classes yesterday? O_O

    ReplyDelete
  102. if any1z there plz let me know through gmail chat....... id:adijinu2010@gmail.com

    ReplyDelete
  103. Hello every body sorry for the gap i was having fever for the last 5 days as i had bacterial fever.
    OK sorry we will continue from monday those there please be in touch
    next topic structure and union

    ReplyDelete