Thread: help me with some idea...

  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
    28,413
    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;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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?

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, 03: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