Results 1 to 6 of 6

Thread: Help me to use the transform() in C++ coding

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    Help me to use the transform() in C++ coding

    Hello, How are you All. I am the student of the MscCS. I must have to submit the assignment on the functions of the C++ library in four days. I could also had the well knowledge of the functions that could be used in the C++ programming language. Even though, I could not know much more about the transform() function of the C++ programming language. So, I would like to know about the transform() function of the C++ programming language. I also would like to know How the transform() function could be used in the C++ Programs. Reply Me!!

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Use the transform()

    The transform() function can be used in the C++ language to apply the function to the given range of an element. The following can be the general syntax of the transform() function :
    Code:
    template < class InptItrtr, class OtptItrtr, class UnryOprtr >
      OtptItrtr transform ( InptItrtr first1, InptItrtr last1,
                                 OtptItrtr result, UnryOprtr op );

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    The transform() in C++ coding

    I think you can have to under go through the following code of lines of the program that can help's you to get the knowledge or the information of the replace_if() function in the C++ language :
    Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int opincrease (int i)
     {
     return ++i; 
    }
    int opsum (int i, int j) 
    { 
    return i+j;
     }
    int main ()
     {
      vector<int> fst;
      vector<int> scnd;
      vector<int>::iterator t;
      for (int i=1; i<6; i++) fst.pushback (i*10); 
      second.resize(fst.size());    
      transform (fst.begin(), fst.end(), scnd.begin(), opincrease);  
      transform (fst.begin(), fst.end(), scnd.begin(), fst.begin(), opsum);
      cout << "first contains:";
      for (t=fst.begin(); t!=fst.end(); ++t)
        cout << " " << *t;
      cout << endl;
      return 0;
    }
    Output:
    Code:
    first contains: 21 41 61 81 101

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Help me to use the transform()

    Hello, According to my knowledge of the transform() function is that the transform() function can be used in the C++ programming to apply first version to all of an elements in the input range ([fst1,lst1)) and can stores each value that can be returned in the range beginning at result. I hope you should understand from the this explanation. If you can not get it then reply me!!!!

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Help me to use the transform() in C++ coding

    The following can be the parameters of the transform() function in the C++ language :
    1. op : This parameter of the transform() function can be used for the unary function that can taking one element as an argument and can returns the some value that can be as result.
    2. fst1, lst1 : These parameters of the transform() function can be used for input iterators to the final and starting positions of the sequence that can be first. The range used can be as [fst1,lst1).
    3. rslt : This parameter of the transform() function can be used for output iterator to the starting position of the range where the results of the functions can be stored.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    The transform() in C++

    There can be one more another program that can also help's you to know or to get the knowledge of the transform() function in the C++ language :
    Code:
    int increment(int i)
     { 
    return ++i;
     }
    int sm(int a, int b)
     {
     return a+b; 
    }
    int main()
     {
      vector<int> w1;
      for(int i=1; i<6; i++) w1.push_back (i*i);    
      vector<int> w2(w1.size());
      transform(w1.begin(), w1.end(), w2.begin(), increment);      
      transform(w1.begin(), w1.end(), w2.begin(), w1.begin(), sm); 
       return 0;
    }

Similar Threads

  1. java coding
    By unikshegz in forum Software Development
    Replies: 1
    Last Post: 27-10-2010, 01:56 AM
  2. How to use the pop_heap() in C++ coding
    By Garrick in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 05:28 PM
  3. Help in coding documents
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 02:34 AM
  4. C++ coding faster?
    By Chandrakant81 in forum Software Development
    Replies: 3
    Last Post: 17-02-2009, 10:51 PM
  5. Problem with C coding
    By SANDESH49 in forum Software Development
    Replies: 2
    Last Post: 02-09-2008, 01:23 PM

Tags for this Thread

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
  •  
Page generated in 1,713,495,145.35286 seconds with 17 queries