help me with some idea...

This is a discussion on help me with some idea... within the C++ Programming forums, part of the General Programming Boards category; what you mean by this ?? ?? cheers as i know that otherset is a StringSet... it can't used of ...

  1. #31
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    what you mean by this ?? ?? cheers

    as i know that otherset is a StringSet... it can't used of insert


    i try this

    Code:
    StringSet StringSet::set_union(StringSet otherset)
    {
        StringSet UnionResult;
        
        for(int i = 0; i < contents.size(); i++)
        {
            UnionResult.insert( contents[i] );
            UnionResult.inser( otherset );  // ???????
        }   
        return UnionResult;
    }
    Last edited by peter_hii; 10-01-2006 at 06:38 AM.

  2. #32
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    i being thinking .......

    insert otherset into contents
    and another loop to insert the overall contents into UnionResult....is tat alright?

  3. #33
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    Code:
    StringSet StringSet::set_union(StringSet otherset)
    {
        StringSet UnionResult;
        
        for(int i = contents.size(); i > contents.size(); i++)
        {
            //UnionResult.insert( contents[i] );
            otherset.insert( contents[i] );
        }   
        for(int i = 0; i < contents.size(); i++)
        {
            UnionResult.insert( contents[i] );
        }
        return UnionResult;
    }

  4. #34
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    More like:
    Code:
    StringSet StringSet::set_union(const StringSet& otherset) const
    {
        StringSet result;
    
        // copy over contents of this StringSet
        result.contents.assign(contents.begin(), contents.end());
    
        // insert the contents of the other StringSet
        for (unsigned int i = 0; i < otherset.contents.size(); ++i)
        {
            result.insert(otherset.contents[i]);
        }
    
        return result;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #35
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    is the assign keywords?
    new for me .. hehe....can you please explain...? thank you ...

  6. #36
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    I am assuming that the contents member variable is a standard container such as a std::vector. You should read up on what assign() does.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #37
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    ok i understand assign() by viewing www.cppreference.com
    really thanx laserlight .. you are brilliant...

    one more question which i dont really understand why i could not display wat i want....

    this is my class = header file

    Code:
    
    #include <string>
    #include <iostream>
    #include <vector>
    #include "stringset.h"
    
    using namespace std; 
    
    
    class InvertedIndex 
    {
    //insert data member here
      struct inputType
      {
          string word;
          StringSet file;
      };
      
      vector<inputType> list;
    
    public:
     
      // Tally adds one word/file pair to the index 
      void tally(string word, string file);
    and this is my implementation code

    Code:
    #include "inverted_index.h"
    #include "osdir.h"
    
    // InvertedIndex::tally
    //   Pre: a word and file pair as strings
    //   Post: adds the file to the index under word
    void InvertedIndex::tally(string word, string file) 
    {
         inputType input;
    
         list.push_back( input );
    }
    
    // print
    // Pre: an index structure
    // Post: renders the index on the screen
    void InvertedIndex::print() 
    {
        for( vector<inputType>::const_iterator output = list.begin(); output != list.end(); output++ )
        cout << "Word: " << output->word << "\t\tFile: " << output->file << endl;
    }
    and the main code

    Code:
    #include "inverted_index.h"
    
    int main() 
    {
      
      // test the InvertedIndex 
     InvertedIndex idx;
     idx.tally("cat", "cats.txt");
     idx.tally("cat", "animals.txt");
     idx.tally("cat", "everything.txt");
     idx.tally("dog", "dogs.txt");
     idx.print();
    why the output is empty. ??

  8. #38
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    can someone please help on this serioes problem of mine????anyone?

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. project idea ???
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-09-2005, 09:56 AM
  2. Have an idea?
    By B0bDole in forum Projects and Job Recruitment
    Replies: 46
    Last Post: 01-13-2005, 02:25 PM
  3. A little problem about an idea, help please
    By louis_mine in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 09:52 PM
  4. totally screwed up idea
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-17-2001, 12:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21