[RESOLVED] c++ dictionary - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 46

Thread: [RESOLVED] c++ dictionary

  1. #31
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    Getting a word in all 8 directions is a function of nextword() in my sample code of post #27 and has nothing to do with using a map. Get the word from the 2d array and then test if it is an actual word or not.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  2. #32
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    Oh so the first the function nextword () search in all directions for a word in 2d array then it checks if its a real word or not from dictionary if yes it display it if not does nothing is that what you meant ???

  3. #33
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    Quote Originally Posted by david16 View Post
    Oh so the first the function nextword () search in all directions for a word in 2d array then it checks if its a real word or not from dictionary if yes it display it if not does nothing is that what you meant ???
    Not quite. nextword() does the iteration and obtains the next set of letters from the 2d array. This is returned from nextword() as parameter word and returns true. Once all the possible letter combinations from the 2d array have been obtained, it returns false. The nextword() calling function checks if the returned word is actually in the dictionary or not and if it is increments (and adds if necessary) the word to wrdmap. Once nextword() returns false, the program displays the contents of wrdmap which contains a list of found words and their frequency.

    The important part of this exercise is the 2d iteration of possible words in all 8 directions - not seeing if they are actually words or not. I suggest you focus now on this 8 direction 2d array iteration.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  4. #34
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    The problem with prototype you sent , some of usages are specific to visual studio 2017 that why if I want to open it later with 2010 I won't be able to do it . also to be sincere , some things you used I didn't cover yet so I'm not able to understand . I was hoping to simplify the syntax but I was unable to understand things w.second , static ... also there is an error I get on visual 2017 on this map<string, int> dicmap; . can we use loop to do this task I was trying to do so . but I will need a prototype to use can you help ?? thx
    Last edited by david16; July 12th, 2017 at 01:47 AM.

  5. #35
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    The code posted compiles and runs OK on my computer using VS2017.

    Lots of current c++ code won't work with VS2010 which is now 7 years old and doesn't support the current c++ standard as VS2010 was released before the c++11 standard was adopted. The current standard is c++14 with the new c++17 standard imminent.

    Time to upgrade.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  6. #36
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    yes I do have visual 2017 but if I were to open that somewhere where only 2010 is there , I built a common solution that why I;m working on how can we make life easier especially that some material you used I didn't cover yet which make it hard to understand you see ? the problem is also to get the solution that can fit my knowledge you see ?? thx for your support .

  7. #37
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    yes I do have visual 2017 but I'm working on how can we make life easier especially that some material you used I didn't cover yet which make it hard to understand you see ? the problem is also to get the solution that can fit my knowledge you see and things I could probably understand on my own you see ?? thx for your support .

  8. #38
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    First before starting the part I would like to know if there is a way to read my txt file faster .. you see if each time I have to go and search the whole file which has about 383023 words it will take alot of time can I for example store smewhere within the code to make it readable faster ?? thanks

  9. #39
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  10. #40
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    I heard about something I don't know if its easy to understand . if you have a large file which in my case is dictionary called Napster and a cross word game with search in all 8 directions , I can create something called tree which allow me to send from my 2d cross word game a character first one for example and search for it in my file its will get to the location where this letter is present and using multiples loops in 8 directions I will be able to send each time one more character and check if its a word in my file to display it is that possible any suggestion on that ?? I'm not looking for a fully optimized way to do it by the fastest with my knowledge thank you


    the main thing to do now is to add templates or something so I can send to the function that is doing the task any array size I want because I have different ones assume user chose this one display bellow I can search in the direction marked in colors

    Code:
    Z B X G Y
    B A F U Y
    I N B L U
    P X K M J
    C V L N V
    
    Z B X G Y
    B A F U Y
    I N B L U
    P X K M J
    C V L N V
    
    Z B X G Y
    B A F U Y
    I N B L U
    P X K M J
    C V L N V
    Last edited by david16; July 12th, 2017 at 05:34 AM.

  11. #41
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    I can create something called tree which allow me to send from my 2d cross word game a character first one for example and search for it in my file its will get to the location where this letter is present
    A tree is how set & map store the data internally! A tree is quite a complex advanced data structure and you need to have covered use of dynamic memory before creating one.

    First before starting the part I would like to know if there is a way to read my txt file faster
    Use a set. First read the data from the file into a set and then accessing the words vis searching is of order O(log n) where n is the number of stored words.
    Last edited by 2kaud; July 12th, 2017 at 05:43 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  12. #42
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    Ohh didnt know about that .. I guess I should go back to think how loops can solve this problem I don't have any choice

    Code:
     void dict() {
    
    	ifstream  dictionary("Napster.txt");
    
    	if (!dictionary) {
    
    		cout << "\nCannot open file.\n " << endl;
    	}
    
    	string read;
    
    	while ( getline (dictionary, read))
    	{
    		cout << read << endl; //added this to make sure its working
    	}
    }
    i can possibly pass it to a bool function to make search
    here is the part I already showed you were I read my file ( about 383023 words ) I will use loops to solve it maybe its long solution but Its the only material I can use in other cases we have static and vector which i'm not familiar with . the search process is going to be slow because of the amount of words in my file that why search has to be in a very special way you see ? is there an optimized way to use for loops to solve it ?? just show me a prototype so I can have a concrete example or I can also post the hole program to make things easier .. thx a lot
    Last edited by david16; July 12th, 2017 at 06:47 AM.

  13. #43
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    is there an optimized way to use for loops to solve it
    If you post the code for how you're currently doing it, then we'll be able to advise on optimisation.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

  14. #44
    Join Date
    May 2017
    Posts
    173

    Re: c++ dictionary

    ok I will see your post #39 but I guess its c# not c++
    Last edited by david16; July 12th, 2017 at 09:01 AM.

  15. #45
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,584

    Re: c++ dictionary

    check for word in the array
    That is the main part of the exercise! No one here is going to write this part for you. When you have attempted this, if you post the code we'll provide further advice and guidance.

    the problem is how to do this task
    See the site reference in post #39.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)