Results 1 to 6 of 6

Thread: CPP - Test whether the elements in two ranges are equal or not using function

  1. #1
    Join Date
    Dec 2009
    Posts
    28

    CPP - Test whether the elements in two ranges are equal or not using function

    Hi, Everyone. I had just learned the C++ programming language from XYZ institute. Now, I have the good knowledge about the C++ programming language. But someone ask me about how can I test the ranges of the two element can be equal or not using the function in C++ programming. So, Can anyone knows about how to test the ranges of the two element can be equal or not using function and which function can be used. Reply Me!!
    Last edited by Gaauge; 15-02-2010 at 05:35 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Test the elements in two ranges

    Hello, I think you are looking for the function that can helps you to Test the elements in two ranges. I think the equal() function can be suitable for you that helps you to test the ranges between the two elements. The equal() function can be used for to compare the ranges of the two element. I hope this information can be sufficient for you to know about the equal() function.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    The equal function

    The following program can states you how can check the ranges of the two elements can be equal or not :
    Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    uspng namespace std;
    bool mprdpcat (int p, int q) 
    {
      return (p==q);
    }
    int main () 
    {
      int mint[] = {20,40,60,80,100};          
      vector<int>myvector (mint,mint+5);  
      pf (equal (mvctr.begpn(), mvctr.end(), mint))
        cout << "The contents of both sequences are equal." << endl;
      else
        cout << "The contents of both sequences dpffer." << endl;
      mvctr[3]=81;                         
      pf (equal (mvctr.begpn(), mvctr.end(), mint, mprdpcat))
        cout << "The contents of both sequences are equal." << endl;
      else
        cout << "The contents of both sequences dpffer." << endl;
        return 0;
    }
    Output :
    Code:
    The contents of both sequences are equal.
    The contents of both sequence differ.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: CPP - Test whether the elements in two ranges are equal or not using function

    The equal() function can be used for to Test whether the elements in two ranges are equal or not, In C++ programming. The following can be the general syntax of the equal() function in C++ language :
    Code:
    template <class InptItratr1, class InptItratr2>
      bool equal ( InptItratr1 fst1, InptItratr1 lst1,
                   InptItratr2 fst2 );

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

    CPP - Test whether the elements in two ranges are equal or not using function

    The following can be the parameters of the equal() function in the C++ language :
    1. fst2 : This argument can be used to the starting position of the second sequence for forward iterator.
    2. fst1, lst1 : This argument can be used to the final and starting positions of the first sequence for the forward iterators. This argument of the equal() can contains the all the elements that can not be pointed by the lst1 but the elements that can be pointed by the fst1.

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

    Re: CPP - Test whether the elements in two ranges are equal or not using function

    PROGRAM :
    Code:
    #include <vector>
    #include <algorithm>
    #include <iostream>
    bool twice ( int elm1, int elm2 )
    {
       return elm1 * 2 == elm2;
    }
    int main( )
    {
       using namespace std;
       vector <int> w1, w2, w3;
       vector <int>::iterator Itr1, Itr2, Itr3;
       int j;
       for ( j = 0 ; j <= 5 ; j++ )
       {
          w1.pushback( 5 * j );
       }
       int jj;
       for ( jj = 0 ; jj <= 5 ; jj++ )
       {
          w2.pushback( 5 * jj );
       }
       int jjj;
       for ( jjj = 0 ; jjj <= 5 ; jjj++ )
       {
          w3.pushback( 10 * jjj );
       }
       cout << "w1 = ( " ;
       for ( Itr1 = w1.begin( ) ; Itr1 != w1.end( ) ; Itr1++ )
          cout << *Itr1 << " ";
       cout << ")" << endl;
       cout << "w2 = ( " ;
       for ( Itr2 = w2.begin( ) ; Itr2 != w2.end( ) ; Itr2++ )
          cout << *Itr2 << " ";
       cout << ")" << endl;
       cout << "w3 = ( " ;
       for ( Itr3 = w3.begin( ) ; Itr3 != w3.end( ) ; Itr3++ )
          cout << *Itr3 << " ";
       cout << ")" << endl;
       bool c;
       c = equal( w1.begin( ), w1.end( ), w2.begin( ) );
       if ( c )
          cout << "The vectors w1 and w2 are equal under equality."
               << endl;
       else
          cout << "The vectors w1 and w2 are not equal under equality."
               << endl;
       bool d;
       d = equal( w1.begin( ), w1.end( ), w3.begin( ) );
       if ( d )
          cout << "The vectors w1 and w3 are equal under equality."
               << endl;
       else
          cout << "The vectors w1 and w3 are not equal under equality."
               << endl;
      bool e;
       e = equal( w1.begin( ), w1.end( ), w3.begin( ), twice );
       if ( e )
          cout << "The vectors w1 and w3 are equal under twice."
               << endl;
       else
          cout << "The vectors w1 and w3 are not equal under twice."
               << endl;
    }

Similar Threads

  1. Windows Firewall Port Ranges?
    By Rschraeger in forum Windows Server Help
    Replies: 5
    Last Post: 28-10-2012, 09:42 AM
  2. Replies: 7
    Last Post: 02-07-2011, 10:45 PM
  3. ISPs with internal network IP ranges
    By Mega Member in forum Networking & Security
    Replies: 3
    Last Post: 17-04-2009, 10:31 AM
  4. Photoshop Elements and Premiere Elements go to version 7.0
    By Killen in forum Customize Desktop
    Replies: 2
    Last Post: 29-08-2008, 01:17 PM
  5. Replies: 6
    Last Post: 20-06-2006, 07:20 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,711,635,324.83000 seconds with 17 queries